]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Use slave PCM as a timing-source for file ifile
authorTakashi Iwai <tiwai@suse.de>
Fri, 14 Mar 2008 13:03:54 +0000 (14:03 +0100)
committerTakashi Iwai <tiwai@suse.de>
Fri, 14 Mar 2008 13:03:54 +0000 (14:03 +0100)
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

index 4d632707afba2f51390753a67318f88261906166..6d2582f9c9d97cd3eb9c280d99b51d2b01d7298a 100644 (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_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;