1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <android/log.h> 18 #include "sles.h" 19 #include "jni_sles.h" 20 #include <stdio.h> 21 #include <stddef.h> 22 23 ///// 24 JNIEXPORT jlong JNICALL Java_com_android_cts_verifier_audio_NativeAudioThread_slesInit 25 (JNIEnv *env __unused, jobject obj __unused, jint samplingRate, jint frameCount, jint micSource) { 26 27 sles_data * pSles = NULL; 28 29 if (slesInit(&pSles, samplingRate, frameCount, micSource) != SLES_FAIL) { 30 31 return (long)pSles; 32 } 33 // FIXME This should be stored as a (long) field in the object, 34 // so that incorrect Java code could not synthesize a bad sles pointer. 35 return 0; 36 } 37 38 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAudioThread_slesProcessNext 39 (JNIEnv *env __unused, jobject obj __unused, jlong sles, jdoubleArray samplesArray, 40 jlong offset) { 41 sles_data * pSles= (sles_data*) ((long)sles); 42 43 long maxSamples = (*env)->GetArrayLength(env, samplesArray); 44 double *pSamples = (*env)->GetDoubleArrayElements(env, samplesArray,0); 45 46 long availableSamples = maxSamples-offset; 47 double *pCurrentSample = pSamples+offset; 48 49 SLES_PRINTF("jni slesProcessNext pSles:%p, currentSample %p, availableSamples %ld ", pSles, 50 pCurrentSample, availableSamples); 51 52 int samplesRead = slesProcessNext(pSles, pCurrentSample, availableSamples); 53 54 return samplesRead; 55 } 56 57 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAudioThread_slesDestroy 58 (JNIEnv *env __unused, jobject obj __unused, jlong sles) { 59 sles_data * pSles= (sles_data*) ((long) sles); 60 61 int status = slesDestroy(&pSles); 62 63 return status; 64 } 65