Message-ID: From: Shawn Hargreaves To: djgpp AT delorie DOT com Subject: Re: Q: Allegro, precise sound timing Date: Tue, 23 Nov 1999 15:09:37 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" Reply-To: djgpp AT delorie DOT com Bettina Altmann writes: > for an experiment we have to compare the exact timing of a click > that is presented by the soundcard with that of a keypress. > Therefore we have to know the position of the voice playing the > audiostream containing the clicks very precisely. Test of int > voice_get_position(int voice) yielded that it gives the current > position only in units of 248 samples (with our setup). This is inevitable on all the soundcards that Allegro supports, and indeed on most PC sound hardware, because the cards work by transferring blocks of samples by DMA, and then at the end of each block, generating an interrupt to let the CPU refill the next block of sound data. This means that there will always be a slight delay between the CPU generating each block of sound, and the card actually playing it, and also that the CPU will only be able to access sound information according to the granularity of whatever block size it is using. Most DOS and Windows sound drivers use buffer sizes somewhere in the range of 1k or 2k: Allegro tends to be more like 256 or 512 bytes, so the latencies are far better than average, and are adequate for playing music without noticable timing errors. But, this is still nowhere near useful for experiments that need to measure exact response time (which I presume is what you are doing here). You can improve things by increasing the playback frequency, and even more if you decrease the buffer size in the sb.c file, but the latency will never truly go away, and if you make the buffers too small the interrupt load will crash your machine. For zero latency sound, you can operate the SB by writing sample values directly to ports rather than using DMA transfers. That requires your program to spend all the time just sat there pushing data to the card, though, rather than it working in the background, and Allegro won't do that for you so you'd need to write all your own sound code. Alternatively, you could use some other hardware that is more geared towards instant response, like the PC speaker, or a MIDI note playing system like Adlib or AWE32. Shawn Hargreaves.