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 /////
Java_com_android_cts_verifier_audio_NativeAudioThread_slesInit(JNIEnv * env __unused,jobject obj __unused,jint samplingRate,jint frameCount,jint micSource,jint numFramesToIgnore)24 JNIEXPORT jlong JNICALL Java_com_android_cts_verifier_audio_NativeAudioThread_slesInit
25 (JNIEnv *env __unused, jobject obj __unused, jint samplingRate, jint frameCount,
26 jint micSource, jint numFramesToIgnore) {
27
28 sles_data * pSles = NULL;
29
30 if (slesInit(&pSles, samplingRate, frameCount, micSource, numFramesToIgnore) != SLES_FAIL) {
31
32 return (long)pSles;
33 }
34 // FIXME This should be stored as a (long) field in the object,
35 // so that incorrect Java code could not synthesize a bad sles pointer.
36 return 0;
37 }
38
Java_com_android_cts_verifier_audio_NativeAudioThread_slesProcessNext(JNIEnv * env __unused,jobject obj __unused,jlong sles,jdoubleArray samplesArray,jlong offset)39 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAudioThread_slesProcessNext
40 (JNIEnv *env __unused, jobject obj __unused, jlong sles, jdoubleArray samplesArray,
41 jlong offset) {
42 sles_data * pSles= (sles_data*) ((long)sles);
43
44 long maxSamples = (*env)->GetArrayLength(env, samplesArray);
45 double *pSamples = (*env)->GetDoubleArrayElements(env, samplesArray,0);
46
47 long availableSamples = maxSamples-offset;
48 double *pCurrentSample = pSamples+offset;
49
50 SLES_PRINTF("jni slesProcessNext pSles:%p, currentSample %p, availableSamples %ld ", pSles,
51 pCurrentSample, availableSamples);
52
53 int samplesRead = slesProcessNext(pSles, pCurrentSample, availableSamples);
54
55 return samplesRead;
56 }
57
Java_com_android_cts_verifier_audio_NativeAudioThread_slesDestroy(JNIEnv * env __unused,jobject obj __unused,jlong sles)58 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAudioThread_slesDestroy
59 (JNIEnv *env __unused, jobject obj __unused, jlong sles) {
60 sles_data * pSles= (sles_data*) ((long) sles);
61
62 int status = slesDestroy(&pSles);
63
64 return status;
65 }
66