2
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Additional permission under GNU GPL version 3 section 7:
21
* If you modify this program, or any covered work, by linking or
22
* combining it with the OpenSSL project's OpenSSL library (or a
23
* modified version of that library), containing parts covered by the
24
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25
* grants you additional permission to convey the resulting work.
26
* Corresponding Source for a non-source form of such a combination
27
* shall include the source code for the parts of OpenSSL used as well
28
* as that of the covered work.
36
#include "array_size.h"
38
#include "mainbuffer.h"
39
#include "audio/dcblocker.h"
41
#include "opensllayer.h"
43
const int OpenSLLayer::NB_BUFFER_PLAYBACK_QUEUE = ANDROID_BUFFER_QUEUE_LENGTH;
44
const int OpenSLLayer::NB_BUFFER_CAPTURE_QUEUE = ANDROID_BUFFER_QUEUE_LENGTH;
48
OpenSLThread(OpenSLLayer *opensl);
50
void initAudioLayer();
52
bool isRunning() const;
56
static void *runCallback(void *context);
58
NON_COPYABLE(OpenSLThread);
64
OpenSLThread::OpenSLThread(OpenSLLayer *opensl)
65
: thread_(0), opensl_(opensl), running_(false)
69
OpenSLThread::isRunning() const
74
OpenSLThread::~OpenSLThread()
77
opensl_->shutdownAudioEngine();
80
pthread_join(thread_, nullptr);
87
pthread_create(&thread_, nullptr, &runCallback, this);
91
OpenSLThread::runCallback(void *data)
93
OpenSLThread *context = static_cast<OpenSLThread*>(data);
99
OpenSLThread::initAudioLayer()
101
opensl_->initAudioEngine();
102
opensl_->initAudioPlayback();
103
opensl_->initAudioCapture();
105
opensl_->flushMain();
106
opensl_->flushUrgent();
110
* Reimplementation of run()
117
opensl_->startAudioPlayback();
118
opensl_->startAudioCapture();
119
opensl_->isStarted_ = true;
121
while (opensl_->isStarted_)
122
usleep(20000); // 20 ms
126
OpenSLLayer::OpenSLLayer(const AudioPreference &pref)
133
, engineInterface_(0)
137
, playerInterface_(0)
138
, recorderInterface_(0)
139
, playbackBufferQueue_(0)
140
, recorderBufferQueue_(0)
141
, playbackBufferIndex_(0)
142
, recordBufferIndex_(0)
143
, playbackBufferStack_(ANDROID_BUFFER_QUEUE_LENGTH, AudioBuffer(BUFFER_SIZE, 1, 8000))
144
, recordBufferStack_(ANDROID_BUFFER_QUEUE_LENGTH, AudioBuffer(BUFFER_SIZE, 1, 8000))
149
OpenSLLayer::~OpenSLLayer()
154
/* Then close the audio devices */
160
OpenSLLayer::startStream()
167
DEBUG("Start OpenSL audio layer");
169
if (audioThread_ == nullptr) {
170
audioThread_ = new OpenSLThread(this);
171
audioThread_->start();
172
} else if (!audioThread_->isRunning()) {
173
audioThread_->start();
179
OpenSLLayer::stopStream()
184
DEBUG("Stop OpenSL audio layer");
192
audioThread_ = nullptr;
199
OpenSLLayer::initAudioEngine()
203
DEBUG("Create Audio Engine\n");
204
result = slCreateEngine(&engineObject_, 0, nullptr, 0, nullptr, nullptr);
205
assert(SL_RESULT_SUCCESS == result);
207
DEBUG("Realize Audio Engine\n");
208
result = (*engineObject_)->Realize(engineObject_, SL_BOOLEAN_FALSE);
209
assert(SL_RESULT_SUCCESS == result);
211
DEBUG("Create Audio Engine Interface\n");
212
result = (*engineObject_)->GetInterface(engineObject_, SL_IID_ENGINE, &engineInterface_);
213
assert(SL_RESULT_SUCCESS == result);
215
DEBUG("Create Output Mixer\n");
216
result = (*engineInterface_)->CreateOutputMix(engineInterface_, &outputMixer_, 0, nullptr, nullptr);
217
assert(SL_RESULT_SUCCESS == result);
219
DEBUG("Realize Output Mixer\n");
220
result = (*outputMixer_)->Realize(outputMixer_, SL_BOOLEAN_FALSE);
221
assert(SL_RESULT_SUCCESS == result);
223
DEBUG("Audio Engine Initialization Done\n");
227
OpenSLLayer::shutdownAudioEngine()
230
// destroy buffer queue audio player object, and invalidate all associated interfaces
231
DEBUG("Shutdown audio player\n");
233
if (playerObject_ != nullptr) {
234
(*playerObject_)->Destroy(playerObject_);
235
playerObject_ = nullptr;
236
playerInterface_ = nullptr;
237
playbackBufferQueue_ = nullptr;
240
// destroy output mix object, and invalidate all associated interfaces
241
DEBUG("Shutdown audio mixer\n");
243
if (outputMixer_ != nullptr) {
244
(*outputMixer_)->Destroy(outputMixer_);
245
outputMixer_ = nullptr;
248
if(recorderObject_ != nullptr){
249
(*recorderObject_)->Destroy(recorderObject_);
250
recorderObject_ = nullptr;
251
recorderInterface_ = nullptr;
252
recorderBufferQueue_ = nullptr;
255
// destroy engine object, and invalidate all associated interfaces
256
DEBUG("Shutdown audio engine\n");
257
if (engineObject_ != nullptr) {
258
(*engineObject_)->Destroy(engineObject_);
259
engineObject_ = nullptr;
260
engineInterface_ = nullptr;
265
OpenSLLayer::initAudioPlayback()
267
assert(nullptr != engineObject_);
268
assert(nullptr != engineInterface_);
269
assert(nullptr != outputMixer_);
273
// Initialize the location of the buffer queue
274
DEBUG("Create playback queue\n");
275
SLDataLocator_AndroidSimpleBufferQueue bufferLocation = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
276
NB_BUFFER_PLAYBACK_QUEUE
279
// Initnialize the audio format for this queue
280
DEBUG("Setting audio format\n");
281
SLDataFormat_PCM audioFormat = {SL_DATAFORMAT_PCM,
284
SL_PCMSAMPLEFORMAT_FIXED_16,
285
SL_PCMSAMPLEFORMAT_FIXED_16,
286
SL_SPEAKER_FRONT_CENTER,
287
SL_BYTEORDER_LITTLEENDIAN
290
// Create the audio source
291
DEBUG("Set Audio Sources\n");
292
SLDataSource audioSource = {&bufferLocation, &audioFormat};
294
DEBUG("Get Output Mixer interface\n");
295
result = (*outputMixer_)->GetInterface(outputMixer_, SL_IID_OUTPUTMIX, &outputMixInterface_);
298
// Cofiguration fo the audio sink as an output mixer
299
DEBUG("Set output mixer location\n");
300
SLDataLocator_OutputMix mixerLocation = {SL_DATALOCATOR_OUTPUTMIX, outputMixer_};
301
SLDataSink audioSink = {&mixerLocation, nullptr};
303
const SLInterfaceID ids[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
305
SL_IID_ANDROIDCONFIGURATION,
308
const SLboolean req[] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
310
const unsigned nbInterface = ARRAYSIZE(ids);
312
// create audio player
313
DEBUG("Create audio player\n");
314
result = (*engineInterface_)->CreateAudioPlayer(engineInterface_, &playerObject_, &audioSource, &audioSink, nbInterface, ids, req);
315
assert(SL_RESULT_SUCCESS == result);
317
SLAndroidConfigurationItf playerConfig;
318
SLint32 streamType = SL_ANDROID_STREAM_VOICE;
321
result = (*playerObject_)->GetInterface(playerObject_,
322
SL_IID_ANDROIDCONFIGURATION,
325
if (result == SL_RESULT_SUCCESS && playerConfig) {
326
result = (*playerConfig)->SetConfiguration(
327
playerConfig, SL_ANDROID_KEY_STREAM_TYPE,
328
&streamType, sizeof(SLint32));
331
DEBUG("Realize audio player\n");
332
result = (*playerObject_)->Realize(playerObject_, SL_BOOLEAN_FALSE);
333
assert(SL_RESULT_SUCCESS == result);
335
if (result != SL_RESULT_SUCCESS) {
336
ERROR("Unable to set android player configuration");
339
// create audio interface
340
DEBUG("Create audio player interface\n");
341
result = (*playerObject_)->GetInterface(playerObject_, SL_IID_PLAY, &playerInterface_);
342
assert(SL_RESULT_SUCCESS == result);
344
// create the buffer queue interface
345
DEBUG("Create buffer queue interface\n");
346
result = (*playerObject_)->GetInterface(playerObject_, SL_IID_BUFFERQUEUE, &playbackBufferQueue_);
347
assert(SL_RESULT_SUCCESS == result);
349
// register the buffer queue on the buffer object
350
DEBUG("Register audio callback\n");
351
result = (*playbackBufferQueue_)->RegisterCallback(playbackBufferQueue_, audioPlaybackCallback, this);
352
assert(SL_RESULT_SUCCESS == result);
354
DEBUG("Audio Playback Initialization Done\n");
358
OpenSLLayer::initAudioCapture()
362
// configure audio source
363
DEBUG("Configure audio source\n");
364
SLDataLocator_IODevice deviceLocator = {SL_DATALOCATOR_IODEVICE,
365
SL_IODEVICE_AUDIOINPUT,
366
SL_DEFAULTDEVICEID_AUDIOINPUT,
370
SLDataSource audioSource = {&deviceLocator,
374
// configure audio sink
375
DEBUG("Configure audio sink\n");
377
SLDataLocator_AndroidSimpleBufferQueue bufferLocator = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
378
NB_BUFFER_CAPTURE_QUEUE
381
DEBUG("Capture-> Sampling Rate: %d", sampleRate_);
382
DEBUG("Capture-> getInternalSamplingRate: %d", Manager::instance().getMainBuffer().getInternalSamplingRate());
383
SLDataFormat_PCM audioFormat = {SL_DATAFORMAT_PCM, 1,
385
SL_PCMSAMPLEFORMAT_FIXED_16,
386
SL_PCMSAMPLEFORMAT_FIXED_16,
387
SL_SPEAKER_FRONT_CENTER,
388
SL_BYTEORDER_LITTLEENDIAN
391
SLDataSink audioSink = {&bufferLocator,
395
// create audio recorder
396
// (requires the RECORD_AUDIO permission)
397
DEBUG("Create audio recorder\n");
398
const SLInterfaceID id[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE};
399
const SLboolean req[] = {SL_BOOLEAN_TRUE};
401
if (engineInterface_ != nullptr) {
402
result = (*engineInterface_)->CreateAudioRecorder(engineInterface_,
403
&recorderObject_, &audioSource, &audioSink, 1, id, req);
406
if (SL_RESULT_SUCCESS != result) {
407
DEBUG("Error: could not create audio recorder");
411
// realize the audio recorder
412
DEBUG("Realize the audio recorder\n");
413
result = (*recorderObject_)->Realize(recorderObject_, SL_BOOLEAN_FALSE);
415
if (SL_RESULT_SUCCESS != result) {
416
DEBUG("Error: could not realize audio recorder");
420
// get the record interface
421
DEBUG("Create the record interface\n");
422
result = (*recorderObject_)->GetInterface(recorderObject_, SL_IID_RECORD, &recorderInterface_);
423
assert(SL_RESULT_SUCCESS == result);
425
// get the buffer queue interface
426
DEBUG("Create the buffer queue interface\n");
427
result = (*recorderObject_)->GetInterface(recorderObject_, SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
428
&recorderBufferQueue_);
429
assert(SL_RESULT_SUCCESS == result);
431
// register callback on the buffer queue
432
DEBUG("Register the audio capture callback\n");
433
result = (*recorderBufferQueue_)->RegisterCallback(recorderBufferQueue_, audioCaptureCallback, this);
434
assert(SL_RESULT_SUCCESS == result);
436
DEBUG("Audio capture initialized\n");
441
OpenSLLayer::startAudioPlayback()
443
assert(nullptr != playbackBufferQueue_);
445
DEBUG("Start audio playback\n");
449
for (int i = 0; i < NB_BUFFER_PLAYBACK_QUEUE; i++) {
450
AudioBuffer &buffer = getNextPlaybackBuffer();
451
incrementPlaybackIndex();
455
result = (*playbackBufferQueue_)->Enqueue(playbackBufferQueue_, buffer.getChannel(0)->data(), buffer.frames());
457
if (SL_RESULT_SUCCESS != result) {
458
DEBUG("Error could not enqueue initial buffers\n");
462
result = (*playerInterface_)->SetPlayState(playerInterface_, SL_PLAYSTATE_PLAYING);
463
assert(SL_RESULT_SUCCESS == result);
465
DEBUG("Audio playback started\n");
469
OpenSLLayer::startAudioCapture()
471
assert(nullptr != playbackBufferQueue_);
473
DEBUG("Start audio capture\n");
478
// in case already recording, stop recording and clear buffer queue
479
if (recorderInterface_ != nullptr) {
480
result = (*recorderInterface_)->SetRecordState(recorderInterface_, SL_RECORDSTATE_STOPPED);
481
assert(SL_RESULT_SUCCESS == result);
484
DEBUG("Clearing recorderBufferQueue\n");
485
result = (*recorderBufferQueue_)->Clear(recorderBufferQueue_);
486
assert(SL_RESULT_SUCCESS == result);
488
DEBUG("getting next record buffer\n");
489
// enqueue an empty buffer to be filled by the recorder
490
// (for streaming recording, we enqueue at least 2 empty buffers to start things off)
491
AudioBuffer &buffer = getNextRecordBuffer();
492
incrementRecordIndex();
496
DEBUG("Enqueue record buffer\n");
497
result = (*recorderBufferQueue_)->Enqueue(recorderBufferQueue_, buffer.getChannel(0)->data(), buffer.frames());
499
// the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT,
500
// which for this code example would indicate a programming error
501
if (SL_RESULT_SUCCESS != result) {
502
DEBUG("Error could not enqueue buffers in audio capture\n");
507
result = (*recorderInterface_)->SetRecordState(recorderInterface_, SL_RECORDSTATE_RECORDING);
508
assert(SL_RESULT_SUCCESS == result);
510
DEBUG("Audio capture started\n");
514
OpenSLLayer::stopAudioPlayback()
516
DEBUG("Stop audio playback\n");
518
if (playerInterface_ != nullptr) {
520
result = (*playerInterface_)->SetPlayState(playerInterface_, SL_PLAYSTATE_STOPPED);
521
assert(SL_RESULT_SUCCESS == result);
524
DEBUG("Audio playback stopped\n");
528
OpenSLLayer::stopAudioCapture()
530
DEBUG("Stop audio capture\n");
532
if (recorderInterface_ != nullptr) {
534
result = (*recorderInterface_)->SetRecordState(recorderInterface_, SL_RECORDSTATE_STOPPED);
535
assert(SL_RESULT_SUCCESS == result);
538
DEBUG("Audio capture stopped\n");
542
std::vector<std::string>
543
OpenSLLayer::getCaptureDeviceList() const
545
std::vector<std::string> captureDeviceList;
549
// Although OpenSL ES specification allows enumerating
550
// available output (and also input) devices, NDK implementation is not mature enough to
551
// obtain or select proper one (SLAudioIODeviceCapabilitiesItf, the official interface
552
// to obtain such an information)-> SL_FEATURE_UNSUPPORTED
554
SLuint32 InputDeviceIDs[MAX_NUMBER_INPUT_DEVICES];
555
SLint32 numInputs = 0;
556
SLboolean mic_available = SL_BOOLEAN_FALSE;
557
SLuint32 mic_deviceID = 0;
566
// Get the Audio IO DEVICE CAPABILITIES interface, implicit
567
DEBUG("Get the Audio IO DEVICE CAPABILITIES interface, implicit");
569
res = (*engineObject_)->GetInterface(engineObject_, SL_IID_AUDIOIODEVICECAPABILITIES, (void*)&AudioIODeviceCapabilitiesItf);
572
DEBUG("Get the Audio IO DEVICE CAPABILITIES interface, implicit");
573
numInputs = MAX_NUMBER_INPUT_DEVICES;
575
res = (*AudioIODeviceCapabilitiesItf)->GetAvailableAudioInputs(AudioIODeviceCapabilitiesItf, &numInputs, InputDeviceIDs);
579
// Search for either earpiece microphone or headset microphone input
580
// device - with a preference for the latter
581
for (i=0;i<numInputs; i++)
583
res = (*AudioIODeviceCapabilitiesItf)->QueryAudioInputCapabilities(AudioIODeviceCapabilitiesItf,
585
&AudioInputDescriptor);
588
if((AudioInputDescriptor.deviceConnection == SL_DEVCONNECTION_ATTACHED_WIRED) &&
589
(AudioInputDescriptor.deviceScope == SL_DEVSCOPE_USER) &&
590
(AudioInputDescriptor.deviceLocation == SL_DEVLOCATION_HEADSET))
592
DEBUG("SL_DEVCONNECTION_ATTACHED_WIRED : mic_deviceID: %d", InputDeviceIDs[i] );
593
mic_deviceID = InputDeviceIDs[i];
594
mic_available = SL_BOOLEAN_TRUE;
596
} else if((AudioInputDescriptor.deviceConnection == SL_DEVCONNECTION_INTEGRATED) &&
597
(AudioInputDescriptor.deviceScope == SL_DEVSCOPE_USER) &&
598
(AudioInputDescriptor.deviceLocation == SL_DEVLOCATION_HANDSET))
600
DEBUG("SL_DEVCONNECTION_INTEGRATED : mic_deviceID: %d", InputDeviceIDs[i] );
601
mic_deviceID = InputDeviceIDs[i];
602
mic_available = SL_BOOLEAN_TRUE;
607
if (!mic_available) {
608
// Appropriate error message here
609
ERROR("No mic available quitting");
614
return captureDeviceList;
617
/* Checks for error. If any errors exit the application! */
619
OpenSLLayer::CheckErr( SLresult res )
621
if ( res != SL_RESULT_SUCCESS )
623
// Debug printing to be placed here
628
std::vector<std::string>
629
OpenSLLayer::getPlaybackDeviceList() const
631
std::vector<std::string> playbackDeviceList;
633
return playbackDeviceList;
637
OpenSLLayer::audioPlaybackCallback(SLAndroidSimpleBufferQueueItf queue, void *context)
639
assert(nullptr != context);
640
static_cast<OpenSLLayer*>(context)->playback(queue);
644
OpenSLLayer::playback(SLAndroidSimpleBufferQueueItf queue)
646
assert(nullptr != queue);
648
notifyIncomingCall();
650
AudioBuffer &buffer = getNextPlaybackBuffer();
652
size_t samplesToGet = Manager::instance().getMainBuffer().availableForGet(MainBuffer::DEFAULT_ID);
653
size_t urgentSamplesToGet = urgentRingBuffer_.availableForGet(MainBuffer::DEFAULT_ID);
655
bufferIsFilled_ = false;
656
//DEBUG("samplesToGet:%d", samplesToGet);
657
//DEBUG("urgentSamplesToGet:%d", urgentSamplesToGet);
659
if (urgentSamplesToGet > 0)
660
bufferIsFilled_ = audioPlaybackFillWithUrgent(buffer, urgentSamplesToGet);
662
if (samplesToGet > 0)
663
bufferIsFilled_ = audioPlaybackFillWithVoice(buffer, samplesToGet);
665
bufferIsFilled_ = audioPlaybackFillWithToneOrRingtone(buffer);
669
if (bufferIsFilled_) {
670
SLresult result = (*queue)->Enqueue(queue, buffer.getChannel(0)->data(), buffer.frames()*sizeof(SFLAudioSample));
672
if (SL_RESULT_SUCCESS != result) {
673
DEBUG("Error could not enqueue buffers in playback callback\n");
676
incrementPlaybackIndex();
678
DEBUG("Error buffer not filled in audio playback\n");
683
OpenSLLayer::audioCaptureCallback(SLAndroidSimpleBufferQueueItf queue, void *context)
685
assert(nullptr != context);
686
static_cast<OpenSLLayer*>(context)->capture(queue);
690
OpenSLLayer::capture(SLAndroidSimpleBufferQueueItf queue)
692
assert(nullptr != queue);
694
AudioBuffer &old_buffer = getNextRecordBuffer();
695
incrementRecordIndex();
696
AudioBuffer &buffer = getNextRecordBuffer();
699
// enqueue an empty buffer to be filled by the recorder
700
// (for streaming recording, we enqueue at least 2 empty buffers to start things off)
701
result = (*recorderBufferQueue_)->Enqueue(recorderBufferQueue_, buffer.getChannel(0)->data(), buffer.frames()*sizeof(SFLAudioSample));
704
audioCaptureFillBuffer(old_buffer);
706
// the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT,
707
// which for this code example would indicate a programming error
708
assert(SL_RESULT_SUCCESS == result);
714
OpenSLLayer::updatePreference(AudioPreference &preference, int index, PCMType type)
716
#ifdef OUTSIDE_TESTING
719
case SFL_PCM_PLAYBACK:
722
case SFL_PCM_CAPTURE:
725
case SFL_PCM_RINGTONE:
735
void OpenSLLayer::audioCaptureFillBuffer(AudioBuffer &buffer)
737
MainBuffer &mbuffer = Manager::instance().getMainBuffer();
739
const unsigned mainBufferSampleRate = mbuffer.getInternalSamplingRate();
740
const bool resample = mainBufferSampleRate != sampleRate_;
742
buffer.applyGain(isCaptureMuted_ ? 0.0 : captureGain_);
745
int outSamples = buffer.frames() * (static_cast<double>(sampleRate_) / mainBufferSampleRate);
746
AudioBuffer out(outSamples, 1, mainBufferSampleRate);
747
converter_.resample(buffer, out);
748
dcblocker_.process(out);
749
mbuffer.putData(out, MainBuffer::DEFAULT_ID);
751
dcblocker_.process(buffer);
752
mbuffer.putData(buffer, MainBuffer::DEFAULT_ID);
756
bool OpenSLLayer::audioPlaybackFillWithToneOrRingtone(AudioBuffer &buffer)
758
buffer.resize(BUFFER_SIZE);
759
AudioLoop *tone = Manager::instance().getTelephoneTone();
760
AudioLoop *file_tone = Manager::instance().getTelephoneFile();
762
// In case of a dtmf, the pointers will be set to nullptr once the dtmf length is
763
// reached. For this reason we need to fill audio buffer with zeros if pointer is nullptr
765
tone->getNext(buffer, playbackGain_);
766
} else if (file_tone) {
767
file_tone->getNext(buffer, playbackGain_);
775
bool OpenSLLayer::audioPlaybackFillWithUrgent(AudioBuffer &buffer, size_t samplesToGet)
777
// Urgent data (dtmf, incoming call signal) come first.
778
samplesToGet = std::min(samplesToGet, BUFFER_SIZE);
779
buffer.resize(samplesToGet);
780
urgentRingBuffer_.get(buffer, MainBuffer::DEFAULT_ID);
781
buffer.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
783
// Consume the regular one as well (same amount of samples)
784
Manager::instance().getMainBuffer().discard(samplesToGet, MainBuffer::DEFAULT_ID);
789
bool OpenSLLayer::audioPlaybackFillWithVoice(AudioBuffer &buffer, size_t samplesAvail)
791
MainBuffer &mainBuffer = Manager::instance().getMainBuffer();
793
buffer.resize(samplesAvail);
794
mainBuffer.getData(buffer, MainBuffer::DEFAULT_ID);
795
buffer.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
797
if (sampleRate_ != mainBuffer.getInternalSamplingRate()) {
798
DEBUG("OpenSLLayer::audioPlaybackFillWithVoice sampleRate_ != mainBuffer.getInternalSamplingRate() \n");
799
AudioBuffer out(buffer, false);
800
out.setSampleRate(sampleRate_);
801
converter_.resample(buffer, out);
808
void dumpAvailableEngineInterfaces()
811
DEBUG("Engine Interfaces\n");
812
SLuint32 numSupportedInterfaces;
813
result = slQueryNumSupportedEngineInterfaces(&numSupportedInterfaces);
814
assert(SL_RESULT_SUCCESS == result);
815
result = slQueryNumSupportedEngineInterfaces(NULL);
816
assert(SL_RESULT_PARAMETER_INVALID == result);
818
DEBUG("Engine number of supported interfaces %lu\n", numSupportedInterfaces);
819
for(SLuint32 i=0; i< numSupportedInterfaces; i++){
820
SLInterfaceID pInterfaceId;
821
slQuerySupportedEngineInterfaces(i, &pInterfaceId);
822
const char* nm = "unknown iid";
824
if (pInterfaceId==SL_IID_NULL) nm="null";
825
else if (pInterfaceId==SL_IID_OBJECT) nm="object";
826
else if (pInterfaceId==SL_IID_AUDIOIODEVICECAPABILITIES) nm="audiodevicecapabilities";
827
else if (pInterfaceId==SL_IID_LED) nm="led";
828
else if (pInterfaceId==SL_IID_VIBRA) nm="vibra";
829
else if (pInterfaceId==SL_IID_METADATAEXTRACTION) nm="metadataextraction";
830
else if (pInterfaceId==SL_IID_METADATATRAVERSAL) nm="metadatatraversal";
831
else if (pInterfaceId==SL_IID_DYNAMICSOURCE) nm="dynamicsource";
832
else if (pInterfaceId==SL_IID_OUTPUTMIX) nm="outputmix";
833
else if (pInterfaceId==SL_IID_PLAY) nm="play";
834
else if (pInterfaceId==SL_IID_PREFETCHSTATUS) nm="prefetchstatus";
835
else if (pInterfaceId==SL_IID_PLAYBACKRATE) nm="playbackrate";
836
else if (pInterfaceId==SL_IID_SEEK) nm="seek";
837
else if (pInterfaceId==SL_IID_RECORD) nm="record";
838
else if (pInterfaceId==SL_IID_EQUALIZER) nm="equalizer";
839
else if (pInterfaceId==SL_IID_VOLUME) nm="volume";
840
else if (pInterfaceId==SL_IID_DEVICEVOLUME) nm="devicevolume";
841
else if (pInterfaceId==SL_IID_BUFFERQUEUE) nm="bufferqueue";
842
else if (pInterfaceId==SL_IID_PRESETREVERB) nm="presetreverb";
843
else if (pInterfaceId==SL_IID_ENVIRONMENTALREVERB) nm="environmentalreverb";
844
else if (pInterfaceId==SL_IID_EFFECTSEND) nm="effectsend";
845
else if (pInterfaceId==SL_IID_3DGROUPING) nm="3dgrouping";
846
else if (pInterfaceId==SL_IID_3DCOMMIT) nm="3dcommit";
847
else if (pInterfaceId==SL_IID_3DLOCATION) nm="3dlocation";
848
else if (pInterfaceId==SL_IID_3DDOPPLER) nm="3ddoppler";
849
else if (pInterfaceId==SL_IID_3DSOURCE) nm="3dsource";
850
else if (pInterfaceId==SL_IID_3DMACROSCOPIC) nm="3dmacroscopic";
851
else if (pInterfaceId==SL_IID_MUTESOLO) nm="mutesolo";
852
else if (pInterfaceId==SL_IID_DYNAMICINTERFACEMANAGEMENT) nm="dynamicinterfacemanagement";
853
else if (pInterfaceId==SL_IID_MIDIMESSAGE) nm="midimessage";
854
else if (pInterfaceId==SL_IID_MIDIMUTESOLO) nm="midimutesolo";
855
else if (pInterfaceId==SL_IID_MIDITEMPO) nm="miditempo";
856
else if (pInterfaceId==SL_IID_MIDITIME) nm="miditime";
857
else if (pInterfaceId==SL_IID_AUDIODECODERCAPABILITIES) nm="audiodecodercapabilities";
858
else if (pInterfaceId==SL_IID_AUDIOENCODERCAPABILITIES) nm="audioencodercapabilities";
859
else if (pInterfaceId==SL_IID_AUDIOENCODER) nm="audioencoder";
860
else if (pInterfaceId==SL_IID_BASSBOOST) nm="bassboost";
861
else if (pInterfaceId==SL_IID_PITCH) nm="pitch";
862
else if (pInterfaceId==SL_IID_RATEPITCH) nm="ratepitch";
863
else if (pInterfaceId==SL_IID_VIRTUALIZER) nm="virtualizer";
864
else if (pInterfaceId==SL_IID_VISUALIZATION) nm="visualization";
865
else if (pInterfaceId==SL_IID_ENGINE) nm="engine";
866
else if (pInterfaceId==SL_IID_ENGINECAPABILITIES) nm="enginecapabilities";
867
else if (pInterfaceId==SL_IID_THREADSYNC) nm="theadsync";
868
else if (pInterfaceId==SL_IID_ANDROIDEFFECT) nm="androideffect";
869
else if (pInterfaceId==SL_IID_ANDROIDEFFECTSEND) nm="androideffectsend";
870
else if (pInterfaceId==SL_IID_ANDROIDEFFECTCAPABILITIES) nm="androideffectcapabilities";
871
else if (pInterfaceId==SL_IID_ANDROIDCONFIGURATION) nm="androidconfiguration";
872
else if (pInterfaceId==SL_IID_ANDROIDSIMPLEBUFFERQUEUE) nm="simplebuferqueue";
873
//else if (pInterfaceId==//SL_IID_ANDROIDBUFFERQUEUESOURCE) nm="bufferqueuesource";