Home | History | Annotate | Download | only in audio_loopback

Lines Matching refs:pSles

41         sles_data * pSles = (sles_data*) calloc(1, sizeof (sles_data));
43 SLES_PRINTF("malloc %d bytes at %p",sizeof(sles_data), pSles);
44 *ppSles = pSles;
45 if (pSles != NULL)
49 status = slesCreateServer(pSles, samplingRate, frameCount, micSource);
76 sles_data *pSles = (sles_data*) context;
77 if (pSles != NULL) {
83 pthread_mutex_lock(&(pSles->mutex));
87 assert(pSles->rxFront <= pSles->rxBufCount);
88 assert(pSles->rxRear <= pSles->rxBufCount);
89 assert(pSles->rxFront != pSles->rxRear);
90 char *buffer = pSles->rxBuffers[pSles->rxFront];
93 if (++pSles->rxFront > pSles->rxBufCount) {
94 pSles->rxFront = 0;
97 ssize_t actual = audio_utils_fifo_write(&(pSles->fifo), buffer,
98 (size_t) pSles->bufSizeInFrames);
99 if (actual != (ssize_t) pSles->bufSizeInFrames) {
106 if (pSles->fifo2Buffer != NULL) {
107 actual = audio_utils_fifo_write(&(pSles->fifo2), buffer,
108 (size_t) pSles->bufSizeInFrames);
109 if (actual != (ssize_t) pSles->bufSizeInFrames) {
115 result = (*(pSles->recorderBufferQueue))->Enqueue(pSles->recorderBufferQueue, buffer,
116 pSles->bufSizeInBytes);
120 SLuint32 rxRearNext = pSles->rxRear+1;
121 if (rxRearNext > pSles->rxBufCount) {
124 assert(rxRearNext != pSles->rxFront);
125 pSles->rxBuffers[pSles->rxRear] = buffer;
126 pSles->rxRear = rxRearNext;
131 pthread_mutex_unlock(&(pSles->mutex));
133 } //pSles not null
139 sles_data *pSles = (sles_data*) context;
140 if (pSles != NULL) {
144 pthread_mutex_lock(&(pSles->mutex));
148 assert(pSles->txFront <= pSles->txBufCount);
149 assert(pSles->txRear <= pSles->txBufCount);
150 assert(pSles->txFront != pSles->txRear);
151 char *buffer = pSles->txBuffers[pSles->txFront];
152 if (++pSles->txFront > pSles->txBufCount) {
153 pSles->txFront = 0;
157 ssize_t actual = audio_utils_fifo_read(&(pSles->fifo), buffer, pSles->bufSizeInFrames);
158 if (actual != (ssize_t) pSles->bufSizeInFrames) {
161 memset(buffer, 0, pSles->bufSizeInFrames * pSles->channels * sizeof(short));
164 if (pSles->injectImpulse == -1) {
169 for (unsigned i = 0; i < pSles->bufSizeInFrames / 8; i += 8) {
171 for (unsigned k = 0; k < pSles->channels; k++) {
172 ((short *)buffer)[(i+j)*pSles->channels+k] = j < 4 ? 0x7FFF : 0x8000;
176 pSles->injectImpulse = 0;
180 result = (*(pSles->playerBufferQueue))->Enqueue(pSles->playerBufferQueue, buffer,
181 pSles->bufSizeInBytes);
185 assert(pSles->txFront <= pSles->txBufCount);
186 assert(pSles->txRear <= pSles->txBufCount);
187 SLuint32 txRearNext = pSles->txRear+1;
188 if (txRearNext > pSles->txBufCount) {
191 assert(txRearNext != pSles->txFront);
192 pSles->txBuffers[pSles->txRear] = buffer;
193 pSles->txRear = txRearNext;
197 pthread_mutex_unlock(&(pSles->mutex));
199 } //pSles not null
202 int slesCreateServer(sles_data *pSles, int samplingRate, int frameCount, int micSource) {
205 if (pSles == NULL) {
247 pSles->rxBufCount = 1; // -r#
248 pSles->txBufCount = 1; // -t#
249 pSles->bufSizeInFrames = frameCount;//240; // -f#
250 pSles->channels = 1; // -c#
251 pSles->sampleRate = samplingRate;//48000; // -s#
252 pSles->exitAfterSeconds = 3; // -e#
253 pSles->freeBufCount = 0; // calculated
254 pSles->bufSizeInBytes = 0; // calculated
255 pSles->injectImpulse = 300; // -i#i
263 pSles->rxFront; // oldest recording
264 pSles->rxRear; // next to be recorded
265 pSles->txFront; // oldest playing
266 pSles->txRear; // next to be played
267 pSles->freeFront; // oldest free
268 pSles->freeRear; // next to be freed
270 pSles->fifo; //(*)
271 pSles->fifo2Buffer = NULL;
272 pSles->recorderBufferQueue;
273 pSles->playerBufferQueue;
276 pSles->freeBufCount = pSles->rxBufCount + pSles->txBufCount;
278 pSles->bufSizeInBytes = pSles->channels * pSles->bufSizeInFrames * sizeof(short);
281 pSles->freeBuffers = (char **) calloc(pSles->freeBufCount+1, sizeof(char *));
283 for (j = 0; j < pSles->freeBufCount; ++j) {
284 pSles->freeBuffers[j] = (char *) malloc(pSles->bufSizeInBytes);
286 pSles->freeFront = 0;
287 pSles->freeRear = pSles->freeBufCount;
288 pSles->freeBuffers[j] = NULL;
291 pSles->rxBuffers = (char **) calloc(pSles->rxBufCount+1, sizeof(char *));
292 pSles->rxFront = 0;
293 pSles->rxRear = 0;
296 pSles->txBuffers = (char **) calloc(pSles->txBufCount+1, sizeof(char *));
297 pSles->txFront = 0;
298 pSles->txRear = 0;
300 size_t frameSize = pSles->channels * sizeof(short);
302 pSles->fifoBuffer = new short[FIFO_FRAMES * pSles->channels];
303 audio_utils_fifo_init(&(pSles->fifo), FIFO_FRAMES, frameSize, pSles->fifoBuffer);
316 pSles->fifo2Buffer = new short[FIFO2_FRAMES * pSles->channels];
317 audio_utils_fifo_init(&(pSles->fifo2), FIFO2_FRAMES, frameSize, pSles->fifo2Buffer);
328 pSles->engineObject;
329 result = slCreateEngine(&(pSles->engineObject), 0, NULL, 0, NULL, NULL);
331 result = (*(pSles->engineObject))->Realize(pSles->engineObject, SL_BOOLEAN_FALSE);
334 result = (*(pSles->engineObject))->GetInterface(pSles->engineObject, SL_IID_ENGINE,
339 pSles->outputmixObject;
340 result = (*engineEngine)->CreateOutputMix(engineEngine, &(pSles->outputmixObject), 0, NULL,
343 result = (*(pSles->outputmixObject))->Realize(pSles->outputmixObject, SL_BOOLEAN_FALSE);
353 locator_bufferqueue_tx.numBuffers = pSles->txBufCount;
355 locator_outputmix.outputMix = pSles->outputmixObject;
357 pcm.numChannels = pSles->channels;
358 pcm.samplesPerSec = pSles->sampleRate * 1000;
361 pcm.channelMask = pSles->channels == 1 ? SL_SPEAKER_FRONT_CENTER :
368 pSles->playerObject = NULL;
369 pSles->recorderObject = NULL;
372 result = (*engineEngine)->CreateAudioPlayer(engineEngine, &(pSles->playerObject),
382 result = (*(pSles->playerObject))->Realize(pSles->playerObject, SL_BOOLEAN_FALSE);
385 result = (*(pSles->playerObject))->GetInterface(pSles->playerObject, SL_IID_PLAY,
388 result = (*(pSles->playerObject))->GetInterface(pSles->playerObject, SL_IID_BUFFERQUEUE,
389 &(pSles->playerBufferQueue));
391 result = (*(pSles->playerBufferQueue))->RegisterCallback(pSles->playerBufferQueue,
392 playerCallback, pSles);
396 for (j = 0; j < pSles->txBufCount; ++j) {
399 assert(pSles->freeFront != pSles->freeRear);
400 char *buffer = pSles->freeBuffers[pSles->freeFront];
401 if (++pSles->freeFront > pSles->freeBufCount) {
402 pSles->freeFront = 0;
406 SLuint32 txRearNext = pSles->txRear + 1;
407 if (txRearNext > pSles->txBufCount) {
410 assert(txRearNext != pSles->txFront);
411 pSles->txBuffers[pSles->txRear] = buffer;
412 pSles->txRear = txRearNext;
413 result = (*(pSles->playerBufferQueue))->Enqueue(pSles->playerBufferQueue,
414 buffer, pSles->bufSizeInBytes);
433 locator_bufferqueue_rx.numBuffers = pSles->rxBufCount;
440 result = (*engineEngine)->CreateAudioRecorder(engineEngine, &(pSles->recorderObject),
457 result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject,
470 result = (*(pSles->recorderObject))->Realize(pSles->recorderObject, SL_BOOLEAN_FALSE);
473 result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject, SL_IID_RECORD,
476 result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject,
477 SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &(pSles->recorderBufferQueue));
479 result = (*(pSles->recorderBufferQueue))->RegisterCallback(pSles->recorderBufferQueue,
480 recorderCallback, pSles);
484 for (j = 0; j < pSles->rxBufCount; ++j) {
487 assert(pSles->freeFront != pSles->freeRear);
488 char *buffer = pSles->freeBuffers[pSles->freeFront];
489 if (++pSles->freeFront > pSles->freeBufCount) {
490 pSles->freeFront = 0;
494 SLuint32 rxRearNext = pSles->rxRear + 1;
495 if (rxRearNext > pSles->rxBufCount) {
498 assert(rxRearNext != pSles->rxFront);
499 pSles->rxBuffers[pSles->rxRear] = buffer;
500 pSles->rxRear = rxRearNext;
501 result = (*(pSles->recorderBufferQueue))->Enqueue(pSles->recorderBufferQueue,
502 buffer, pSles->bufSizeInBytes);
518 int slesProcessNext(sles_data *pSles, double *pSamples, long maxSamples) {
521 SLES_PRINTF("slesProcessNext: pSles = %p, currentSample: %p, maxSamples = %ld", pSles,
530 if (pSles == NULL) {
537 if (pSles->fifo2Buffer != NULL) {
539 short buffer[pSles->bufSizeInFrames * pSles->channels];
540 ssize_t actual = audio_utils_fifo_read(&(pSles->fifo2), buffer,
541 pSles->bufSizeInFrames);
553 if (pSles->injectImpulse > 0) {
554 if (pSles->injectImpulse <= 100) {
555 pSles->injectImpulse = -1;
558 if ((pSles->injectImpulse % 1000) < 100) {
561 pSles->injectImpulse -= 100;
568 result = (*(pSles->playerBufferQueue))->GetState(pSles->playerBufferQueue,
572 result = (*(pSles->recorderBufferQueue))->GetState(pSles->recorderBufferQueue,
576 SLES_PRINTF("End of slesProcessNext: pSles = %p, samplesRead = %d, maxSamples= %ld", pSles,
582 int slesDestroyServer(sles_data *pSles) {
585 SLES_PRINTF("Start slesDestroyServer: pSles = %p", pSles);
586 if (pSles == NULL) {
590 if (NULL != pSles->playerObject) {
594 SLresult result = (*(pSles->playerObject))->GetInterface(pSles->playerObject,
604 if (NULL != pSles->recorderObject) {
607 SLresult result = (*(pSles->recorderObject))->GetInterface(pSles->recorderObject,
617 audio_utils_fifo_deinit(&(pSles->fifo));
618 delete[] pSles->fifoBuffer;
623 audio_utils_fifo_deinit(&(pSles->fifo2));
624 delete[] pSles->fifo2Buffer;
630 if (NULL != pSles->playerObject) {
631 (*(pSles->playerObject))->Destroy(pSles->playerObject);
636 if (NULL != pSles->recorderObject) {
637 (*(pSles->recorderObject))->Destroy(pSles->recorderObject);
642 (*(pSles->outputmixObject))->Destroy(pSles->outputmixObject);
644 (*(pSles->engineObject))->Destroy(pSles->engineObject);
647 // free(pSles);
648 // pSles=NULL;