*
* 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;
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;
}
/**
*/
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);
EXIT(E_WRITE);
if (r > 0) {
result += r;
- count -= r;
+ frames -= r;
data += r * bytes_per_frame;
}
}
*/
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)