From 5c5f1358123af69155267463a0b6254ad9cbecc4 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 14 Mar 2008 14:03:54 +0100 Subject: [PATCH] Use slave PCM as a timing-source for file ifile When ifile option is used for the file plugin, it ignores the slave PCM and just feeds the input data. This patch changes the behavior a bit - it uses the slave PCM as the timing source (just read and throw data away) so that the input data can be read in the right sample rate. --- src/pcm/pcm_file.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index 4d632707..6d2582f9 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -231,21 +231,19 @@ static snd_pcm_sframes_t snd_pcm_file_readi(snd_pcm_t *pcm, void *buffer, snd_pc { snd_pcm_file_t *file = pcm->private_data; snd_pcm_channel_area_t areas[pcm->channels]; - snd_pcm_sframes_t n /* , bytesn */; + snd_pcm_sframes_t n; + n = snd_pcm_readi(file->gen.slave, buffer, size); + if (n <= 0) + return n; if (file->ifd >= 0) { - n = /* bytesn = */ read(file->ifd, buffer, size * pcm->frame_bits / 8); - if (n > 0) - n = n * 8 / pcm->frame_bits; - /* SNDERR("DEBUG: channels = %d, sample_bits = %d, frame_bits = %d, bytes = %d, frames = %d", - pcm->channels, pcm->sample_bits, pcm->frame_bits, bytesn, n); */ - } else { - n = snd_pcm_readi(file->gen.slave, buffer, size); - if (n > 0) { - snd_pcm_areas_from_buf(pcm, areas, buffer); - snd_pcm_file_add_frames(pcm, areas, 0, n); - } + n = read(file->ifd, buffer, n * pcm->frame_bits / 8); + if (n < 0) + return n; + return n * 8 / pcm->frame_bits; } + snd_pcm_areas_from_buf(pcm, areas, buffer); + snd_pcm_file_add_frames(pcm, areas, 0, n); return n; } @@ -642,7 +640,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name, err = snd_pcm_slave_conf(root, slave, &sconf, 0); if (err < 0) return err; - if (!fname && fd < 0) { + if (!fname && fd < 0 && !ifname) { snd_config_delete(sconf); SNDERR("file is not defined"); return -EINVAL; -- 2.47.1