Home | History | Annotate | Download | only in audio_loopback

Lines Matching refs:pSles

42         sles_data * pSles = (sles_data*) calloc(1, sizeof (sles_data));
44 SLES_PRINTF("malloc %zu bytes at %p", sizeof(sles_data), pSles);
45 *ppSles = pSles;
46 if (pSles != NULL)
50 status = slesCreateServer(pSles, samplingRate, frameCount, micSource,
78 sles_data *pSles = (sles_data*) context;
79 if (pSles != NULL) {
85 pthread_mutex_lock(&(pSles->mutex));
89 assert(pSles->rxFront <= pSles->rxBufCount);
90 assert(pSles->rxRear <= pSles->rxBufCount);
91 assert(pSles->rxFront != pSles->rxRear);
92 char *buffer = pSles->rxBuffers[pSles->rxFront];
95 if (++pSles->rxFront > pSles->rxBufCount) {
96 pSles->rxFront = 0;
100 if (pSles->numFramesToIgnore) {
101 SLuint32 framesToErase = pSles->numFramesToIgnore;
102 if (framesToErase > pSles->bufSizeInFrames) {
103 framesToErase = pSles->bufSizeInFrames;
105 pSles->numFramesToIgnore -= framesToErase;
107 memset(buffer, 0, framesToErase * pSles->channels * sizeof(short));
110 ssize_t actual = audio_utils_fifo_write(&(pSles->fifo), buffer,
111 (size_t) pSles->bufSizeInFrames);
112 if (actual != (ssize_t) pSles->bufSizeInFrames) {
119 if (pSles->fifo2Buffer != NULL) {
120 actual = audio_utils_fifo_write(&(pSles->fifo2), buffer,
121 (size_t) pSles->bufSizeInFrames);
122 if (actual != (ssize_t) pSles->bufSizeInFrames) {
128 result = (*(pSles->recorderBufferQueue))->Enqueue(pSles->recorderBufferQueue, buffer,
129 pSles->bufSizeInBytes);
133 SLuint32 rxRearNext = pSles->rxRear+1;
134 if (rxRearNext > pSles->rxBufCount) {
137 assert(rxRearNext != pSles->rxFront);
138 pSles->rxBuffers[pSles->rxRear] = buffer;
139 pSles->rxRear = rxRearNext;
144 pthread_mutex_unlock(&(pSles->mutex));
146 } //pSles not null
152 sles_data *pSles = (sles_data*) context;
153 if (pSles != NULL) {
157 pthread_mutex_lock(&(pSles->mutex));
161 assert(pSles->txFront <= pSles->txBufCount);
162 assert(pSles->txRear <= pSles->txBufCount);
163 assert(pSles->txFront != pSles->txRear);
164 char *buffer = pSles->txBuffers[pSles->txFront];
165 if (++pSles->txFront > pSles->txBufCount) {
166 pSles->txFront = 0;
170 ssize_t actual = audio_utils_fifo_read(&(pSles->fifo), buffer, pSles->bufSizeInFrames);
171 if (actual != (ssize_t) pSles->bufSizeInFrames) {
174 memset(buffer, 0, pSles->bufSizeInFrames * pSles->channels * sizeof(short));
177 if (pSles->injectImpulse == -1) {
182 for (unsigned i = 0; i < pSles->bufSizeInFrames / 8; i += 8) {
184 for (unsigned k = 0; k < pSles->channels; k++) {
185 ((short *)buffer)[(i+j)*pSles->channels+k] = j < 4 ? 0x7FFF : 0x8000;
189 pSles->injectImpulse = 0;
193 result = (*(pSles->playerBufferQueue))->Enqueue(pSles->playerBufferQueue, buffer,
194 pSles->bufSizeInBytes);
198 assert(pSles->txFront <= pSles->txBufCount);
199 assert(pSles->txRear <= pSles->txBufCount);
200 SLuint32 txRearNext = pSles->txRear+1;
201 if (txRearNext > pSles->txBufCount) {
204 assert(txRearNext != pSles->txFront);
205 pSles->txBuffers[pSles->txRear] = buffer;
206 pSles->txRear = txRearNext;
210 pthread_mutex_unlock(&(pSles->mutex));
212 } //pSles not null
215 int slesCreateServer(sles_data *pSles, int samplingRate, int frameCount,
219 if (pSles == NULL) {
261 pSles->rxBufCount = 1; // -r#
262 pSles->txBufCount = 1; // -t#
263 pSles->bufSizeInFrames = frameCount;//240; // -f#
264 pSles->channels = 1; // -c#
265 pSles->sampleRate = samplingRate;//48000; // -s#
266 pSles->exitAfterSeconds = 3; // -e#
267 pSles->freeBufCount = 0; // calculated
268 pSles->bufSizeInBytes = 0; // calculated
269 pSles->injectImpulse = 300; // -i#i
272 pSles->numFramesToIgnore = numFramesToIgnore;
274 pSles->numFramesToIgnore = 0;
284 pSles->rxFront; // oldest recording
285 pSles->rxRear; // next to be recorded
286 pSles->txFront; // oldest playing
287 pSles->txRear; // next to be played
288 pSles->freeFront; // oldest free
289 pSles->freeRear; // next to be freed
291 pSles->fifo; //(*)
293 pSles->fifo2Buffer = NULL;
296 pSles->freeBufCount = pSles->rxBufCount + pSles->txBufCount;
298 pSles->bufSizeInBytes = pSles->channels * pSles->bufSizeInFrames * sizeof(short);
301 pSles->freeBuffers = (char **) calloc(pSles->freeBufCount+1, sizeof(char *));
303 for (j = 0; j < pSles->freeBufCount; ++j) {
304 pSles->freeBuffers[j] = (char *) malloc(pSles->bufSizeInBytes);
306 pSles->freeFront = 0;
307 pSles->freeRear = pSles->freeBufCount;
308 pSles->freeBuffers[j] = NULL;
311 pSles->rxBuffers = (char **) calloc(pSles->rxBufCount+1, sizeof(char *));
312 pSles->rxFront = 0;
313 pSles->rxRear = 0;
316 pSles->txBuffers = (char **) calloc(pSles->txBufCount+1, sizeof(char *));
317 pSles->txFront = 0;
318 pSles->txRear = 0;
320 size_t frameSize = pSles->channels * sizeof(short);
322 pSles->fifoBuffer = new short[FIFO_FRAMES * pSles->channels];
323 audio_utils_fifo_init(&(pSles->fifo), FIFO_FRAMES, frameSize, pSles->fifoBuffer);
336 pSles->fifo2Buffer = new short[FIFO2_FRAMES * pSles->channels];
337 audio_utils_fifo_init(&(pSles->fifo2), FIFO2_FRAMES, frameSize, pSles->fifo2Buffer);
348 result = slCreateEngine(&(pSles->engineObject), 0, NULL, 0, NULL, NULL);
350 result = (*(pSles->engineObject))->Realize(pSles->engineObject, SL_BOOLEAN_FALSE);
353 result = (*(pSles->engineObject))->GetInterface(pSles->engineObject, SL_IID_ENGINE,
358 result = (*engineEngine)->CreateOutputMix(engineEngine, &(pSles->outputmixObject), 0, NULL,
361 result = (*(pSles->outputmixObject))->Realize(pSles->outputmixObject, SL_BOOLEAN_FALSE);
371 locator_bufferqueue_tx.numBuffers = pSles->txBufCount;
373 locator_outputmix.outputMix = pSles->outputmixObject;
375 pcm.numChannels = pSles->channels;
376 pcm.samplesPerSec = pSles->sampleRate * 1000;
379 pcm.channelMask = pSles->channels == 1 ? SL_SPEAKER_FRONT_CENTER :
386 pSles->playerObject = NULL;
387 pSles->recorderObject = NULL;
390 result = (*engineEngine)->CreateAudioPlayer(engineEngine, &(pSles->playerObject),
400 result = (*(pSles->playerObject))->Realize(pSles->playerObject, SL_BOOLEAN_FALSE);
403 result = (*(pSles->playerObject))->GetInterface(pSles->playerObject, SL_IID_PLAY,
406 result = (*(pSles->playerObject))->GetInterface(pSles->playerObject, SL_IID_BUFFERQUEUE,
407 &(pSles->playerBufferQueue));
409 result = (*(pSles->playerBufferQueue))->RegisterCallback(pSles->playerBufferQueue,
410 playerCallback, pSles);
414 for (j = 0; j < pSles->txBufCount; ++j) {
417 assert(pSles->freeFront != pSles->freeRear);
418 char *buffer = pSles->freeBuffers[pSles->freeFront];
419 if (++pSles->freeFront > pSles->freeBufCount) {
420 pSles->freeFront = 0;
424 SLuint32 txRearNext = pSles->txRear + 1;
425 if (txRearNext > pSles->txBufCount) {
428 assert(txRearNext != pSles->txFront);
429 pSles->txBuffers[pSles->txRear] = buffer;
430 pSles->txRear = txRearNext;
431 result = (*(pSles->playerBufferQueue))->Enqueue(pSles->playerBufferQueue,
432 buffer, pSles->bufSizeInBytes);
451 locator_bufferqueue_rx.numBuffers = pSles->rxBufCount;
458 result = (*engineEngine)->CreateAudioRecorder(engineEngine, &(pSles->recorderObject),
475 result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject,
488 result = (*(pSles->recorderObject))->Realize(pSles->recorderObject, SL_BOOLEAN_FALSE);
491 result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject, SL_IID_RECORD,
494 result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject,
495 SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &(pSles->recorderBufferQueue));
497 result = (*(pSles->recorderBufferQueue))->RegisterCallback(pSles->recorderBufferQueue,
498 recorderCallback, pSles);
502 for (j = 0; j < pSles->rxBufCount; ++j) {
505 assert(pSles->freeFront != pSles->freeRear);
506 char *buffer = pSles->freeBuffers[pSles->freeFront];
507 if (++pSles->freeFront > pSles->freeBufCount) {
508 pSles->freeFront = 0;
512 SLuint32 rxRearNext = pSles->rxRear + 1;
513 if (rxRearNext > pSles->rxBufCount) {
516 assert(rxRearNext != pSles->rxFront);
517 pSles->rxBuffers[pSles->rxRear] = buffer;
518 pSles->rxRear = rxRearNext;
519 result = (*(pSles->recorderBufferQueue))->Enqueue(pSles->recorderBufferQueue,
520 buffer, pSles->bufSizeInBytes);
536 int slesProcessNext(sles_data *pSles, double *pSamples, long maxSamples) {
539 SLES_PRINTF("slesProcessNext: pSles = %p, currentSample: %p, maxSamples = %ld", pSles,
548 if (pSles == NULL) {
555 if (pSles->fifo2Buffer != NULL) {
557 short buffer[pSles->bufSizeInFrames * pSles->channels];
558 ssize_t actual = audio_utils_fifo_read(&(pSles->fifo2), buffer,
559 pSles->bufSizeInFrames);
571 if (pSles->injectImpulse > 0) {
572 if (pSles->injectImpulse <= 100) {
573 pSles->injectImpulse = -1;
576 if ((pSles->injectImpulse % 1000) < 100) {
579 pSles->injectImpulse -= 100;
586 result = (*(pSles->playerBufferQueue))->GetState(pSles->playerBufferQueue,
590 result = (*(pSles->recorderBufferQueue))->GetState(pSles->recorderBufferQueue,
594 SLES_PRINTF("End of slesProcessNext: pSles = %p, samplesRead = %d, maxSamples= %ld", pSles,
600 int slesDestroyServer(sles_data *pSles) {
603 SLES_PRINTF("Start slesDestroyServer: pSles = %p", pSles);
604 if (pSles == NULL) {
608 if (NULL != pSles->playerObject) {
612 SLresult result = (*(pSles->playerObject))->GetInterface(pSles->playerObject,
622 if (NULL != pSles->recorderObject) {
625 SLresult result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject,
635 audio_utils_fifo_deinit(&(pSles->fifo));
636 delete[] pSles->fifoBuffer;
641 audio_utils_fifo_deinit(&(pSles->fifo2));
642 delete[] pSles->fifo2Buffer;
648 if (NULL != pSles->playerObject) {
649 (*(pSles->playerObject))->Destroy(pSles->playerObject);
654 if (NULL != pSles->recorderObject) {
655 (*(pSles->recorderObject))->Destroy(pSles->recorderObject);
660 (*(pSles->outputmixObject))->Destroy(pSles->outputmixObject);
662 (*(pSles->engineObject))->Destroy(pSles->engineObject);
665 // free(pSles);
666 // pSles=NULL;