From owner-freebsd-chat@FreeBSD.ORG Fri Aug 13 15:05:45 2004 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 761AD16A4CE for ; Fri, 13 Aug 2004 15:05:45 +0000 (GMT) Received: from hak.cnd.mcgill.ca (hak.cnd.mcgill.ca [132.216.11.133]) by mx1.FreeBSD.org (Postfix) with ESMTP id 070DD43D2F for ; Fri, 13 Aug 2004 15:05:45 +0000 (GMT) (envelope-from mat@hak.cnd.mcgill.ca) Received: from hak.cnd.mcgill.ca (localhost [127.0.0.1]) by hak.cnd.mcgill.ca (8.12.9/8.12.8) with ESMTP id i7DFCVP3001790; Fri, 13 Aug 2004 11:12:31 -0400 (EDT) (envelope-from mat@hak.cnd.mcgill.ca) Received: (from mat@localhost) by hak.cnd.mcgill.ca (8.12.9/8.12.8/Submit) id i7DFCU1X001789; Fri, 13 Aug 2004 11:12:30 -0400 (EDT) Date: Fri, 13 Aug 2004 11:12:30 -0400 From: Mathew Kanner To: Peter Wood Message-ID: <20040813151230.GB280@cnd.mcgill.ca> References: <411C9FE9.3000905@alastria.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <411C9FE9.3000905@alastria.net> User-Agent: Mutt/1.4.1i Organization: I speak for myself, operating in Montreal, CANADA X-Spam-Status: No, hits=0.0 required=5.0 tests=none autolearn=no version=2.62 X-Spam-Checker-Version: SpamAssassin 2.62 (2004-01-11) on hak.cnd.mcgill.ca cc: freebsd-chat@freebsd.org Subject: Re: FreeBSD pcm(4) latency (From write() to audible output) X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2004 15:05:45 -0000 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/