diff options
-rw-r--r-- | modules/alsa/alsa_play.c | 4 | ||||
-rw-r--r-- | modules/alsa/alsa_src.c | 16 | ||||
-rw-r--r-- | modules/opensles/player.c | 16 | ||||
-rw-r--r-- | modules/opensles/recorder.c | 20 | ||||
-rw-r--r-- | modules/oss/oss.c | 28 | ||||
-rw-r--r-- | modules/winwave/play.c | 2 | ||||
-rw-r--r-- | modules/winwave/src.c | 2 |
7 files changed, 51 insertions, 37 deletions
diff --git a/modules/alsa/alsa_play.c b/modules/alsa/alsa_play.c index 1826f15..ebd8146 100644 --- a/modules/alsa/alsa_play.c +++ b/modules/alsa/alsa_play.c @@ -115,8 +115,8 @@ int alsa_play_alloc(struct auplay_st **stp, struct auplay *ap, st->sampc = prm->srate * prm->ch * prm->ptime / 1000; num_frames = st->prm.srate * st->prm.ptime / 1000; - st->sampv = mem_alloc(2 * st->sampc); - if (!st->mbw) { + st->sampv = mem_alloc(2 * st->sampc, NULL); + if (!st->sampv) { err = ENOMEM; goto out; } diff --git a/modules/alsa/alsa_src.c b/modules/alsa/alsa_src.c index 4e2a16a..f95765c 100644 --- a/modules/alsa/alsa_src.c +++ b/modules/alsa/alsa_src.c @@ -21,7 +21,8 @@ struct ausrc_st { pthread_t thread; bool run; snd_pcm_t *read; - struct mbuf *mbr; + int16_t *sampv; + size_t sampc; ausrc_read_h *rh; void *arg; struct ausrc_prm prm; @@ -42,7 +43,7 @@ static void ausrc_destructor(void *arg) if (st->read) snd_pcm_close(st->read); - mem_deref(st->mbr); + mem_deref(st->sampv); mem_deref(st->as); mem_deref(st->device); } @@ -65,7 +66,7 @@ static void *read_thread(void *arg) } while (st->run) { - err = snd_pcm_readi(st->read, st->mbr->buf, num_frames); + err = snd_pcm_readi(st->read, st->sampv, num_frames); if (err == -EPIPE) { snd_pcm_prepare(st->read); continue; @@ -74,7 +75,7 @@ static void *read_thread(void *arg) continue; } - st->rh(st->mbr->buf, err * 2 * st->prm.ch, st->arg); + st->rh(st->sampv, err * st->prm.ch, st->arg); } out: @@ -88,7 +89,6 @@ int alsa_src_alloc(struct ausrc_st **stp, struct ausrc *as, ausrc_read_h *rh, ausrc_error_h *errh, void *arg) { struct ausrc_st *st; - uint32_t sampc; int num_frames; int err; (void)ctx; @@ -113,11 +113,11 @@ int alsa_src_alloc(struct ausrc_st **stp, struct ausrc *as, st->rh = rh; st->arg = arg; - sampc = prm->srate * prm->ch * prm->ptime / 1000; + st->sampc = prm->srate * prm->ch * prm->ptime / 1000; num_frames = st->prm.srate * st->prm.ptime / 1000; - st->mbr = mbuf_alloc(2 * sampc); - if (!st->mbr) { + st->sampv = mem_alloc(2 * st->sampc, NULL); + if (!st->sampv) { err = ENOMEM; goto out; } diff --git a/modules/opensles/player.c b/modules/opensles/player.c index a317e5d..b9c9b68 100644 --- a/modules/opensles/player.c +++ b/modules/opensles/player.c @@ -17,7 +17,8 @@ struct auplay_st { struct auplay *ap; /* inheritance */ - int16_t buf[160 * 2]; + int16_t *sampv; + size_t sampc; auplay_write_h *wh; void *arg; @@ -38,6 +39,7 @@ static void auplay_destructor(void *arg) if (st->outputMixObject != NULL) (*st->outputMixObject)->Destroy(st->outputMixObject); + mem_deref(st->sampv); mem_deref(st->ap); } @@ -46,9 +48,9 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) { struct auplay_st *st = context; - st->wh((void *)st->buf, sizeof(st->buf), st->arg); + st->wh(st->sampv, st->sampc, st->arg); - (*st->BufferQueue)->Enqueue(bq, st->buf, sizeof(st->buf)); + (*st->BufferQueue)->Enqueue(bq, st->sampv, st->sampc * 2); } @@ -151,6 +153,14 @@ int opensles_player_alloc(struct auplay_st **stp, struct auplay *ap, st->wh = wh; st->arg = arg; + st->sampc = prm->srate * prm->ch * prm->ptime / 1000; + + st->sampv = mem_alloc(2 * st->sampc, NULL); + if (!st->sampv) { + err = ENOMEM; + goto out; + } + err = createOutput(st); if (err) goto out; diff --git a/modules/opensles/recorder.c b/modules/opensles/recorder.c index 6301451..4e1e6c7 100644 --- a/modules/opensles/recorder.c +++ b/modules/opensles/recorder.c @@ -18,7 +18,9 @@ struct ausrc_st { struct ausrc *as; /* inheritance */ - int16_t buf[160]; + int16_t *sampv; + size_t sampc; + uint32_t ptime; pthread_t thread; bool run; ausrc_read_h *rh; @@ -42,6 +44,7 @@ static void ausrc_destructor(void *arg) if (st->recObject != NULL) (*st->recObject)->Destroy(st->recObject); + mem_deref(st->sampv); mem_deref(st->as); } @@ -68,12 +71,13 @@ static void *record_thread(void *arg) #endif r = (*st->recBufferQueue)->Enqueue(st->recBufferQueue, - st->buf, sizeof(st->buf)); + st->sampv, + st->sampc * 2); if (r != SL_RESULT_SUCCESS) { DEBUG_WARNING("Enqueue: r = %d\n", r); } - ts += 20; + ts += st->ptime; } return NULL; @@ -85,7 +89,7 @@ static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context) struct ausrc_st *st = context; (void)bq; - st->rh((void *)st->buf, sizeof(st->buf), st->arg); + st->rh(st->sampv, st->sampc, st->arg); } @@ -192,6 +196,14 @@ int opensles_recorder_alloc(struct ausrc_st **stp, struct ausrc *as, st->as = mem_ref(as); st->rh = rh; st->arg = arg; + st->ptime = prm->ptime; + st->sampc = prm->srate * prm->ch * prm->ptime / 1000; + + st->sampv = mem_alloc(2 * st->sampc, NULL); + if (!st->sampv) { + err = ENOMEM; + goto out; + } err = createAudioRecorder(st, prm); if (err) { diff --git a/modules/oss/oss.c b/modules/oss/oss.c index f0644e2..38d34f3 100644 --- a/modules/oss/oss.c +++ b/modules/oss/oss.c @@ -23,7 +23,8 @@ struct ausrc_st { struct ausrc *as; /* inheritance */ int fd; - struct mbuf *mb; + int16_t *sampv; + size_t sampc; ausrc_read_h *rh; ausrc_error_h *errh; void *arg; @@ -153,7 +154,7 @@ static void ausrc_destructor(void *arg) (void)close(st->fd); } - mem_deref(st->mb); + mem_deref(st->sampv); mem_deref(st->as); } @@ -161,22 +162,14 @@ static void ausrc_destructor(void *arg) static void read_handler(int flags, void *arg) { struct ausrc_st *st = arg; - struct mbuf *mb = st->mb; int n; (void)flags; - n = read(st->fd, mbuf_buf(mb), mbuf_get_space(mb)); + n = read(st->fd, st->sampv, st->sampc*2); if (n <= 0) return; - mb->pos += n; - - if (mb->pos < mb->size) - return; - - st->rh(mb->buf, mb->size, st->arg); - - mb->pos = 0; + st->rh(st->sampv, n/2, st->arg); } @@ -206,7 +199,6 @@ static int src_alloc(struct ausrc_st **stp, struct ausrc *as, ausrc_read_h *rh, ausrc_error_h *errh, void *arg) { struct ausrc_st *st; - unsigned sampc; int err; (void)ctx; @@ -227,10 +219,10 @@ static int src_alloc(struct ausrc_st **stp, struct ausrc *as, if (!device) device = oss_dev; - sampc = prm->srate * prm->ch * prm->ptime / 1000; + st->sampc = prm->srate * prm->ch * prm->ptime / 1000; - st->mb = mbuf_alloc(2 * sampc); - if (!st->mb) { + st->sampv = mem_alloc(2 * st->sampc, NULL); + if (!st->sampv) { err = ENOMEM; goto out; } @@ -245,7 +237,7 @@ static int src_alloc(struct ausrc_st **stp, struct ausrc *as, if (err) goto out; - err = oss_reset(st->fd, prm->srate, prm->ch, sampc, 1); + err = oss_reset(st->fd, prm->srate, prm->ch, st->sampc, 1); if (err) goto out; @@ -296,7 +288,7 @@ static int play_alloc(struct auplay_st **stp, struct auplay *ap, goto out; } - err = oss_reset(st->fd, prm->srate, prm->ch, sampc, 0); + err = oss_reset(st->fd, prm->srate, prm->ch, st->sampc, 0); if (err) goto out; diff --git a/modules/winwave/play.c b/modules/winwave/play.c index e2e5051..29568ba 100644 --- a/modules/winwave/play.c +++ b/modules/winwave/play.c @@ -75,7 +75,7 @@ static int dsp_write(struct auplay_st *st) wh->lpData = (LPSTR)mb->buf; if (st->wh) { - st->wh(mb->buf, mb->size, st->arg); + st->wh((void *)mb->buf, mb->size/2, st->arg); } wh->dwBufferLength = mb->size; diff --git a/modules/winwave/src.c b/modules/winwave/src.c index c264a3d..9d23c1e 100644 --- a/modules/winwave/src.c +++ b/modules/winwave/src.c @@ -110,7 +110,7 @@ static void CALLBACK waveInCallback(HWAVEOUT hwo, if (st->inuse < 3) add_wave_in(st); - st->rh((uint8_t *)wh->lpData, wh->dwBytesRecorded, st->arg); + st->rh((void *)wh->lpData, wh->dwBytesRecorded/2, st->arg); waveInUnprepareHeader(st->wavein, wh, sizeof(*wh)); st->inuse--; |