// 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; }
int main_circularbuffer() { /* Benchmark for 100 MB of data at the time of writing with gcc -O9 real 0m0.347s user 0m0.345s sys 0m0.001s With gcc -O2 real 0m0.539s user 0m0.535s sys 0m0.000s */ CircularBuffer* state = create_circular_buffer(3); push_circular_buffer(state, 'x'); push_circular_buffer(state, 'x'); push_circular_buffer(state, 'x'); for(int i=0;i<100000000; i++){ rotate_circular_buffer(state, 'a'); } destroy_circular_buffer(state); return 0; }