aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmet İnan <ainan at>2008-02-21 01:55:30 -0500
committerTakashi Iwai <tiwai@suse.de>2008-04-24 06:00:14 -0400
commit53463a8302d0c3148c4c64c034312215e76429c2 (patch)
tree0d83a19ffbb7d340744d7f3f98f3f35971ae279f
parent03d7ca177fd2ecac8eb22f482f327ecaae4ac8cb (diff)
[ALSA] snd-dummy - improved timing, silence on prepare
Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/drivers/dummy.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index a240eaeb5c62..f67f65829f3e 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -181,10 +181,10 @@ struct snd_dummy_pcm {
181 struct snd_dummy *dummy; 181 struct snd_dummy *dummy;
182 spinlock_t lock; 182 spinlock_t lock;
183 struct timer_list timer; 183 struct timer_list timer;
184 unsigned int pcm_size; 184 unsigned int pcm_buffer_size;
185 unsigned int pcm_count; 185 unsigned int pcm_period_size;
186 unsigned int pcm_bps; /* bytes per second */ 186 unsigned int pcm_bps; /* bytes per second */
187 unsigned int pcm_jiffie; /* bytes per one jiffie */ 187 unsigned int pcm_hz; /* HZ */
188 unsigned int pcm_irq_pos; /* IRQ position */ 188 unsigned int pcm_irq_pos; /* IRQ position */
189 unsigned int pcm_buf_pos; /* position in buffer */ 189 unsigned int pcm_buf_pos; /* position in buffer */
190 struct snd_pcm_substream *substream; 190 struct snd_pcm_substream *substream;
@@ -238,11 +238,15 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
238 if (bps <= 0) 238 if (bps <= 0)
239 return -EINVAL; 239 return -EINVAL;
240 dpcm->pcm_bps = bps; 240 dpcm->pcm_bps = bps;
241 dpcm->pcm_jiffie = bps / HZ; 241 dpcm->pcm_hz = HZ;
242 dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); 242 dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
243 dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); 243 dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream);
244 dpcm->pcm_irq_pos = 0; 244 dpcm->pcm_irq_pos = 0;
245 dpcm->pcm_buf_pos = 0; 245 dpcm->pcm_buf_pos = 0;
246
247 snd_pcm_format_set_silence(runtime->format, runtime->dma_area,
248 bytes_to_samples(runtime, runtime->dma_bytes));
249
246 return 0; 250 return 0;
247} 251}
248 252
@@ -254,11 +258,11 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data)
254 spin_lock_irqsave(&dpcm->lock, flags); 258 spin_lock_irqsave(&dpcm->lock, flags);
255 dpcm->timer.expires = 1 + jiffies; 259 dpcm->timer.expires = 1 + jiffies;
256 add_timer(&dpcm->timer); 260 add_timer(&dpcm->timer);
257 dpcm->pcm_irq_pos += dpcm->pcm_jiffie; 261 dpcm->pcm_irq_pos += dpcm->pcm_bps;
258 dpcm->pcm_buf_pos += dpcm->pcm_jiffie; 262 if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) {
259 dpcm->pcm_buf_pos %= dpcm->pcm_size; 263 dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz;
260 if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { 264 dpcm->pcm_buf_pos += dpcm->pcm_period_size;
261 dpcm->pcm_irq_pos %= dpcm->pcm_count; 265 dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size;
262 spin_unlock_irqrestore(&dpcm->lock, flags); 266 spin_unlock_irqrestore(&dpcm->lock, flags);
263 snd_pcm_period_elapsed(dpcm->substream); 267 snd_pcm_period_elapsed(dpcm->substream);
264 } else 268 } else