All of lore.kernel.org
 help / color / mirror / Atom feed
* Division by zero in snd_pcm_rate_sw_params()
@ 2004-07-24  1:30 Francois Gouget
  2004-07-24 10:02 ` James Courtier-Dutton
  0 siblings, 1 reply; 4+ messages in thread
From: Francois Gouget @ 2004-07-24  1:30 UTC (permalink / raw)
  To: alsa-devel; +Cc: Wine Devel

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

Hi,

I am working on Wine and lately I have been tracking various sound 
related issues. One issue I noticed is a crash in Wine's winmm wave test 
when using the Alsa sound backend.

More precisely:
  * if Wine's winmm wave test is the only application using the sound 
device, then it works
  * but if another application is already using the sound device (e.g. 
xmms), then Wine's winmm wave test crashes when trying to play the 96kHz 
test.

The crash occurs when calling snd_pcm_sw_params():

     EXIT_ON_ERROR( snd_pcm_sw_params(pcm, sw_params), MMSYSERR_ERROR, 
"unable to set sw params for playback");

See this URL for the exact source:
http://source.winehq.org/source/dlls/winmm/winealsa/audio.c#L1602

Digging some more I found out that the division by zero happens in the 
snd_pcm_rate_sw_params() function pcm_rate.c. Here's why:

  * Wine sets xfer_align to 1:
    EXIT_ON_ERROR(snd_pcm_sw_params_set_xfer_align(pcm, sw_params, 1),
                  MMSYSERR_ERROR, "unable to set xfer align");

  * then it calls snd_pcm_sw_params() as shown above

  * eventually we get to snd_pcm_rate_sw_params() in src/pcm/pcm_rate.c. 
(http://cvs.sourceforge.net/viewcvs.py/alsa/alsa-lib/src/pcm/pcm_rate.c?rev=1.83&view=markup)

  * There we call recalc():

    recalc(pcm, &sparams->xfer_align);

  * when more than one application uses the soundcard, recalc() ends up 
doing:

    *val = muldiv_near(*val, slave->period_size, pcm->period_size);

  * however in my case slave->period_size is less than half of 
pcm->period_size so I end up with xfer_align == *val == 0.

  * then, a few lines later in snd_pcm_rate_sw_params() we do:

     if (sparams->start_threshold > (slave->buffer_size /
             sparams->xfer_align) * sparams->xfer_align)
         sparams->start_threshold = (slave->buffer_size /
             sparams->xfer_align) * sparams->xfer_align;

    And we crash with a division by zero because now sparams->xfer_align==0.
    (these lines were added in CVS revision 1.83 of this file)

Simply resetting xfer_align to 1 is it is zero after the call to 
recalc() (see attached patch) fixes the problem for me (no crash and the 
test tone plays correctly). However I don't know if this is the right 
fix, hence the following questions:

Does my patch look ok? What is the proper procedure to get it applied? 
Is there further information I can provide to resolve this issue?

My configuration:
  * Up to date Debian testing
  * Alsa 1.0.5a
  * cat /proc/asound/cards
0 [V8235          ]: VIA8233 - VIA 8235
                      VIA 8235 at 0xbc00, irq 5


-- 
Francois Gouget
fgouget@codeweavers.com


[-- Attachment #2: pcm_rate.diff --]
[-- Type: text/plain, Size: 497 bytes --]

--- pcm_rate.c.orig	2004-07-24 03:19:41.000000000 +0200
+++ pcm_rate.c	2004-07-24 03:20:41.000000000 +0200
@@ -630,6 +638,8 @@
 	recalc(pcm, &sparams->avail_min);
 	rate->orig_avail_min = sparams->avail_min;
 	recalc(pcm, &sparams->xfer_align);
+	if (sparams->xfer_align==0)
+		sparams->xfer_align=1;
 	recalc(pcm, &sparams->start_threshold);
 	if (sparams->start_threshold <= slave->buffer_size) {
 		if (sparams->start_threshold > (slave->buffer_size / sparams->avail_min) * sparams->avail_min)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Division by zero in snd_pcm_rate_sw_params()
  2004-07-24 10:02 ` James Courtier-Dutton
@ 2004-07-24  9:50   ` Jaroslav Kysela
  2004-07-24 10:36   ` Francois Gouget
  1 sibling, 0 replies; 4+ messages in thread
From: Jaroslav Kysela @ 2004-07-24  9:50 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: alsa-devel

On Sat, 24 Jul 2004, James Courtier-Dutton wrote:

> Once I have tested my code more fully, I will post a patch to the list.
> I have been posting patches for pcm_rate.c already, but although they 
> are better than before, they still do not work in all cases.

I appreciate your work.

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Division by zero in snd_pcm_rate_sw_params()
  2004-07-24  1:30 Division by zero in snd_pcm_rate_sw_params() Francois Gouget
@ 2004-07-24 10:02 ` James Courtier-Dutton
  2004-07-24  9:50   ` Jaroslav Kysela
  2004-07-24 10:36   ` Francois Gouget
  0 siblings, 2 replies; 4+ messages in thread
From: James Courtier-Dutton @ 2004-07-24 10:02 UTC (permalink / raw)
  To: Francois Gouget; +Cc: alsa-devel

Francois Gouget wrote:
> Hi,
> 
> I am working on Wine and lately I have been tracking various sound 
> related issues. One issue I noticed is a crash in Wine's winmm wave test 
> when using the Alsa sound backend.
> 

This and other problems are caused by the many bug/problems with the 
pcm_rate.c plugin. I have been doing some work on the pcm_rate.c plugin, 
and your patch contains something one of the bug fixes I already have 
here fixes. I could reproduce it without needing wine.

Once I have tested my code more fully, I will post a patch to the list.
I have been posting patches for pcm_rate.c already, but although they 
are better than before, they still do not work in all cases.

James


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Division by zero in snd_pcm_rate_sw_params()
  2004-07-24 10:02 ` James Courtier-Dutton
  2004-07-24  9:50   ` Jaroslav Kysela
@ 2004-07-24 10:36   ` Francois Gouget
  1 sibling, 0 replies; 4+ messages in thread
From: Francois Gouget @ 2004-07-24 10:36 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: alsa-devel

James Courtier-Dutton wrote:
[...]
> This and other problems are caused by the many bug/problems with the 
> pcm_rate.c plugin. I have been doing some work on the pcm_rate.c plugin, 
> and your patch contains something one of the bug fixes I already have 
> here fixes. I could reproduce it without needing wine.

I just wanted to report the problem to make sure it was known and also 
to check Wine is not doing something wrong.
Since you're obviously aware of the problem and even working on a 
solution everything's perfect!

Thanks for your work.

-- 
Francois Gouget
fgouget@codeweavers.com



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-07-24 10:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-24  1:30 Division by zero in snd_pcm_rate_sw_params() Francois Gouget
2004-07-24 10:02 ` James Courtier-Dutton
2004-07-24  9:50   ` Jaroslav Kysela
2004-07-24 10:36   ` Francois Gouget

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.