From ad347d6c5f3405ac356d1eb9c154bdb1f9d63059 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 9 Feb 2014 12:05:47 +0100 Subject: alsa: use native-endian format SND_PCM_FORMAT_S16 also reduce hardware buffersize to 4 blocks --- modules/alsa/alsa.c | 18 +++--------------- modules/alsa/alsa.h | 2 +- modules/alsa/alsa_play.c | 5 ++--- modules/alsa/alsa_src.c | 3 +-- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/modules/alsa/alsa.c b/modules/alsa/alsa.c index 6ffa5a8..3239d41 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa/alsa.c @@ -33,24 +33,12 @@ static struct ausrc *ausrc; static struct auplay *auplay; -static inline snd_pcm_format_t audio_fmt(enum aufmt fmt) -{ - switch (fmt) { - - default: - case AUFMT_S16LE: return SND_PCM_FORMAT_S16_LE; - case AUFMT_PCMU: return SND_PCM_FORMAT_MU_LAW; - case AUFMT_PCMA: return SND_PCM_FORMAT_A_LAW; - } -} - - -int alsa_reset(snd_pcm_t *pcm, uint32_t srate, uint32_t ch, enum aufmt fmt, +int alsa_reset(snd_pcm_t *pcm, uint32_t srate, uint32_t ch, uint32_t num_frames) { snd_pcm_hw_params_t *hw_params = NULL; - const snd_pcm_format_t pcmfmt = audio_fmt(fmt); - snd_pcm_uframes_t period = num_frames, bufsize = num_frames * 10; + const snd_pcm_format_t pcmfmt = SND_PCM_FORMAT_S16; + snd_pcm_uframes_t period = num_frames, bufsize = num_frames * 4; int err; err = snd_pcm_hw_params_malloc(&hw_params); diff --git a/modules/alsa/alsa.h b/modules/alsa/alsa.h index f779fcc..be345c6 100644 --- a/modules/alsa/alsa.h +++ b/modules/alsa/alsa.h @@ -7,7 +7,7 @@ extern char alsa_dev[64]; -int alsa_reset(snd_pcm_t *pcm, uint32_t srate, uint32_t ch, enum aufmt fmt, +int alsa_reset(snd_pcm_t *pcm, uint32_t srate, uint32_t ch, uint32_t num_frames); int alsa_src_alloc(struct ausrc_st **stp, struct ausrc *as, struct media_ctx **ctx, diff --git a/modules/alsa/alsa_play.c b/modules/alsa/alsa_play.c index 856ed96..a0afa4e 100644 --- a/modules/alsa/alsa_play.c +++ b/modules/alsa/alsa_play.c @@ -75,7 +75,7 @@ static void *write_thread(void *arg) warning("alsa: write error: %s\n", snd_strerror(n)); } else if (n != samples) { - warning("alsa: write: wrote %d of %d bytes\n", + warning("alsa: write: wrote %d of %d samples\n", n, samples); } } @@ -130,8 +130,7 @@ int alsa_play_alloc(struct auplay_st **stp, struct auplay *ap, goto out; } - err = alsa_reset(st->write, st->prm.srate, st->prm.ch, st->prm.fmt, - num_frames); + err = alsa_reset(st->write, st->prm.srate, st->prm.ch, num_frames); if (err) { warning("alsa: could not reset player '%s' (%s)\n", st->device, snd_strerror(err)); diff --git a/modules/alsa/alsa_src.c b/modules/alsa/alsa_src.c index 441c501..67e6bcb 100644 --- a/modules/alsa/alsa_src.c +++ b/modules/alsa/alsa_src.c @@ -131,8 +131,7 @@ int alsa_src_alloc(struct ausrc_st **stp, struct ausrc *as, goto out; } - err = alsa_reset(st->read, st->prm.srate, st->prm.ch, st->prm.fmt, - num_frames); + err = alsa_reset(st->read, st->prm.srate, st->prm.ch, num_frames); if (err) { warning("alsa: could not reset source '%s' (%s)\n", st->device, snd_strerror(err)); -- cgit v1.2.3