Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ahmet İnan" <ainan@mathematik.uni-freiburg.de>
To: alsa-devel@alsa-project.org
Subject: Re: [PATCH] improved snd-aloop quality when using certain samplerates and kernel HZ
Date: Tue, 19 Feb 2008 13:50:46 +0100	[thread overview]
Message-ID: <20080219125046.GA6455@mathematik.uni-freiburg.de> (raw)
In-Reply-To: <20080219030144.GA12698@mathematik.uni-freiburg.de>

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

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>
 
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

[-- Attachment #2: alsa-driver-1.0.15-aloop-ainan-patch1.diff --]
[-- Type: text/plain, Size: 4340 bytes --]

--- aloop-kernel-orig.c	2008-02-19 03:27:10.203115360 +0100
+++ aloop-kernel.c	2008-02-19 13:39:27.040593408 +0100
@@ -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 <perex@perex.cz>");
 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;

[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2008-02-19 12:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-19  3:01 [PATCH] improved snd-aloop quality when using certain samplerates and kernel HZ Ahmet İnan
2008-02-19 12:50 ` Ahmet İnan [this message]
2008-02-20 11:47   ` Takashi Iwai
2008-02-20 14:19     ` Ahmet İnan
2008-02-20 16:08       ` Takashi Iwai
2008-02-21  0:06         ` Ahmet İnan
2008-02-21  6:54           ` Takashi Iwai
2008-02-22 18:05             ` Ahmet İnan
2008-02-28 11:48               ` Takashi Iwai
2008-03-01 11:55                 ` Ahmet İnan
2008-03-01 15:22                   ` Takashi Iwai
2008-03-01 23:35                     ` Ahmet İnan
2008-03-06 15:51                       ` Takashi Iwai
2008-03-06 20:51                         ` Ahmet İnan
2008-05-31 20:00                         ` Problem with aloop Ahmet İnan
2008-06-01 16:15                           ` Benjamin van den Hout
2008-06-02  8:08                             ` Ahmet İnan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080219125046.GA6455@mathematik.uni-freiburg.de \
    --to=ainan@mathematik.uni-freiburg.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox