FreeBSD pcm(4) latency (From write() to audible output)

Mathew Kanner mat at cnd.mcgill.ca
Fri Aug 13 08:05:45 PDT 2004


On Aug 13, Peter Wood wrote:
> I'm currently in the middle of writing an automated radio playout system 
> for a northern student radio station in the UK (post SBN liquidation).
> 
> I have the requirement of it running on a *nix system. I'm a large BSD 
> advocate between our friends, so would prefer not to use Linux.
> 
> The system design consists of a daemon for each soundcard used in the 
> studio. I'm currently in the process of writing this daemon.
> 
> 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.
> 
> I'm opening the soundcard with:
> 
> audio_fd = open((char *) device, O_WRONLY | O_FSYNC | O_DIRECT);
> 
> I've used O_DIRECT and O_FSYNC to try and get rid of this delay, but 
> alas that didn't work, device is cast as it's coming from a void * 
> (thanks to pthread_create ;).
> 
> The daemon outputs blocks of 0 when there is no actual audio to output 
> so the sound card is always fed.
> 
> While this isn't a problem for mpg123, it is for this application.  I've 
> tried to find where the delay is, however I haven't had any luck.
> 
> Could anyone knowledgable let me know if there's any hope for getting 
> rid of it (hacking the kernel is fine ;) or if I should "give up" and go 
> to linux?
> 
> I suppose Linux does have ALSA which claims 2.6ms latency but I was 
> hoping to just use OSS. Oh well.
> 
> For reference the test machine is a 2.2Ghz machine with a AC97 chip 
> (yeah crap I know, studio playout machines will probably have a Creative 
> card) running 4.10-STABLE (Yeasturday's cvsup).
> 
> My appologies if this isn't the right place, I'm happy to go pester else 
> where. Heh.


	Freebsd-multimedia would be the right place.  I think what you
want is a smaller block size.  The SNDCTL_DSP_SETBLKSIZE should be the
right IOCTL to use, check out the oss programmers manual, I don't have
a link right now but google should find it pretty quick.

	--Mat
-- 
		Applicants must also have extensive knowledge of UNIX,
	although they should have sufficiently good programming
	taste to not consider this an achievement.
			- MIT AI Lab job ad in the /Boston Globe/



More information about the freebsd-chat mailing list