Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Aug 2004 16:39:17 +0100
From:      Peter Wood <peter@alastria.net>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: FreeBSD pcm(4) latency (From write() to audible output)
Message-ID:  <411CE0A5.5020708@alastria.net>
In-Reply-To: <20040813151119.GE4198@dan.emsphone.com>
References:  <411CC1EF.5090201@alastria.net> <20040813151119.GE4198@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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) :: <peter@alastria.net> :: Tel +44 7974 799440



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?411CE0A5.5020708>