From owner-freebsd-multimedia@freebsd.org Sun Jul 30 22:10:48 2017 Return-Path: Delivered-To: freebsd-multimedia@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EB685DC36A3 for ; Sun, 30 Jul 2017 22:10:48 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A03CE828B4 for ; Sun, 30 Jul 2017 22:10:48 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2016.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 709862607A0; Mon, 31 Jul 2017 00:10:45 +0200 (CEST) Subject: Re: snd_uaudio monitor recording To: Marcel Bonnet Cc: FreeBSD multimedia References: From: Hans Petter Selasky Message-ID: <579d149d-7f44-3290-0adc-fbed8e48316e@selasky.org> Date: Mon, 31 Jul 2017 00:08:36 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------572D96BB2DE5A55BDCD567D7" Content-Language: en-US X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jul 2017 22:10:49 -0000 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 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--