]> err.no Git - linux-2.6/commitdiff
[ALSA] snd-dummy - improved timing, silence on prepare
authorAhmet İnan <ainan at>
Thu, 21 Feb 2008 06:55:30 +0000 (07:55 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 24 Apr 2008 10:00:14 +0000 (12:00 +0200)
Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/drivers/dummy.c

index a240eaeb5c620d754c81a23602e0b4809b4fe40f..f67f65829f3e26704658da40b780796b434e9320 100644 (file)
@@ -181,10 +181,10 @@ struct snd_dummy_pcm {
        struct snd_dummy *dummy;
        spinlock_t lock;
        struct timer_list timer;
-       unsigned int pcm_size;
-       unsigned int pcm_count;
+       unsigned int pcm_buffer_size;
+       unsigned int pcm_period_size;
        unsigned int pcm_bps;           /* bytes per second */
-       unsigned int pcm_jiffie;        /* bytes per one jiffie */
+       unsigned int pcm_hz;            /* HZ */
        unsigned int pcm_irq_pos;       /* IRQ position */
        unsigned int pcm_buf_pos;       /* position in buffer */
        struct snd_pcm_substream *substream;
@@ -238,11 +238,15 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
        if (bps <= 0)
                return -EINVAL;
        dpcm->pcm_bps = bps;
-       dpcm->pcm_jiffie = bps / HZ;
-       dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream);
-       dpcm->pcm_count = snd_pcm_lib_period_bytes(substream);
+       dpcm->pcm_hz = HZ;
+       dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
+       dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream);
        dpcm->pcm_irq_pos = 0;
        dpcm->pcm_buf_pos = 0;
+
+       snd_pcm_format_set_silence(runtime->format, runtime->dma_area,
+                       bytes_to_samples(runtime, runtime->dma_bytes));
+
        return 0;
 }
 
@@ -254,11 +258,11 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data)
        spin_lock_irqsave(&dpcm->lock, flags);
        dpcm->timer.expires = 1 + jiffies;
        add_timer(&dpcm->timer);
-       dpcm->pcm_irq_pos += dpcm->pcm_jiffie;
-       dpcm->pcm_buf_pos += dpcm->pcm_jiffie;
-       dpcm->pcm_buf_pos %= dpcm->pcm_size;
-       if (dpcm->pcm_irq_pos >= dpcm->pcm_count) {
-               dpcm->pcm_irq_pos %= dpcm->pcm_count;
+       dpcm->pcm_irq_pos += dpcm->pcm_bps;
+       if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) {
+               dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz;
+               dpcm->pcm_buf_pos += dpcm->pcm_period_size;
+               dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size;
                spin_unlock_irqrestore(&dpcm->lock, flags);
                snd_pcm_period_elapsed(dpcm->substream);
        } else