int opensles_player_alloc(struct auplay_st **stp, struct auplay *ap, struct auplay_prm *prm, const char *device, auplay_write_h *wh, void *arg) { struct auplay_st *st; int err; (void)device; st = mem_zalloc(sizeof(*st), auplay_destructor); if (!st) return ENOMEM; st->ap = mem_ref(ap); st->wh = wh; st->arg = arg; err = createOutput(st); if (err) goto out; err = createPlayer(st, prm); if (err) goto out; bqPlayerCallback(st->BufferQueue, st); out: if (err) mem_deref(st); else *stp = st; return err; }
// init mididriver jboolean Java_org_billthefarmer_accordion_MidiDriver_init(JNIEnv *env, jobject obj) { EAS_RESULT result; if (result = initEAS() != EAS_SUCCESS) { shutdownEAS(); LOG_E(LOG_TAG, "Init EAS failed: %ld", result); return JNI_FALSE; } // LOG_D(LOG_TAG, "Init EAS success, buffer: %ld", bufferSize); // allocate buffer in bytes buffer = (EAS_PCM *)malloc(bufferSize * sizeof(EAS_PCM)); if (buffer == NULL) { shutdownEAS(); LOG_E(LOG_TAG, "Allocate buffer failed"); return JNI_FALSE; } // create the engine and output mix objects if (result = createEngine() != SL_RESULT_SUCCESS) { shutdownEAS(); shutdownAudio(); free(buffer); buffer = NULL; LOG_E(LOG_TAG, "Create engine failed: %ld", result); return JNI_FALSE; } // create buffer queue audio player if (result = createBufferQueueAudioPlayer() != SL_RESULT_SUCCESS) { shutdownEAS(); shutdownAudio(); free(buffer); buffer = NULL; LOG_E(LOG_TAG, "Create buffer queue audio player failed: %ld", result); return JNI_FALSE; } // call the callback to start playing bqPlayerCallback(bqPlayerBufferQueue, NULL); return JNI_TRUE; }
int opensles_player_alloc(struct auplay_st **stp, const struct auplay *ap, struct auplay_prm *prm, const char *device, auplay_write_h *wh, void *arg) { struct auplay_st *st; int err; (void)device; if (!stp || !ap || !prm || !wh) return EINVAL; debug("opensles: opening player %uHz, %uchannels\n", prm->srate, prm->ch); st = mem_zalloc(sizeof(*st), auplay_destructor); if (!st) return ENOMEM; st->ap = ap; st->wh = wh; st->arg = arg; st->sampc = prm->srate * prm->ch * PTIME / 1000; st->bufferId = 0; for (int i=0; i<N_PLAY_QUEUE_BUFFERS; i++) { st->sampv[i] = mem_zalloc(2 * st->sampc, NULL); if (!st->sampv[i]) { err = ENOMEM; goto out; } } err = createOutput(st); if (err) goto out; err = createPlayer(st, prm); if (err) goto out; /* kick-start the buffer callback */ bqPlayerCallback(st->BufferQueue, st); out: if (err) mem_deref(st); else *stp = st; return err; }
void SNDOpenSLUpdateAudio(s16 *buffer, u32 num_samples) { for(int i = 0 ; i < NUM_BUFFERS ; ++i) { if(buffers[i].avail) { memcpy(buffers[i].data, buffer, sizeof(s16) * 2 * num_samples); int currentSoundBuffer = nextSoundBuffer; buffers[i].samples = num_samples; buffers[i].avail = false; nextSoundBuffer = i; if(!currentlyPlaying) { (*bqPlayerBufferQueue)->Clear(bqPlayerBufferQueue); bqPlayerCallback(bqPlayerBufferQueue, NULL); currentlyPlaying = true; } //LOGI("Copied %d samples to buffer %d", num_samples, nextSoundBuffer); return; } } //should never get here... }