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 <SLES/OpenSLES.h> 18 #include <SLES/OpenSLES_Android.h> 19 #include <pthread.h> 20 #include <android/log.h> 21 22 #ifndef _Included_org_drrickorang_loopback_sles 23 #define _Included_org_drrickorang_loopback_sles 24 25 //struct audio_utils_fifo; 26 #define SLES_PRINTF(...) __android_log_print(ANDROID_LOG_INFO, "sles_jni", __VA_ARGS__); 27 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 #include <audio_utils/fifo.h> 33 34 typedef struct { 35 SLuint32 rxBufCount; // -r# 36 SLuint32 txBufCount; // -t# 37 SLuint32 bufSizeInFrames; // -f# 38 SLuint32 channels; // -c# 39 SLuint32 sampleRate; // -s# 40 SLuint32 exitAfterSeconds; // -e# 41 SLuint32 freeBufCount; // calculated 42 SLuint32 bufSizeInBytes; // calculated 43 int injectImpulse; // -i#i 44 SLuint32 numFramesToIgnore; 45 46 // Storage area for the buffer queues 47 char **rxBuffers; 48 char **txBuffers; 49 char **freeBuffers; 50 51 // Buffer indices 52 SLuint32 rxFront; // oldest recording 53 SLuint32 rxRear; // next to be recorded 54 SLuint32 txFront; // oldest playing 55 SLuint32 txRear; // next to be played 56 SLuint32 freeFront; // oldest free 57 SLuint32 freeRear; // next to be freed 58 59 struct audio_utils_fifo fifo; //(*) 60 struct audio_utils_fifo fifo2; 61 short *fifo2Buffer; 62 short *fifoBuffer; 63 SLAndroidSimpleBufferQueueItf recorderBufferQueue; 64 SLBufferQueueItf playerBufferQueue; 65 66 pthread_mutex_t mutex;// = PTHREAD_MUTEX_INITIALIZER; 67 68 //other things that belong here 69 SLObjectItf playerObject; 70 SLObjectItf recorderObject; 71 SLObjectItf outputmixObject; 72 SLObjectItf engineObject; 73 } sles_data; 74 75 enum { 76 SLES_SUCCESS = 0, 77 SLES_FAIL = 1, 78 } SLES_STATUS_ENUM; 79 80 int slesInit(sles_data ** ppSles, int samplingRate, int frameCount, 81 int micSource, int numFramesToIgnore); 82 83 //note the double pointer to properly free the memory of the structure 84 int slesDestroy(sles_data ** ppSles); 85 86 ///full 87 int slesFull(sles_data *pSles); 88 89 int slesCreateServer(sles_data *pSles, int samplingRate, int frameCount, int micSource, int numFramesToIgnore); 90 int slesProcessNext(sles_data *pSles, double *pSamples, long maxSamples); 91 int slesDestroyServer(sles_data *pSles); 92 93 #ifdef __cplusplus 94 } 95 #endif 96 #endif //_Included_org_drrickorang_loopback_sles 97