From: djs@jet.uk (David J Stevenson)
Newsgroups: comp.sys.amiga.audio
Subject: Re: Halving sample speed while keeping pitch
Date: 26 Aug 92 14:54:36 GMT
Organization: Joint European Torus

In <ERICJ.92Aug24131911@lagos.cfsat.Honeywell.COM> ericj@hwcae.Honeywell.COM (Eric Jacobsen) writes:

>In article <9208241809.AA00474@.nairobi.inel.gov.inel.gov.> mnu@INEL.GOV (Rick Morneau) writes:

>   I don't want to change the sampling rate - I want to slow down the  
>   signal without changing the pitch of the human voice (in case you're  
>   wondering, I'm working with speech, NOT music). In other words, I  
>   want to stretch out the signal so that it sounds like the speaker is  
>   speaking more slowly, with out distorting the pitch.

>Oh! NOW I understand! It sure sounded like you were asking for a method
>of downsampling. My apologies for the confusion on my part.

>What you are asking for is possible, but not trivial to accomplish
>and not the sort of thing I'd expect to see in most canned software.

>One way to get what you are looking for:

>1. Upsample the signal until it is of the length you wish. The pitch
>will be lower, but you can get the time duration you want.

>2. Take the upsampled signal and mix it with a sine wave that shifts
>the pitch back up. (You get a sum and difference frequency, you filter
>out the difference freq). Actually, this is kinda tough to do 
>digitally. It is a lot easier to do this in the analog domain when
>you play it back.
Eh?  What pitch sine wave? At what level?
What the software actually needs to do is double the number of samples
in the signal; this is what oversampling does.  So, between every sample
in the source signal add a sample at the zero level (may be zero, or 32768
or whatever, depending on number of bits and whether the signal data is
signed).  This gives the correct number of samples, but has introduced some
high-frequency distortion.

However, this distortion is ABOVE the maximum frequency present in the
original signal (see Nyquist theorem).  It can therefore be removed by a
simple filter.  How to design digital filters is a complex subject to
understand, but the algorithms for designing filters are available in the
public domain.  Search the comp.dsp FAQ for references on filter design.  If
the signal sample rate is fixed, you only need design the filter once, and
can do so with as many (or few) parameters as your run-time routines can
handle.

Example:  You have a signal sampled at 25kHz for 4 seconds.  Add the zeros,
giving you 200k samples in total.  The highest frequency in the original
signal is (in theory; in practise it may actually be lower) 12.5kHz.  Apply
a digital filter to remove frequencies above this.  Your zeros will now
be an interpolation between the 'real' values from the original signal.

Notes:  If the signal is going to be output through some fairly low quality
        device, it may be sufficient to simplify this by inserting, between
        each real sample, a new sample which is half-way between the samples
        either side.  This is, conceptually, the same as following the above
        scheme, but with a simple, lowish-quality, digital filter stage.

        Digital filters are easier to implement on specialist DSPs; I am not
        an Amiga person, so I do not know if such processors are available
        as add-ins.  The NeXT and Atari Falcon machines have DSPs built in.

Hope this helps, and I suggest you find an FAQ for comp.dsp, if there is
one.

-- 
+---------------------------------------------------+
| David Stevenson  djs@jet.uk   Tel: +44 235 465028 |
+---------------------------------------------------+
- Disclaimer: Please note that the above is a personal view and should not 
  be construed as an official comment from the JET project.
Newsgroups: comp.sys.amiga.audio