From: Andre Date: Mon, 17 Apr 2006 18:59:12 +0000 (+0200) Subject: play.c: Let alsa_init() return the number of bytes per chunk X-Git-Tag: v0.2.12~78 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=026647beaed61d9d7ae4ec9fa076735a98036d4d;ds=inline play.c: Let alsa_init() return the number of bytes per chunk --- diff --git a/play.c b/play.c index 1a30285d..0a53331b 100644 --- a/play.c +++ b/play.c @@ -98,7 +98,7 @@ static void read_wav_header(void) * * Install PCM software and hardware configuration. Exit on errors. */ -static void alsa_init(void) +static int alsa_init(void) { snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; @@ -169,6 +169,7 @@ static void alsa_init(void) if (snd_pcm_sw_params(handle, swparams) < 0) EXIT(E_SW_PARAMS); bytes_per_frame = snd_pcm_format_physical_width(FORMAT) * conf.channels_arg / 8; + return chunk_size * bytes_per_frame; } /** @@ -180,14 +181,14 @@ static void alsa_init(void) */ int alsa_write(u_char *data, size_t nbytes) { - size_t count = nbytes / bytes_per_frame; + size_t frames = nbytes / bytes_per_frame; snd_pcm_sframes_t r, result = 0; - while (count > 0) { + while (frames > 0) { /* write interleaved frames */ - r = snd_pcm_writei(handle, data, count); + r = snd_pcm_writei(handle, data, frames); if (r < 0) PARA_ERROR_LOG("write error: %s\n", snd_strerror(r)); - if (r == -EAGAIN || (r >= 0 && r < count)) + if (r == -EAGAIN || (r >= 0 && r < frames)) snd_pcm_wait(handle, 1); else if (r == -EPIPE) snd_pcm_prepare(handle); @@ -195,7 +196,7 @@ int alsa_write(u_char *data, size_t nbytes) EXIT(E_WRITE); if (r > 0) { result += r; - count -= r; + frames -= r; data += r * bytes_per_frame; } } @@ -254,13 +255,12 @@ static void do_initial_delay(struct timeval *delay) */ static void play_pcm(size_t loaded) { - size_t chunk_bytes, bufsize, written = 0, prebuf_size; + size_t bufsize, written = 0, prebuf_size; ssize_t ret; unsigned char *p; struct timeval delay; + int chunk_bytes = alsa_init(); - alsa_init(); - chunk_bytes = chunk_size * bytes_per_frame; bufsize = (conf.bufsize_arg * 1024 / chunk_bytes) * chunk_bytes; audiobuf = realloc(audiobuf, bufsize); if (!audiobuf)