improved snd-aloop quality when using certain samplerates and kernel HZ
PATCH 1/1 improved snd-aloop quality when using certain samplerates and kernel HZ
after using a HZ:=300 kernel for some time now and needing snd-aloop again i found out, that i either had to correct the hardcoded number, or fix the problem permanently, which couses stuttering and other problems.
i also removed the SYNC on start code, not just because its more or less useless and brings problems, but ive got a nice idea how to fix this overrun/underrun problem in a much nicer way.
so stay tuned for the next patch, until its implemented.
this patch here is more or less experimental, id like to hear some feedback.
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-1.0.15-aloop-ainan-patch0.diff
please also include my email address when responding - i have no intention to enable recieving emails from the list.
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
aloop-kernel.c renamed from aloop-kernel-orig.c +20 -51
@@ -32,9 +32,6 @@/* comment in to trash your kernel logfiles */ /* #define SND_CARD_LOOPBACK_VERBOSE */ -/* comment in for synchronization on start trigger -* works well on alsa apps but bad on oss emulation */ -/* #define SND_CARD_LOOPBACK_START_SYNC */ MODULE_AUTHOR ("Jaroslav Kysela <[email protected]>" );MODULE_DESCRIPTION ("A loopback soundcard" );
@@ -85,16 +82,13 @@snd_card_loopback_t *loopback;spinlock_t lock;struct timer_list timer; -int stream; -unsigned int pcm_1000_size; -unsigned int pcm_1000_count; -unsigned int pcm_size; -unsigned int pcm_count; +unsigned int pcm_size_hz; +unsigned int pcm_count_hz;unsigned int pcm_bps;/* bytes per second */ -unsigned int pcm_1000_jiffie;/* 1000 * bytes per one jiffie */ -unsigned int pcm_1000_irq_pos;/* IRQ position */ -unsigned int pcm_1000_buf_pos;/* position in buffer */ -unsigned int pcm_period_pos;/* period aligned pos in buffer */ +unsigned int pcm_hz;/* HZ */ +unsigned int pcm_irq_pos_hz;/* IRQ position * HZ */ +unsigned int pcm_buf_pos_hz;/* position in buffer * HZ */ +unsigned int pcm_period_pos_hz;/* period aligned pos in buffer * HZ */ struct snd_pcm_substream *substream;struct snd_card_loopback_cable *cable; } snd_card_loopback_pcm_t;
@@ -123,18 +117,7 @@ {struct snd_pcm_runtime *runtime = substream->runtime;snd_card_loopback_pcm_t *dpcm = runtime->private_data; -#ifdef SND_CARD_LOOPBACK_START_SYNC -snd_card_loopback_pcm_t *capture_dpcm; -#endif if (cmd ==SNDRV_PCM_TRIGGER_START ) { -#ifdef SND_CARD_LOOPBACK_START_SYNC -if (dpcm->cable->capture_running) { - capture_dpcm = dpcm->cable->capture->runtime->private_data; - dpcm->pcm_1000_irq_pos = capture_dpcm->pcm_1000_irq_pos; - dpcm->pcm_1000_buf_pos = capture_dpcm->pcm_1000_buf_pos; - dpcm->pcm_period_pos = capture_dpcm->pcm_period_pos; - } -#endif dpcm->cable->playback_running =1 ;snd_card_loopback_timer_start (substream); }else if (cmd ==SNDRV_PCM_TRIGGER_STOP ) {
@@ -154,18 +137,7 @@ {struct snd_pcm_runtime *runtime = substream->runtime;snd_card_loopback_pcm_t *dpcm = runtime->private_data; -#ifdef SND_CARD_LOOPBACK_START_SYNC -snd_card_loopback_pcm_t *playback_dpcm; -#endif if (cmd ==SNDRV_PCM_TRIGGER_START ) { -#ifdef SND_CARD_LOOPBACK_START_SYNC -if (dpcm->cable->playback_running) { - playback_dpcm = dpcm->cable->playback->runtime->private_data; - dpcm->pcm_1000_irq_pos = playback_dpcm->pcm_1000_irq_pos; - dpcm->pcm_1000_buf_pos = playback_dpcm->pcm_1000_buf_pos; - dpcm->pcm_period_pos = playback_dpcm->pcm_period_pos; - } -#endif dpcm->cable->capture_running =1 ;snd_card_loopback_timer_start (substream); }else if (cmd ==SNDRV_PCM_TRIGGER_STOP ) {
@@ -190,14 +162,12 @@if (bps <=0 )return -EINVAL ; dpcm->pcm_bps = bps; - dpcm->pcm_1000_jiffie = (1000 * bps) /HZ ; - dpcm->pcm_size =frames_to_bytes (runtime, runtime->buffer_size); - dpcm->pcm_count =frames_to_bytes (runtime, runtime->period_size); - dpcm->pcm_1000_size =1000 *frames_to_bytes (runtime, runtime->buffer_size); - dpcm->pcm_1000_count =1000 *frames_to_bytes (runtime, runtime->period_size); - dpcm->pcm_1000_irq_pos =0 ; - dpcm->pcm_1000_buf_pos =0 ; - dpcm->pcm_period_pos =0 ; + dpcm->pcm_hz =HZ ; + dpcm->pcm_size_hz =frames_to_bytes (runtime, runtime->buffer_size) * dpcm->pcm_hz; + dpcm->pcm_count_hz =frames_to_bytes (runtime, runtime->period_size) * dpcm->pcm_hz; + dpcm->pcm_irq_pos_hz =0 ; + dpcm->pcm_buf_pos_hz =0 ; + dpcm->pcm_period_pos_hz =0 ; cable->hw.formats = (1ULL << runtime->format); cable->hw.rate_min = runtime->rate;
@@ -246,13 +216,13 @@add_timer (&dpcm->timer);spin_lock_irq (&dpcm->lock); - dpcm->pcm_1000_irq_pos += dpcm->pcm_1000_jiffie; - dpcm->pcm_1000_buf_pos += dpcm->pcm_1000_jiffie; - dpcm->pcm_1000_buf_pos %= dpcm->pcm_1000_size; -if (dpcm->pcm_1000_irq_pos >= dpcm->pcm_1000_count) { - dpcm->pcm_1000_irq_pos %= dpcm->pcm_1000_count; - dpcm->pcm_period_pos += dpcm->pcm_count; - dpcm->pcm_period_pos %= dpcm->pcm_size; + dpcm->pcm_irq_pos_hz += dpcm->pcm_bps; + dpcm->pcm_buf_pos_hz += dpcm->pcm_bps; + dpcm->pcm_buf_pos_hz %= dpcm->pcm_size_hz; +if (dpcm->pcm_irq_pos_hz >= dpcm->pcm_count_hz) { + dpcm->pcm_irq_pos_hz %= dpcm->pcm_count_hz; + dpcm->pcm_period_pos_hz += dpcm->pcm_count_hz; + dpcm->pcm_period_pos_hz %= dpcm->pcm_size_hz;spin_unlock_irq (&dpcm->lock);snd_pcm_period_elapsed (dpcm->substream); }else {
@@ -264,7 +234,7 @@ {struct snd_pcm_runtime *runtime = substream->runtime;snd_card_loopback_pcm_t *dpcm = runtime->private_data; -return bytes_to_frames (runtime, dpcm->pcm_period_pos); +return bytes_to_frames (runtime, dpcm->pcm_period_pos_hz / dpcm->pcm_hz); } static struct snd_pcm_hardware snd_card_loopback_info =
@@ -381,7 +351,6 @@ dpcm->timer.data = (unsigned long )dpcm; dpcm->timer.function = snd_card_loopback_timer_function; dpcm->cable = &loopback->cables[substream->number][half]; - dpcm->stream = substream->stream; runtime->private_data = dpcm; runtime->private_free = snd_card_loopback_runtime_free; runtime->hw = snd_card_loopback_info;
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
sorry, forget about the patch before. this one here is a lot better to read and fixes one silly mistake.
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-1.0.15-aloop-ainan-patch1.diff
please also include my email address when responding - i have no intention to enable recieving emails from the list.
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
aloop-kernel.c renamed from aloop-kernel-orig.c +11 -42
@@ -32,9 +32,6 @@/* comment in to trash your kernel logfiles */ /* #define SND_CARD_LOOPBACK_VERBOSE */ -/* comment in for synchronization on start trigger -* works well on alsa apps but bad on oss emulation */ -/* #define SND_CARD_LOOPBACK_START_SYNC */ MODULE_AUTHOR ("Jaroslav Kysela <[email protected]>" );MODULE_DESCRIPTION ("A loopback soundcard" );
@@ -85,15 +82,12 @@snd_card_loopback_t *loopback;spinlock_t lock;struct timer_list timer; -int stream; -unsigned int pcm_1000_size; -unsigned int pcm_1000_count;unsigned int pcm_size;unsigned int pcm_count;unsigned int pcm_bps;/* bytes per second */ -unsigned int pcm_1000_jiffie;/* 1000 * bytes per one jiffie */ -unsigned int pcm_1000_irq_pos;/* IRQ position */ -unsigned int pcm_1000_buf_pos;/* position in buffer */ +unsigned int pcm_hz;/* HZ */ +unsigned int pcm_irq_pos;/* IRQ position */ +unsigned int pcm_buf_pos;/* position in buffer */ unsigned int pcm_period_pos;/* period aligned pos in buffer */ struct snd_pcm_substream *substream;struct snd_card_loopback_cable *cable;
@@ -123,18 +117,7 @@ {struct snd_pcm_runtime *runtime = substream->runtime;snd_card_loopback_pcm_t *dpcm = runtime->private_data; -#ifdef SND_CARD_LOOPBACK_START_SYNC -snd_card_loopback_pcm_t *capture_dpcm; -#endif if (cmd ==SNDRV_PCM_TRIGGER_START ) { -#ifdef SND_CARD_LOOPBACK_START_SYNC -if (dpcm->cable->capture_running) { - capture_dpcm = dpcm->cable->capture->runtime->private_data; - dpcm->pcm_1000_irq_pos = capture_dpcm->pcm_1000_irq_pos; - dpcm->pcm_1000_buf_pos = capture_dpcm->pcm_1000_buf_pos; - dpcm->pcm_period_pos = capture_dpcm->pcm_period_pos; - } -#endif dpcm->cable->playback_running =1 ;snd_card_loopback_timer_start (substream); }else if (cmd ==SNDRV_PCM_TRIGGER_STOP ) {
@@ -154,18 +137,7 @@ {struct snd_pcm_runtime *runtime = substream->runtime;snd_card_loopback_pcm_t *dpcm = runtime->private_data; -#ifdef SND_CARD_LOOPBACK_START_SYNC -snd_card_loopback_pcm_t *playback_dpcm; -#endif if (cmd ==SNDRV_PCM_TRIGGER_START ) { -#ifdef SND_CARD_LOOPBACK_START_SYNC -if (dpcm->cable->playback_running) { - playback_dpcm = dpcm->cable->playback->runtime->private_data; - dpcm->pcm_1000_irq_pos = playback_dpcm->pcm_1000_irq_pos; - dpcm->pcm_1000_buf_pos = playback_dpcm->pcm_1000_buf_pos; - dpcm->pcm_period_pos = playback_dpcm->pcm_period_pos; - } -#endif dpcm->cable->capture_running =1 ;snd_card_loopback_timer_start (substream); }else if (cmd ==SNDRV_PCM_TRIGGER_STOP ) {
@@ -190,13 +162,11 @@if (bps <=0 )return -EINVAL ; dpcm->pcm_bps = bps; - dpcm->pcm_1000_jiffie = (1000 * bps) /HZ ; + dpcm->pcm_hz =HZ ; dpcm->pcm_size =frames_to_bytes (runtime, runtime->buffer_size); dpcm->pcm_count =frames_to_bytes (runtime, runtime->period_size); - dpcm->pcm_1000_size =1000 *frames_to_bytes (runtime, runtime->buffer_size); - dpcm->pcm_1000_count =1000 *frames_to_bytes (runtime, runtime->period_size); - dpcm->pcm_1000_irq_pos =0 ; - dpcm->pcm_1000_buf_pos =0 ; + dpcm->pcm_irq_pos =0 ; + dpcm->pcm_buf_pos =0 ; dpcm->pcm_period_pos =0 ; cable->hw.formats = (1ULL << runtime->format);
@@ -246,11 +216,11 @@add_timer (&dpcm->timer);spin_lock_irq (&dpcm->lock); - dpcm->pcm_1000_irq_pos += dpcm->pcm_1000_jiffie; - dpcm->pcm_1000_buf_pos += dpcm->pcm_1000_jiffie; - dpcm->pcm_1000_buf_pos %= dpcm->pcm_1000_size; -if (dpcm->pcm_1000_irq_pos >= dpcm->pcm_1000_count) { - dpcm->pcm_1000_irq_pos %= dpcm->pcm_1000_count; + dpcm->pcm_irq_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos %= dpcm->pcm_size * dpcm->pcm_hz; +if (dpcm->pcm_irq_pos >= dpcm->pcm_count * dpcm->pcm_hz) { + dpcm->pcm_irq_pos %= dpcm->pcm_count * dpcm->pcm_hz; dpcm->pcm_period_pos += dpcm->pcm_count; dpcm->pcm_period_pos %= dpcm->pcm_size;spin_unlock_irq (&dpcm->lock);
@@ -381,7 +351,6 @@ dpcm->timer.data = (unsigned long )dpcm; dpcm->timer.function = snd_card_loopback_timer_function; dpcm->cable = &loopback->cables[substream->number][half]; - dpcm->stream = substream->stream; runtime->private_data = dpcm; runtime->private_free = snd_card_loopback_runtime_free; runtime->hw = snd_card_loopback_info;
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Takashi Iwai
AppliedAt Tue, 19 Feb 2008 13:50:46 +0100,
Quoted 7 lines · Ahmet İnan
sorry, forget about the patch before. this one here is a lot better to read and fixes one silly mistake.
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-1.0.15-aloop-ainan-patch1.diff
Signed-off-by Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>
Looks like a good clean up.
Applied to HG tree now. Thanks!
Takashi
more cleanups.
removed some unneeded stuff.
patch is relative to current hg-tree.
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch0.diff
btw, my "nice" idea turned out to be a bitch, again. its really funny how worse almoust always is better. :(
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
drivers/aloop-kernel.c +0 -4
@@ -86,7 +86,6 @@ typedef struct snd_card_loopback_pcm {unsigned int pcm_bps;/* bytes per second */ unsigned int pcm_hz;/* HZ */ unsigned int pcm_irq_pos;/* IRQ position */ -unsigned int pcm_buf_pos;/* position in buffer */ unsigned int pcm_period_pos;/* period aligned pos in buffer */ struct snd_pcm_substream *substream;struct snd_card_loopback_cable *cable;
@@ -165,7 +164,6 @@ static int snd_card_loopback_prepare(str dpcm->pcm_size =frames_to_bytes (runtime, runtime->buffer_size); dpcm->pcm_count =frames_to_bytes (runtime, runtime->period_size); dpcm->pcm_irq_pos =0 ; - dpcm->pcm_buf_pos =0 ; dpcm->pcm_period_pos =0 ; cable->hw.formats = (1ULL << runtime->format);
@@ -216,8 +214,6 @@ static void snd_card_loopback_timer_funcspin_lock_irq (&dpcm->lock); dpcm->pcm_irq_pos += dpcm->pcm_bps; - dpcm->pcm_buf_pos += dpcm->pcm_bps; - dpcm->pcm_buf_pos %= dpcm->pcm_size * dpcm->pcm_hz;if (dpcm->pcm_irq_pos >= dpcm->pcm_count * dpcm->pcm_hz) { dpcm->pcm_irq_pos %= dpcm->pcm_count * dpcm->pcm_hz; dpcm->pcm_period_pos += dpcm->pcm_count;
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Takashi Iwai
AppliedAt Wed, 20 Feb 2008 15:19:06 +0100,
Quoted 9 lines · Ahmet İnan
more cleanups.
removed some unneeded stuff.
patch is relative to current hg-tree.http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch0.diff
Signed-off-by Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>
Thanks, applied now to HG tree.
Takashi
removed my old debugging macros.
renamed variables to make it more clear.
[snd-aloop - even more cleanups]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch1.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]
i promised to improve and clean up snd-dummy too, so here it is:
reused the same method to improve timing, renamed the variables, added snd_pcm_format_set_silence on prepare.
[snd-dummy - improved timing, silence on prepare]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-kernel-hg-dummy-ainan-patch0.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]
patches are relative to current hg-tree.
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
drivers/aloop-kernel.c +11 -33
@@ -29,9 +29,6 @@#include <sound/pcm.h> #include <sound/initval.h> -/* comment in to trash your kernel logfiles */ -/* #define SND_CARD_LOOPBACK_VERBOSE */ -MODULE_AUTHOR ("Jaroslav Kysela <[email protected]>" );MODULE_DESCRIPTION ("A loopback soundcard" );MODULE_LICENSE ("GPL" );
@@ -81,12 +78,12 @@ typedef struct snd_card_loopback_pcm {snd_card_loopback_t *loopback;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_hz;/* HZ */ unsigned int pcm_irq_pos;/* IRQ position */ -unsigned int pcm_period_pos;/* period aligned pos in buffer */ +unsigned int pcm_buf_pos;/* position in buffer */ struct snd_pcm_substream *substream;struct snd_card_loopback_cable *cable; } snd_card_loopback_pcm_t;
@@ -161,10 +158,10 @@ static int snd_card_loopback_prepare(strreturn -EINVAL ; dpcm->pcm_bps = bps; dpcm->pcm_hz =HZ ; - dpcm->pcm_size =frames_to_bytes (runtime, runtime->buffer_size); - dpcm->pcm_count =frames_to_bytes (runtime, runtime->period_size); + dpcm->pcm_buffer_size =frames_to_bytes (runtime, runtime->buffer_size); + dpcm->pcm_period_size =frames_to_bytes (runtime, runtime->period_size); dpcm->pcm_irq_pos =0 ; - dpcm->pcm_period_pos =0 ; + dpcm->pcm_buf_pos =0 ; cable->hw.formats = (1ULL << runtime->format); cable->hw.rate_min = runtime->rate;
@@ -189,19 +186,6 @@ static int snd_card_loopback_prepare(str cable->capture_valid =1 ; } -#ifdef SND_CARD_LOOPBACK_VERBOSE -printk (KERN_INFO "snd-aloop(c%dd%ds%d%c): frq=%d chs=%d fmt=%d buf=%d per=%d pers=%d\n" , - substream->pcm->card->number, - substream->pcm->device, - substream->stream, - (SNDRV_PCM_STREAM_PLAYBACK == substream->stream ?'p' :'c' ), - runtime->rate, - runtime->channels, -snd_pcm_format_width (runtime->format), -frames_to_bytes (runtime, runtime->buffer_size), -frames_to_bytes (runtime, runtime->period_size), - runtime->periods); -#endif return 0 ; }
@@ -214,10 +198,10 @@ static void snd_card_loopback_timer_funcspin_lock_irq (&dpcm->lock); dpcm->pcm_irq_pos += dpcm->pcm_bps; -if (dpcm->pcm_irq_pos >= dpcm->pcm_count * dpcm->pcm_hz) { - dpcm->pcm_irq_pos %= dpcm->pcm_count * dpcm->pcm_hz; - dpcm->pcm_period_pos += dpcm->pcm_count; - dpcm->pcm_period_pos %= dpcm->pcm_size; +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_irq (&dpcm->lock);snd_pcm_period_elapsed (dpcm->substream); }else {
@@ -229,7 +213,7 @@ static snd_pcm_uframes_t snd_card_loopba {struct snd_pcm_runtime *runtime = substream->runtime;snd_card_loopback_pcm_t *dpcm = runtime->private_data; -return bytes_to_frames (runtime, dpcm->pcm_period_pos); +return bytes_to_frames (runtime, dpcm->pcm_buf_pos); } static struct snd_pcm_hardware snd_card_loopback_info =
@@ -263,9 +247,6 @@ static int snd_card_loopback_hw_params(ssnd_card_loopback_pcm_t *dpcm = runtime->private_data;struct snd_dma_buffer *dmab =NULL ;if (NULL == dpcm->cable->dma_buffer) { -#ifdef SND_CARD_LOOPBACK_VERBOSE -printk (KERN_INFO "snd-aloop: allocating dma buffer\n" ); -#endif dmab =kzalloc (sizeof (*dmab),GFP_KERNEL );if (NULL == dmab)return -ENOMEM ;
@@ -302,9 +283,6 @@ static int snd_card_loopback_hw_free(strif (NULL == cable->dma_buffer)return 0 ; -#ifdef SND_CARD_LOOPBACK_VERBOSE -printk (KERN_INFO "snd-aloop: freeing dma buffer\n" ); -#endif snd_dma_free_pages (cable->dma_buffer);kfree (cable->dma_buffer); cable->dma_buffer =NULL ;
drivers/dummy.c +15 -11
@@ -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(stif (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_funspin_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
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Takashi Iwai
AppliedAt Thu, 21 Feb 2008 01:06:01 +0100,
Ahmet İnan wrote:
At Thu, 21 Feb 2008 01:06:01 +0100,
Quoted 9 lines · Ahmet İnan
[snd-aloop - even more cleanups]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch1.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]i promised to improve and clean up snd-dummy too, so here it is:
reused the same method to improve timing, renamed the variables, addedsnd_pcm_format_set_silenceon prepare.
Quoted 5 lines
[snd-dummy - improved timing, silence on prepare]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-kernel-hg-dummy-ainan-patch0.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]patches are relative to current hg-tree.
Thanks, applied both to HG tree now.
Takashi
when the time interval for a period is smaller than kernel HZ, then snd-aloop and snd-dummy cannot call snd_pcm_period_elapsed as fast enough annymore. this happens for example with games. but the app still needs to see, that the buffer actually did go further, which is provided by these patches.
[snd-aloop - better realtime app support]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch2.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]
[snd-dummy - better realtime app support]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-kernel-hg-dummy-ainan-patch1.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]
patches are relative to current hg-tree.
finally even realtime apps like games work smooth. only one thing left for perfection :)
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
drivers/aloop-kernel.c +3 -3
@@ -198,10 +198,10 @@ static void snd_card_loopback_timer_funcspin_lock_irq (&dpcm->lock); dpcm->pcm_irq_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz;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_irq (&dpcm->lock);snd_pcm_period_elapsed (dpcm->substream); }else {
@@ -213,7 +213,7 @@ static snd_pcm_uframes_t snd_card_loopba {struct snd_pcm_runtime *runtime = substream->runtime;snd_card_loopback_pcm_t *dpcm = runtime->private_data; -return bytes_to_frames (runtime, dpcm->pcm_buf_pos); +return bytes_to_frames (runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz); } static struct snd_pcm_hardware snd_card_loopback_info =
drivers/dummy.c +3 -3
@@ -259,10 +259,10 @@ static void snd_card_dummy_pcm_timer_fun dpcm->timer.expires =1 + jiffies;add_timer (&dpcm->timer); dpcm->pcm_irq_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos += dpcm->pcm_bps; + dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz;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
@@ -274,7 +274,7 @@ static snd_pcm_uframes_t snd_card_dummy_struct snd_pcm_runtime *runtime = substream->runtime;struct snd_dummy_pcm *dpcm = runtime->private_data; -return bytes_to_frames (runtime, dpcm->pcm_buf_pos); +return bytes_to_frames (runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz); } static struct snd_pcm_hardware snd_card_dummy_playback =
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Takashi Iwai
AppliedAt Fri, 22 Feb 2008 19:05:28 +0100,
Quoted 6 lines · Ahmet İnan
when the time interval for a period is smaller than kernel HZ, then snd-aloop and snd-dummy cannot call
snd_pcm_period_elapsedas fast enough annymore. this happens for example with games. but the app still needs to see, that the buffer actually did go further, which is provided by these patches.
Applied to HG tree now. Thanks.
Takashi
Quoted 3 lines
Quoted 2 lines
see, that the buffer actually did go further, which is provided by these patches.
Applied to HG tree now. Thanks.
could it be, that you still forgot to apply this patch, but did the other?
[snd-aloop - better realtime app support]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch2.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]
or you havent synced home alsa-driver with main repository yet, then never mind :)
thanks
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
At Sat, 1 Mar 2008 12:55:06 +0100,
Quoted 6 lines · Ahmet İnan
Quoted 4 lines
Quoted 3 lines
see, that the buffer actually did go further, which is provided by these patches.
Applied to HG tree now. Thanks.
could it be, that you still forgot to apply this patch, but did the other?
It was already applied but a different subject. Please follow the standard patch style at the next time.
Takashi
moved module parameter pcm_substreams range check code around, to prevent catastrophe. removed bogus module parameter pcm_devs code - aloop creates only one pair of devices. allowed float_le, too.
removed obsolete code.
[snd-aloop - more cleanups]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch3.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]
patch is relative to my previous patch.
will fix bogus wiki entries, about the module parameters, too.
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
At Sun, 2 Mar 2008 00:35:03 +0100,
Quoted 11 lines · Ahmet İnan
moved module parameter
pcm_substreamsrange check code around, to prevent catastrophe. removed bogus module parameterpcm_devscode - aloop creates only one pair of devices. allowedfloat_le, too.
removed obsolete code.[snd-aloop - more cleanups]
http://www.mathematik.uni-freiburg.de/IAM/homepages/ainan/alsa-driver-hg-aloop-ainan-patch3.diff
[Signed-off-by: Ahmet İnan <ainan <at> mathematik.uni-freiburg.de>]patch is relative to my previous patch.
Please post the patch instead of URL.
Also, it'd be appreciated if you follow the standard rule for submitting patches. We follow the linux kernel rule for alsa-driver tree, too. See $LINUX/Documentation/SubmittingPatches.
thanks,
Takashi
Quoted 1 line
Also, it'd be appreciated if you follow the standard rule for
thank you for pointing this out. will try my best. patch is relative to current hg-tree.
ahmet
snd-aloop - more cleanups
moved module parameter pcm_substreams range check code around, to prevent catastrophe. removed bogus module parameter pcm_devs code - aloop creates only one pair of devices. allowed float_le, too.
removed obsolete code.
drivers/aloop-kernel.c +12 -22
@@ -39,9 +39,7 @@ static int index[SNDRV_CARDS] = SNDRV_DEstatic int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ;/* Index 0-MAX */ static char *id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ;/* ID for this card */ static int enable[SNDRV_CARDS ] = {1 , [1 ... (SNDRV_CARDS -1 )] =0 }; -static int pcm_devs[SNDRV_CARDS ] = {[0 ... (SNDRV_CARDS -1 )] =1 };static int pcm_substreams[SNDRV_CARDS ] = {[0 ... (SNDRV_CARDS -1 )] =8 }; -/* static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; */ module_param_array (index, int,NULL ,0444 );MODULE_PARM_DESC (index,"Index value for loopback soundcard." );
@@ -49,12 +47,8 @@ MODULE_PARM_DESC(id, "ID string for loopMODULE_PARM_DESC (id,"ID string for loopback soundcard." );module_param_array (enable, bool,NULL ,0444 );MODULE_PARM_DESC (enable,"Enable this loopback soundcard." ); -module_param_array (pcm_devs, int,NULL ,0444 ); -MODULE_PARM_DESC (pcm_devs,"PCM devices # (0-4) for loopback driver." );module_param_array (pcm_substreams, int,NULL ,0444 );MODULE_PARM_DESC (pcm_substreams,"PCM substreams # (1-8) for loopback driver." ); -/* module_param_array(midi_devs, int, NULL, 0444); -* MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for loopback driver."); */ typedef struct snd_card_loopback_cable { struct snd_pcm_substream *playback;
@@ -220,7 +214,8 @@ static struct snd_pcm_hardware snd_card_ { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID), - .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE), + .formats = (SNDRV_PCM_FMTBIT_U8 |SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT_LE), .rates = (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_192000), .rate_min = 8000, .rate_max = 192000,
@@ -395,17 +390,11 @@ static int __init snd_card_loopback_pcm(struct snd_pcm *pcm;int err; -if (0 == device) { -if ((err =snd_pcm_new (loopback->card,"Loopback PCM" , device, substreams, substreams, &pcm)) <0 ) -return err; -snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &snd_card_loopback_playback_ops); -snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_CAPTURE , &snd_card_loopback_capture_ops); - }else { -if ((err =snd_pcm_new (loopback->card,"Loopback PCM" , device, substreams, substreams, &pcm)) <0 ) -return err; -snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &snd_card_loopback_playback_ops); -snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_CAPTURE , &snd_card_loopback_capture_ops); - } +if ((err =snd_pcm_new (loopback->card,"Loopback PCM" , device, substreams, substreams, &pcm)) <0 ) +return err; +snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &snd_card_loopback_playback_ops); +snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_CAPTURE , &snd_card_loopback_capture_ops); + pcm->private_data = loopback; pcm->info_flags =0 ;strcpy (pcm->name,"Loopback PCM" );
@@ -435,6 +424,11 @@ static int __init snd_card_loopback_probreturn -ENOMEM ; loopback = (struct snd_card_loopback *)card->private_data; +if (pcm_substreams[dev] <1 ) + pcm_substreams[dev] =1 ; +if (pcm_substreams[dev] >MAX_PCM_SUBSTREAMS ) + pcm_substreams[dev] =MAX_PCM_SUBSTREAMS ; +for (subdev =0 ; subdev < pcm_substreams[dev]; subdev++) {for (half =0 ; half <2 ; half++) { loopback->cables[subdev][half].playback =NULL ;
@@ -450,10 +444,6 @@ static int __init snd_card_loopback_prob } loopback->card = card; -if (pcm_substreams[dev] <1 ) - pcm_substreams[dev] =1 ; -if (pcm_substreams[dev] >MAX_PCM_SUBSTREAMS ) - pcm_substreams[dev] =MAX_PCM_SUBSTREAMS ;if ((err =snd_card_loopback_pcm (loopback,0 , pcm_substreams[dev])) <0 ) goto __nodev;if ((err =snd_card_loopback_pcm (loopback,1 , pcm_substreams[dev])) <0 )
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: Problem with aloop
In reply to Takashi Iwaiive just read about aloop problems by chance, so excuse the late answer, for ive disabled recieving mails from this list. so also cc me when replying :)
Quoted 1 line
repeating stuttering
try tickless kernel, as it improves the quality of timer interrupts dramatically. dont forget to enable high resolution timer support, hpet and so on.
Quoted 1 line
synchronization issue at the beginning
this is still not resolved and its a pain in the ass to get this done right. ive implemented 4 different ways to solve it and im still not happy with what ive got.
Quoted 1 line
kernel crash when closing
do you really have to put at this manny places this del_timer? try to find the right place and resubmit. :)
ahmet
--
admin der abteilung für angewandte mathematik, tel. 0761-203-5626
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: Problem with aloop
Hi Ahmet,
ive just read about aloop problems by chance, so excuse the late answer,
Quoted 3 lines
for ive disabled recieving mails from this list. so also cc me when replying :)
No problem, I'm delighted somebody is answering my e-mails at all :)
Quoted 5 lines
repeating stuttering
try tickless kernel, as it improves the quality of timer interrupts dramatically.
dont forget to enable high resolution timer support, hpet and so on.
OK, excellent tip. Thanks! High resolution timer support is already enabled and I've got the kernel configured for "realtime" performance (CONFIG_HZ or whatever it was called set to 1000 etc.). I'll try to see if the tickless kernel makes any difference.
Quoted 6 lines
Quoted 1 line
synchronization issue at the beginning
this is still not resolved and its a pain in the ass to get this done right.
ive implemented 4 different ways to solve it and im still not happy with what ive got.
The funny thing is, after I reverted to the 10.0.16 release tarball these stuttering problems went away. So the fixes that were committed in february/march under the 'fixes realtime behaviour' label actually made things much worse..
Quoted 4 lines
Quoted 1 line
kernel crash when closing
do you really have to put at this manny places this
del_timer? try to find the right place and resubmit. :)
I already presumed it was a bit much, I'll be the last one to deny that! ;-)
But then again, I'm not too familiar with ALSA kernel stuff anyway and the existing documentation seems a bit sparse. Also, this patch was made as part of a time-limited project at my company so I sadly couldn't spend more time on it after I (crudely) fixed the bug. However, I'd love to refine my patch (in my own spare time). Can you give me any pointers perhaps? They would be greatly appreciated.
Thanks for taking the time to reply!
Kind regards,
Benjamin
Re: Problem with aloop
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
synchronization issue at the beginning
this is still not resolved and its a pain in the ass to get this done
The funny thing is, after I reverted to the 10.0.16 release tarball these stuttering problems went away. So the fixes that were committed in february/march under the 'fixes realtime behaviour' label actually made things much worse..
without SND_CARD_LOOPBACK_START_SYNC, its still the same. you should really get a tickless kernel first. otherwise its just pure luck and frustration.
Quoted 2 lines
Quoted 1 line
try to find the right place and resubmit. :)
(in my own spare time). Can you give me any pointers perhaps? They would be
usually snd_card_loopback_playback_trigger gets called with SNDRV_PCM_TRIGGER_STOP whenever the device is about to be closed. so the next function would be snd_card_loopback_close. try snd_card_loopback_timer_stop there and report :D
ahmet
Signature · 5 lines
admin der abteilung für angewandte mathematik, tel. 0761-203-5626 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel