Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 Jul 2017 00:08:36 +0200
From:      Hans Petter Selasky <hps@selasky.org>
To:        Marcel Bonnet <marcelbonnet@gmail.com>
Cc:        FreeBSD multimedia <freebsd-multimedia@freebsd.org>
Subject:   Re: snd_uaudio monitor recording
Message-ID:  <579d149d-7f44-3290-0adc-fbed8e48316e@selasky.org>
In-Reply-To: <CAPe0dBmTSPWv70e4QSaTxgNJhXPt4v5QnNkVPbbb6cpVOOn8-g@mail.gmail.com>
References:  <CAPe0dB=wUyr4NZPxEDSfe7jh%2BiJ-17EpgfhJLFjqysV4DBshLw@mail.gmail.com> <a567dbbb-c533-c450-828e-7207f46f7738@selasky.org> <CAPe0dBkDAAdYRSNsrAmu1Xq%2BU6gN_pZG0c22b1FRQrAJ-kK8iw@mail.gmail.com> <a62dc1ef-58fe-a548-b8ab-24d299dde47b@selasky.org> <CAPe0dBk5cbq9VU=yD89qiMU2F27xb5E%2Bsfr3CmxdLVL2M_nn9Q@mail.gmail.com> <c71b6677-0700-5218-3d8f-b41658f6e731@selasky.org> <CAPe0dBmTSPWv70e4QSaTxgNJhXPt4v5QnNkVPbbb6cpVOOn8-g@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------572D96BB2DE5A55BDCD567D7
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

On 07/30/17 22:46, Marcel Bonnet wrote:
> On 30 July 2017 at 07:56, Hans Petter Selasky <hps@selasky.org> wrote:
>> On 07/28/17 15:55, Marcel Bonnet wrote:
>>>
>>> 2.1 But, when I started YouTube (chromium browser), virtual_oss
>>> stopped with a message: Floating point exception . After crash, I had
>>> no sound anymore. I had to re run virtual_oss to get system sound
>>> again.
>>
>>
>> Hi,
>>
>> Can you open the core dump with GDB and get the backtrace?
>>
>> Maybe you need to compile virtual_oss with DEBUG from the ports tree.
>>
>> I believe this is some kind of low hanging fruit - division by zero.
>>
>> --HPS
> 
> Hello!
> 
> Is this the repo? https://github.com/hselasky/virtual_oss
> 
> Below, is the backtrace.
> 

Hi,

Can you try the attached patch?

--HPS


--------------572D96BB2DE5A55BDCD567D7
Content-Type: text/x-patch;
 name="voss.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="voss.diff"

Index: virtual_main.c
===================================================================
--- virtual_main.c	(revision 3948)
+++ virtual_main.c	(working copy)
@@ -1029,6 +1029,33 @@
 	return (vclient_setup_buffers(pvc, 0, 0, channels, 0, 0));
 }
 
+/* greatest common divisor, Euclid equation */
+static uint64_t
+vclient_gcd_64(uint64_t a, uint64_t b)
+{
+	uint64_t an;
+	uint64_t bn;
+
+	while (b != 0) {
+		an = b;
+		bn = a % b;
+		a = an;
+		b = bn;
+	}
+	return (a);
+}
+
+static uint64_t
+vclient_scale(uint64_t value, uint64_t mul, uint64_t div)
+{
+	uint64_t gcd = vclient_gcd_64(mul, div);
+
+	mul /= gcd;
+	div /= gcd;
+
+	return ((value * mul) / div);
+}
+
 static int
 vclient_ioctl_oss(struct cuse_dev *pdev, int fflags,
     unsigned long cmd, void *peer_data)
@@ -1050,8 +1077,7 @@
 	vclient_t *pvc;
 	vblock_t *pvb;
 
-	uint64_t rem;
-	uint64_t div;
+	uint64_t bytes;
 
 	int len;
 	int error;
@@ -1300,31 +1326,22 @@
 	case SNDCTL_DSP_CURRENT_IPTR:
 	case SNDCTL_DSP_CURRENT_OPTR:
 		memset(&data.oss_count, 0, sizeof(data.oss_count));
-		/* compute sample ratio */
-		rem = voss_dsp_sample_rate % pvc->sample_rate;
-		div = voss_dsp_sample_rate / pvc->sample_rate;
-		/* compute division error */
-		rem *= (voss_dsp_blocks - pvc->start_block);
-		rem /= pvc->sample_rate;
-		/* compute output samples */
-		data.oss_count.samples = (voss_dsp_blocks - pvc->start_block - rem) *
-		    (voss_dsp_samples / div) * pvc->channels;
+		/* compute input/output samples */
+		data.oss_count.samples =
+		    vclient_scale((voss_dsp_blocks - pvc->start_block) * voss_dsp_samples,
+		    pvc->sample_rate, voss_dsp_sample_rate) * pvc->channels;
 		break;
 	case SNDCTL_DSP_GETOPTR:
 	case SNDCTL_DSP_GETIPTR:
 		memset(&data.oss_count_info, 0, sizeof(data.oss_count_info));
-		/* compute sample ratio */
-		rem = voss_dsp_sample_rate % pvc->sample_rate;
-		div = voss_dsp_sample_rate / pvc->sample_rate;
-		/* compute division error */
-		rem *= (voss_dsp_blocks - pvc->start_block);
-		rem /= pvc->sample_rate;
-		/* compute output samples */
-		rem = (voss_dsp_blocks - pvc->start_block - rem) *
-		    (voss_dsp_samples / div) * pvc->channels * vclient_sample_bytes(pvc);
-		data.oss_count_info.bytes = rem;
-		data.oss_count_info.blocks = rem / pvc->buffer_size;
-		data.oss_count_info.ptr = rem;
+		/* compute input/output bytes */
+		bytes =
+		    vclient_scale((voss_dsp_blocks - pvc->start_block) * voss_dsp_samples,
+		    pvc->sample_rate, voss_dsp_sample_rate) * pvc->channels *
+		    vclient_sample_bytes(pvc);
+		data.oss_count_info.bytes = bytes;
+		data.oss_count_info.blocks = bytes / pvc->buffer_size;
+		data.oss_count_info.ptr = bytes;
 		break;
 	case SNDCTL_DSP_HALT_OUTPUT:
 		pvc->tx_enabled = 0;

--------------572D96BB2DE5A55BDCD567D7--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?579d149d-7f44-3290-0adc-fbed8e48316e>