LADI JACK2: Switch to 2.minor versioning scheme
[jackdbus.git] / android / opensl_io.h
blob501f0361c9b9a17ab75e10247e372d86c04d024a
1 /*
2 opensl_io.c:
3 Android OpenSL input/output module header
4 Copyright (c) 2012, Victor Lazzarini
5 All rights reserved.
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.
30 #ifndef OPENSL_IO
31 #define OPENSL_IO
33 #include <SLES/OpenSLES.h>
34 #include <SLES/OpenSLES_Android.h>
35 #include <pthread.h>
36 #include <stdlib.h>
38 typedef struct threadLock_{
39 pthread_mutex_t m;
40 pthread_cond_t c;
41 unsigned char s;
42 } threadLock;
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
48 typedef struct opensl_stream {
50 // engine interfaces
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;
68 // buffer indexes
69 int currentInputIndex;
70 int currentOutputIndex;
72 // current buffer half (0, 1)
73 int currentOutputBuffer;
74 int currentInputBuffer;
76 // buffers
77 short *outputBuffer[2];
78 short *inputBuffer[2];
80 // size of buffers
81 int outBufSamples;
82 int inBufSamples;
84 // locks
85 void* inlock;
86 void* outlock;
88 double time;
89 int inchannels;
90 int outchannels;
91 int sr;
93 } OPENSL_STREAM;
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);
117 #ifdef __cplusplus
119 #endif
121 #endif // #ifndef OPENSL_IO