OPENSL_SND *opensl_open(int sr, int outchannels, int bufferframes){ OPENSL_SND *p; p = (OPENSL_SND *) malloc(sizeof(OPENSL_SND)); memset(p, 0, sizeof(OPENSL_SND)); p->outchannels = outchannels; p->sr = sr; if((p->outBufSamples = bufferframes*outchannels) != 0) { if((p->outputBuffer = (short *) calloc(p->outBufSamples, sizeof(short))) == NULL) { opensl_close(p); return NULL; } } if(opensl_createEngine(p) != SL_RESULT_SUCCESS) { opensl_close(p); return NULL; } if(opensl_playOpen(p) != SL_RESULT_SUCCESS) { opensl_close(p); return NULL; } return p; }
void myosd_closeSound(void) { if( soundInit == 1 ) { #ifdef ANDROID __android_log_print(ANDROID_LOG_DEBUG, "MAME4droid.so", "closeSound"); #endif if(sound_engine==1) { if(closeSound_callback!=NULL) closeSound_callback(); } else { if(p!=NULL) opensl_close(p); } soundInit = 0; } }
audio_module_runner *ami_create(int version, int token, int index) { if (version != PATCHFIELD_PROTOCOL_VERSION) { LOGW("Protocol version mismatch."); return NULL; } audio_module_runner *amr = malloc(sizeof(audio_module_runner)); if (amr) { amr->shm_fd = token; amr->shm_ptr = smi_map(token); smi_protect(amr->shm_ptr, get_protected_size()); amr->index = index; amr->done = 0; amr->timed_out = 0; amr->process = NULL; amr->context = NULL; amr->launch_counter = 3; // Make sure that this number stays current. audio_module *module = ami_get_audio_module(amr->shm_ptr, amr->index); // Clear barriers, just in case. sb_clobber(ami_get_barrier(amr->shm_ptr, module->report)); sb_clobber(ami_get_barrier(amr->shm_ptr, module->wake)); sb_clobber(ami_get_barrier(amr->shm_ptr, module->ready)); OPENSL_STREAM *os = opensl_open(module->sample_rate, 0, 2, module->buffer_frames, launch_thread, amr); sb_clobber(&amr->launched); opensl_start(os); sb_wait(&amr->launched, NULL); opensl_close(os); struct sigaction act; act.sa_sigaction = signal_handler; act.sa_flags = SA_SIGINFO; sigfillset(&act.sa_mask); sigaction(AM_SIG_ALRM, &act, NULL); } return (audio_module_runner *) amr; }