19 #ifndef BEATMUP_PROFILE_NOAUDIO
23 #include <SLES/OpenSLES.h>
24 #include <SLES/OpenSLES_Android.h>
27 using namespace Audio;
28 using namespace Android;
31 void playerCallback(SLAndroidSimpleBufferQueueItf queue,
void *data);
36 inline void assert(SLresult code,
const char* message) {
37 if (code != SL_RESULT_SUCCESS)
42 if (code != SL_RESULT_SUCCESS)
61 engine(nullptr), engineObj(nullptr), outputMixObj(nullptr)
74 result = slCreateEngine(&engineObj, 0, NULL, 0, NULL, NULL);
77 result = (*engineObj)->Realize(engineObj, SL_BOOLEAN_FALSE);
82 result = (*engineObj)->GetInterface(engineObj, SL_IID_ENGINE, &engine);
88 result = (*engine)->CreateOutputMix(engine, &outputMixObj, 0, NULL, NULL);
93 result = (*outputMixObj)->Realize(outputMixObj, SL_BOOLEAN_FALSE);
97 SLDataLocator_AndroidSimpleBufferQueue bufferQueueConfig =
101 SLDataFormat_PCM formatConfig = {
108 SL_BYTEORDER_LITTLEENDIAN
110 SLDataSource audioSrc = {&bufferQueueConfig, &formatConfig};
113 SLDataLocator_OutputMix outputMixLocator = {SL_DATALOCATOR_OUTPUTMIX, outputMixObj};
114 SLDataSink audioSnk = {&outputMixLocator, NULL};
117 const SLInterfaceID ids[1] = {SL_IID_BUFFERQUEUE};
118 const SLboolean req[1] = {SL_BOOLEAN_TRUE};
119 result = (*engine)->CreateAudioPlayer(engine, &playerObj, &audioSrc, &audioSnk, 1, ids, req);
120 assert(
result,
"SLES playback initialization failed: buffered player creation",
mode);
123 result = (*playerObj)->Realize(playerObj, SL_BOOLEAN_FALSE);
124 assert(
result,
"SLES playback initialization failed: buffered player realization",
mode);
127 result = (*playerObj)->GetInterface(playerObj, SL_IID_PLAY, &playbackObj);
128 assert(
result,
"SLES playback initialization failed: playback access",
mode);
131 result = (*playerObj)->GetInterface(playerObj, SL_IID_BUFFERQUEUE, &bufferQueueObj);
132 assert(
result,
"SLES playback initialization failed: buffered queue ccess",
mode);
136 assert(
result,
"SLES playback initialization failed: callback registration",
mode);
145 SLresult
result = (*playbackObj)->SetPlayState(playbackObj, SL_PLAYSTATE_PLAYING);
152 SLresult
result = (*playbackObj)->SetPlayState(playbackObj, SL_PLAYSTATE_STOPPED);
158 (*bufferQueueObj)->Enqueue(bufferQueueObj, buffa,
bufferSize);
168 backend =
new SLESBackend();
171 SLESPlayback::~SLESPlayback() {
175 void SLESPlayback::initialize(Mode
mode) {
176 backend->initialize(
mode, *
this);
177 Audio::BasicRealtimePlayback::initialize(
mode);
185 void SLESPlayback::stop() {
189 void SLESPlayback::pushBuffer(
sample8 *buffer,
int bufferIndex) {
190 backend->pushBuffer(buffer);
msize bufferSize
size of each buffer in bytes
Communicates an error occurred during the playback.
void initialize(Audio::AbstractPlayback::Mode mode, Audio::BasicRealtimePlayback &playback)
void pushBuffer(sample8 *buffa)
SLAndroidSimpleBufferQueueItf bufferQueueObj
uint32_t msize
memory size
const int AUDIO_SAMPLE_SIZE[]
void assert(SLresult code, const char *message)
void playerCallback(SLAndroidSimpleBufferQueueItf queue, void *data)
AudioSampleFormat sampleFormat
format of each sample
dtime sampleRate
samples per second / sample rate in Hz
unsigned char numBuffers
number of atomic buffers
unsigned char numChannels
number of channels
dtime bufferLength
length of each atomic buffer in samples