From owner-freebsd-multimedia@FreeBSD.ORG Tue Jan 24 20:22:40 2012 Return-Path: Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 641791065674 for ; Tue, 24 Jan 2012 20:22:40 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-ee0-f54.google.com (mail-ee0-f54.google.com [74.125.83.54]) by mx1.freebsd.org (Postfix) with ESMTP id EFF4A8FC0A for ; Tue, 24 Jan 2012 20:22:39 +0000 (UTC) Received: by eekb47 with SMTP id b47so1874165eek.13 for ; Tue, 24 Jan 2012 12:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=9XyH5s19xV/9Y9RNONg6o/x7y415qaDHah98M40DnLg=; b=g/eCi6emHDALLkL22fsBPgyeaUt7EN1awJu6i0/HMte8BxFbwsk0XkvvxYTrj1gm5B yZ7HqIPI5izC/n0lokDikzi4fzY3dIbwJrnEs3wzDql3NOZjMIO4MhzC9BbdSTDHIgPF AXUzkh7/0NZNPIkCc+sfQW/1NnzX508f2456A= Received: by 10.14.17.101 with SMTP id i77mr4980537eei.30.1327436558299; Tue, 24 Jan 2012 12:22:38 -0800 (PST) Received: from mavbook2.mavhome.dp.ua (pc.mavhome.dp.ua. [212.86.226.226]) by mx.google.com with ESMTPS id b49sm71885342eec.9.2012.01.24.12.22.36 (version=SSLv3 cipher=OTHER); Tue, 24 Jan 2012 12:22:37 -0800 (PST) Sender: Alexander Motin Message-ID: <4F1F1309.3090300@FreeBSD.org> Date: Tue, 24 Jan 2012 22:22:33 +0200 From: Alexander Motin User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:9.0) Gecko/20111227 Thunderbird/9.0 MIME-Version: 1.0 To: freebsd-multimedia@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [RFC] Soft sound buffer size smaller then hard buffer size X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jan 2012 20:22:40 -0000 Hi. I was reported about some sound cards that have fixed 64K buffer with 2K or 8K block sizes. Experimenting with the sound(4) code I've noticed that while it automatically tuning buffer sizes, it almost never sets soft buffer size less then hard buffer size and it always tries to keep all playback buffers full. On the mentioned cards that makes sound(4) set both soft and hard buffers to 64K and results in playback latency at 44100/16/2 of about 800ms! To improve that situation, I've made a patch that allows to set soft buffer size down to just two blocks of the hard buffer and to not write more then that size ahead to the hardware buffer. As result of that change I was able to reduce full practically measured record-playback loop delay in those conditions down to only about 115ms with theoretical playback latency of only about 50ms! Patch works fine for both vchans and direct cases. In both cases sound(4) tries to follow hw.snd.latency_profile and hw.snd.latency values and application-requested buffer size as much as limitation of two hardware blocks allows. The patch can be found here: http://people.freebsd.org/~mav/sound.latency.patch Can somebody review this and tell me whether is this correct? Thank you! -- Alexander Motin