// open the android audio device for input and/or output OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes){ OPENSL_STREAM *p; p = (OPENSL_STREAM *) malloc(sizeof(OPENSL_STREAM)); memset(p, 0, sizeof(OPENSL_STREAM)); p->outchannels = outchannels; p->sr = sr; if((p->outBufSamples = bufferframes*outchannels) != 0) { if((p->outputBuffer = (short *) calloc(p->outBufSamples, sizeof(short))) == NULL) { android_CloseAudioDevice(p); return NULL; } } if((p->outrb = create_circular_buffer(p->outBufSamples*sizeof(short)*4)) == NULL) { android_CloseAudioDevice(p); return NULL; } if(openSLCreateEngine(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } if(openSLPlayOpen(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } return p; }
// open the android audio device for and/or output OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels, int bufferframes) { OPENSL_STREAM* p; p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1); if (!p) return NULL; p->queuesize = bufferframes; p->outchannels = outchannels; p->sr = sr; if (openSLCreateEngine(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } if (openSLPlayOpen(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } p->queue = Queue_New(TRUE, -1, -1); if (!p->queue) { android_CloseAudioDevice(p); return NULL; } return p; }
void * startThreadOutAudio(void * arg){ LOGI("Enter: startThreadOutAudio\n"); //return NULL; mainData_t* mainData = (mainData_t*)arg; SLresult res; SLObjectItf sl; SLEngineOption EngineOption[] = { (SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE}; res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); if(res != SL_RESULT_SUCCESS){ LOGE("Exit: startThreadOutAudio: Can't create OpenSL engine\n"); return 0; } /* Realizing the SL Engine in synchronous mode. */ res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); if(res != SL_RESULT_SUCCESS){ LOGE("Exit: startThreadOutAudio: Can't Realize OpenSL engine\n"); /* Shutdown OpenSL ES */ (*sl)->Destroy(sl); return 0; } openSLPlayOpen(mainData,sl); /* Shutdown OpenSL ES */ (*sl)->Destroy(sl); LOGI("Exit: startThreadOutAudio: OK\n"); return 0; }
// open the android audio device for input and/or output OPENSL_STREAM *android_OpenAudioDevice(int sr, int inchannels, int outchannels, int bufferframes) { OPENSL_STREAM *p; p = (OPENSL_STREAM *) calloc(sizeof(OPENSL_STREAM), 1); p->inchannels = inchannels; p->outchannels = outchannels; p->sr = sr; p->inlock = createThreadLock(); p->outlock = createThreadLock(); if ((p->outBufSamples = bufferframes * outchannels) != 0) { if ((p->outputBuffer[0] = (short *) calloc(p->outBufSamples, sizeof(short))) == NULL || (p->outputBuffer[1] = (short *) calloc(p->outBufSamples, sizeof(short))) == NULL) { android_CloseAudioDevice(p); return NULL; } } if ((p->inBufSamples = bufferframes * inchannels) != 0) { if ((p->inputBuffer[0] = (short *) calloc(p->inBufSamples, sizeof(short))) == NULL || (p->inputBuffer[1] = (short *) calloc(p->inBufSamples, sizeof(short))) == NULL) { android_CloseAudioDevice(p); return NULL; } } p->currentInputIndex = 0; p->currentOutputBuffer = 0; p->currentInputIndex = p->inBufSamples; p->currentInputBuffer = 0; if (openSLCreateEngine(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } if (openSLRecOpen(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } if (openSLPlayOpen(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } notifyThreadLock(p->outlock); notifyThreadLock(p->inlock); p->time = 0.; return p; }
// open the android audio device for input and/or output OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes, int nrbuffers){ OPENSL_STREAM *p; p = (OPENSL_STREAM *) malloc(sizeof(OPENSL_STREAM)); if(p == NULL) return NULL; memset(p, 0, sizeof(OPENSL_STREAM)); p->outchannels = outchannels; p->sr = sr; p->outBufSamples = bufferframes * outchannels; p->nrbuffers = nrbuffers; p->outBufBytes = p->outBufSamples * sizeof(short); short *bfr = (short *)calloc(p->outBufSamples * p->nrbuffers, sizeof(short)); if(bfr == NULL) { free(p); return NULL; } p->buffer = (short **)malloc(sizeof(short *) * p->nrbuffers); if(p->buffer == NULL) { free(p); free(bfr); } int k; for(k = 0; k < p->nrbuffers; k++) { p->buffer[k] = &bfr[k * p->outBufSamples]; } if(openSLCreateEngine(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } if(openSLPlayOpen(p) != SL_RESULT_SUCCESS) { android_CloseAudioDevice(p); return NULL; } return p; }