delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/23/12:05:03

Message-ID: <F77915E7F086D31197F4009027CC81C90DB7FA@probe-2.as-london.acclaim.com>
From: Shawn Hargreaves <SHargreaves AT acclaimstudios DOT co DOT uk>
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)
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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019