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.
This commit is contained in:
Takashi Iwai 2008-03-14 14:03:54 +01:00
parent 3d0dae9099
commit 5c5f135812

View file

@ -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_file_t *file = pcm->private_data;
snd_pcm_channel_area_t areas[pcm->channels]; 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) { if (file->ifd >= 0) {
n = /* bytesn = */ read(file->ifd, buffer, size * pcm->frame_bits / 8); n = read(file->ifd, buffer, n * pcm->frame_bits / 8);
if (n > 0) if (n < 0)
n = n * 8 / pcm->frame_bits; return n;
/* SNDERR("DEBUG: channels = %d, sample_bits = %d, frame_bits = %d, bytes = %d, frames = %d", return n * 8 / pcm->frame_bits;
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);
}
} }
snd_pcm_areas_from_buf(pcm, areas, buffer);
snd_pcm_file_add_frames(pcm, areas, 0, n);
return 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); err = snd_pcm_slave_conf(root, slave, &sconf, 0);
if (err < 0) if (err < 0)
return err; return err;
if (!fname && fd < 0) { if (!fname && fd < 0 && !ifname) {
snd_config_delete(sconf); snd_config_delete(sconf);
SNDERR("file is not defined"); SNDERR("file is not defined");
return -EINVAL; return -EINVAL;