Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Matija Nalis <mnalis-alsadev@voyager.hr>
Cc: alsa-devel@alsa-project.org
Subject: Re: cmipci and sound skipping ?
Date: Mon, 15 Mar 2010 13:17:20 +0100	[thread overview]
Message-ID: <4B9E2550.4030404@ladisch.de> (raw)
In-Reply-To: <20100313201138.GA25034@eagle102.home.lan>

Matija Nalis wrote:
> My card is "Asonic C-Media8738, 4 channel" and mostly works with snd_cmipci
> driver - it is just that (even on completely unloaded system) the sound is
> (very annoyingly) skipping.
> ...
> ALSA pcm_lib.c:316: BUG: pcmC0D0p:0, pos = 4294918144, buffer size = 16384, period size = 1024
> 
> Note that the pos is *always* the same (4294918144 = 0xffff4000 = -16384) which might be important.

This looks like a hardware bug.

It's possible that we can get a valid pointer by reading the register
multiple times.  Please try the patch below.


Regards
Clemens


diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1ded64e..8416b8a 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -941,13 +941,21 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci
 						struct snd_pcm_substream *substream)
 {
 	size_t ptr;
-	unsigned int reg;
+	unsigned int reg, rem, tries;
+
 	if (!rec->running)
 		return 0;
 #if 1 // this seems better..
 	reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2;
-	ptr = rec->dma_size - (snd_cmipci_read_w(cm, reg) + 1);
-	ptr >>= rec->shift;
+	for (tries = 0; tries < 5; tries++) {
+		rem = snd_cmipci_read_w(cm, reg);
+		if (rem < rec->dma_size)
+			goto ok;
+	} 
+	printk(KERN_ERR "cmipci: invalid PCM pointer: %#x\n", rem);
+	return SNDRV_PCM_POS_XRUN;
+ok:
+	ptr = (rec->dma_size - (rem + 1)) >> rec->shift;
 #else
 	reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1;
 	ptr = snd_cmipci_read(cm, reg) - rec->offset;

  reply	other threads:[~2010-03-15 12:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-13 20:11 cmipci and sound skipping ? Matija Nalis
2010-03-15 12:17 ` Clemens Ladisch [this message]
2010-03-15 19:35   ` Matija Nalis
2010-03-23  8:36     ` Clemens Ladisch
     [not found]       ` <20100323201749.GA4675@eagle102.home.lan>
2010-03-24  6:57         ` Clemens Ladisch

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=4B9E2550.4030404@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=mnalis-alsadev@voyager.hr \
    /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