3 Android OpenSL input/output module header
4 Copyright (c) 2012, Victor Lazzarini
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of the <organization> nor the
15 names of its contributors may be used to endorse or promote products
16 derived from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <SLES/OpenSLES.h>
34 #include <SLES/OpenSLES_Android.h>
38 typedef struct threadLock_
{
48 typedef struct opensl_stream
{
51 SLObjectItf engineObject
;
52 SLEngineItf engineEngine
;
54 // output mix interfaces
55 SLObjectItf outputMixObject
;
57 // buffer queue player interfaces
58 SLObjectItf bqPlayerObject
;
59 SLPlayItf bqPlayerPlay
;
60 SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue
;
61 SLEffectSendItf bqPlayerEffectSend
;
63 // recorder interfaces
64 SLObjectItf recorderObject
;
65 SLRecordItf recorderRecord
;
66 SLAndroidSimpleBufferQueueItf recorderBufferQueue
;
69 int currentInputIndex
;
70 int currentOutputIndex
;
72 // current buffer half (0, 1)
73 int currentOutputBuffer
;
74 int currentInputBuffer
;
77 short *outputBuffer
[2];
78 short *inputBuffer
[2];
96 Open the audio device with a given sampling rate (sr), input and output channels and IO buffer size
97 in frames. Returns a handle to the OpenSL stream
99 OPENSL_STREAM
* android_OpenAudioDevice(int sr
, int inchannels
, int outchannels
, int bufferframes
);
101 Close the audio device
103 void android_CloseAudioDevice(OPENSL_STREAM
*p
);
105 Read a buffer from the OpenSL stream *p, of size samples. Returns the number of samples read.
107 int android_AudioIn(OPENSL_STREAM
*p
, float *buffer
,int size
);
109 Write a buffer to the OpenSL stream *p, of size samples. Returns the number of samples written.
111 int android_AudioOut(OPENSL_STREAM
*p
, float *buffer
,int size
);
113 Get the current IO block time in seconds
115 double android_GetTimestamp(OPENSL_STREAM
*p
);
121 #endif // #ifndef OPENSL_IO