Mail Archives: djgpp/1998/01/31/07:46:41

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Sample playback frequency change
Date: Sat, 31 Jan 1998 09:35:25 +0000
Organization: None
Distribution: world
Message-ID: <>
References: <6aul51$qua AT bgtnsc03 DOT worldnet DOT att DOT net>
MIME-Version: 1.0
Lines: 28
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Steve Patton writes:
>My question is, how could I render something that's at one frequency, 
>at another frequency, without the actual sample changine, like if it 
>were at 44100 and I wanted to play it at 22050, I would simply just 
>have it skip every other byte (or short in 16-bit sapmles). But since 
>it's not even, what would be a good algorithm to have it play at a 
>different frequency.

If you just create the AUDIOSTREAM object with the frequency of your
waveform data, the Allegro mixing code will automatically adjust it to
the output sample rate by skipping sample values as you suggest. This
can introduce some distortion if the rates are not in an even ratio
because it will be skipping a different number of samples between each
output point, but this is usually quite acceptable.

For a higher quality sample rate conversion, the first step is to
interpolate the waveform rather than just grabbing the closest sample
point. If the play position falls in between two samples, tween between
them to get a more accurate estimation of the correct value.

For a _really_ high quality rate conversion you should filter the
waveform to remove sampling artifacts, but I don't know the math behind
this and would be very doubtful if it can be done properly in realtime.

Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk -
"Pigs use it for a tambourine" - Frank Zappa

- Raw text -

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