From owner-freebsd-questions@FreeBSD.ORG Fri Aug 13 15:39:28 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ED06716A4CE for ; Fri, 13 Aug 2004 15:39:27 +0000 (GMT) Received: from parallax.alastria.net (parallax.alastria.net [81.7.140.70]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5EEE443D39 for ; Fri, 13 Aug 2004 15:39:27 +0000 (GMT) (envelope-from peter@alastria.net) Received: from [10.2.0.1] (shuttle.cw9.co.uk [82.152.14.18]) i7DFdIHs043290; Fri, 13 Aug 2004 15:39:18 GMT (envelope-from peter@alastria.net) Message-ID: <411CE0A5.5020708@alastria.net> Date: Fri, 13 Aug 2004 16:39:17 +0100 From: Peter Wood Organization: Alastria Networks User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Dan Nelson References: <411CC1EF.5090201@alastria.net> <20040813151119.GE4198@dan.emsphone.com> In-Reply-To: <20040813151119.GE4198@dan.emsphone.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Flag: NO X-Virus-Status: No X-Spam-Score: 0 () X-Spam-Ultra-Flag: NO X-Spam-Low-Flag: NO X-Spam-Flag: NO X-Spam-High-Flag: NO X-Scanned-By: MIMEDefang 2.42 cc: carnaily@softhome.net cc: freebsd-questions@freebsd.org Subject: Re: FreeBSD pcm(4) latency (From write() to audible output) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2004 15:39:28 -0000 Heya Dan, >>I've found that there is about a 800ms delay between the output data >>being written to /dev/dsp and being able to hear the output from the >>soundcard on FreeBSD. I'm working to a 200ms deadline. > What's your write size? At 44100khz*2 channels, a 65k write would take > around 800 ms to play. Try writing smaller chunks, or maybe raise > hw.snd.targetirqrate. Don't I feel like a dunce right now. I forgot the cardinal rule of reproducing my results with other software. I tried the same file with XMMS and it played instantly. My problem was primarly due to the fragment sizes of buffers. I don't know what sizes are set as default but they're to big for my applpications. I've found with: val = (2 << 16) | 9; ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &val); It kills the delay to next to nothing. As far as I understand this, and it's not well, the above means use a maximum of 2 fragments and each fragment should be 2^9 large (ie 512 bytes long). Which I figure to be 1204 bytes total for buffer (or 5ms). It still doesn't happen that quickly for me, but what I'd imagin is delaying it now (and is my problem) is the write() I'm doing. As I'm writing 20ms of Audio out at any time, so I'm waiting for that to complete. Thanks for the suggestion Dan, helped a lot. Andreas, this will be your problem to for your guitar problem, try using the above code (add error checks, it can fail on some hardware (statically set fragments)). I also managed to find the guide to OSS at http://www.opensound.com/pguide/oss.pdf, I shall be looking there before asking here again, don't worry. Off to knock the dust of my dunce cap off, Pete. -- Peter Wood BSc (Hons) :: :: Tel +44 7974 799440