From: Francois Gouget <fgouget@codeweavers.com>
To: alsa-devel@lists.sourceforge.net
Cc: Wine Devel <wine-devel@winehq.org>
Subject: Division by zero in snd_pcm_rate_sw_params()
Date: Sat, 24 Jul 2004 03:30:06 +0200 [thread overview]
Message-ID: <4101BB9E.8010207@codeweavers.com> (raw)
[-- 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)
next reply other threads:[~2004-07-24 1:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-24 1:30 Francois Gouget [this message]
2004-07-24 10:02 ` Division by zero in snd_pcm_rate_sw_params() James Courtier-Dutton
2004-07-24 9:50 ` Jaroslav Kysela
2004-07-24 10:36 ` Francois Gouget
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=4101BB9E.8010207@codeweavers.com \
--to=fgouget@codeweavers.com \
--cc=alsa-devel@lists.sourceforge.net \
--cc=wine-devel@winehq.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 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.