[comp.sys.amiga] Sampling at 29KHz

rokicki@polya.STANFORD.EDU (Tomas G. Rokicki) (05/19/88)

[ Sample *this*, you soundless hulk! ]

	Why Sampling At 29K Is Usually Sufficient

	First, I'm not sure I know what I'm talking about
here, as I'm not a musician and know very little about sound,
but let's pretend I do know what I'm talking about for a
second or two.

	Some people have been bitching lately about having to
provide waveforms for each octave of a sound sample.  I won't
go into issues here about how the relative frequency
distribution changes as a function of frequency for musical
instruments, other than to note that it does, so actually
sampling the different octaves will give you more realistic
sound, but rather I will explain how using separate samples for
the higher frequencies works better than undersampling higher
resolution samples, by stepping through them at a faster rate.

	First, any infinite periodic waveform of period t with
n samples can be represented as a sum of n sine waves with
periods of t/1, t/2, t/3...t/n.  The discrete fourier transform
can do (and undo) this transformation.

	If you undersample such a waveform, aliasing will cause
some strange effects.  Let us say our sampling rate that we are
undersampling at is m (samples per second.)  According to Nyquist,
our sampling rate should be at least twice the frequency of the
highest component sine wave.  Any components that have a
frequency greater than 2/m will have some portion of their energy
aliased or mirrored down to a lower frequency.

	To demonstrate this, let us look at a 10KHz sine wave.
We'll sample it at 20KHz, exactly the Nyquist rate.  If our
samples happen to fall exactly at the zero crossings of the sine
wave, we will have a zero amplitude output.  If they fall on
the peaks, we will have a maximum amplitude output.  Depending
on the random position of our first sample.

	Now let's sample our 10KHz sine wave at 20.2KHz.  We
are now slightly off our frequency, and we will see a 10KHz
tone modulated by a 200 Hz carrier; this will sound like two
narrowly separated frequencies beating against one another.
Ugly as sin.

	Let's now sample a 16KHz sine wave at 20KHz.  In this
case, we will get as output approximately a 4KHz tone at almost
the full amplitude as the original sine wave.  (Draw it out on
graph paper to see what happens.)

	So, by undersampling our highly accurate waveform, we
map the frequencies which are normally unheard (if they are
really there at all) into frequencies which can be heard and which
will greatly diminish the quality of the output.

	How do we fix this?  Easy.  We generate sound samples at
the higher frequencies that do not contain the unheard higher frequency
components of the original sound, and sample this newer sample at
the correct rate.  This is exactly the way it is recommended you do
it on the Amiga, and for good reason.

	Someone recently complained that they had to go all the way
down to a 32 samples to get the high frequencies they needed.  I claim
that that 32 sample sound, if properly created from the filtered
original, would sound superior to an undersampled larger sample size.

	The final point is, because you know *each* sample will be
used, you can adjust the energy of any of the harmonics essentially
independently, and be assured that the output signal will have that
much energy.  Undersampling does not give you this ability.

	Any further comments?

	Oh, so you want to know how to create the smaller samples from
the larger ones.  I'll leave that to the experts out there.

-- 
    /-- Tomas Rokicki         ///  Box 2081  Stanford, CA  94309
   / o  Radical Eye Software ///                  (415) 326-5312
\ /  |  . . . or I       \\\///   Gig 'em, Aggies! (TAMU EE '85)
 V   |  won't get dressed \XX/ Bay area Amiga Developer's GroupE

phil@eos.UUCP (Phil Stone) (05/19/88)

In article <2845@polya.STANFORD.EDU> rokicki@polya.STANFORD.EDU (Tomas G. Rokicki) writes:
>
>	Why Sampling At 29K Is Usually Sufficient
>
>.....Lecture on sampling theory omitted.....
>
>	If you undersample such a waveform, aliasing will cause
>some strange effects.  Let us say our sampling rate that we are
>undersampling at is m (samples per second.)  According to Nyquist,
>our sampling rate should be at least twice the frequency of the
>highest component sine wave.  Any components that have a
>frequency greater than 2/m will have some portion of their energy
>aliased or mirrored down to a lower frequency.
>
>.....7 paragraphs on the evils of undersampling omitted.....

Obviously, one should not try to play frequencies higher than the Nyquist
frequency; this is what you so laboriously illustrate.  Your examples are
not very realistic, however.  Let's take a simple sine-wave synthesis
instead (not the most realistic scenario either, but so simple as to be
an example of what an audio driver *should* be able to handle).

Compute a 256-point sine wave and put it in memory (32-byte sine waves
don't cut it in my book - even a tin ear can hear the interpolation
noise in fixed, jagged steps that big).  With a fixed sample-playback
increment and a maximum rate of 29 KHz, the highest frequency you can
generate is 29000/256 = 113 Hz! - just about TWO OCTAVES below A440(!)
With this same sine wave and a variable (intergral.fractional) sampling
increment, one could generate a maximum frequency of 14 KHz!  Now, I
realize that more complex waveforms will alias at this frequency, but
at more reasonable, musical frequencies, say 1 KHz, fairly complex
waveforms can be easily generated with no Nyquist aliasing, and without
the need to spin-off shorter tables just to get higher frequencies.

My point is, it is the combination of a relatively low sampling rate
*and* a simple increment method that makes the sound driver so
inconvenient to use.  Fix one or the other if you want a high quality
and flexible sound device (I'd pick the increment as the easier to fix,
though I don't appreciate the subtleties of the Amiga's DMA).

Also, I'm all for multi-sampling, if what you are trying to do is
*re-create* a musical instrument.  Not everyone is using the Amiga as
a sampler, though.  I enjoy playing with its synthesis capabilities, and
wouldn't mind if one waveform of say, 256 bytes, could be used over five
octaves - not a tall order.  I used to be able to do *that* with a 6502.

Your postscript tosses off a reference to *making* the other octaves of
sound - this is called interpolation, a process which has earned many Ph.D's
over the last ten years.  Try interpolating 4 octaves from one sample *live*
sometime (can you say "Cray killer?")

>	Any further comments?

Yes.  Why is it that articles that start out with "I really don't know
much about this but..." always turn out to be the longest ones? :-)

		Phil Stone	(I still love the Amiga sound driver)
phil@eos.arc.nasa.gov
phil@eos.UUCP
{ uunet, hplabs, hao, ihnp4, decwrl, allegra, tektronix } ames!eos!phil

rokicki@polya.STANFORD.EDU (Tomas G. Rokicki) (05/19/88)

> Obviously, one should not try to play frequencies higher than the Nyquist
> frequency; this is what you so laboriously illustrate.  Your examples are
> not very realistic, however.  Let's take a simple sine-wave synthesis
> instead (not the most realistic scenario either, but so simple as to be
> an example of what an audio driver *should* be able to handle).

But if you try to play back a waveform that *includes* high frequencies
by undersampling, those high frequencies come back and haunt you.  That
is the point I am trying to make.

> Compute a 256-point sine wave and put it in memory (32-byte sine waves
> don't cut it in my book - even a tin ear can hear the interpolation
> noise in fixed, jagged steps that big).

As chuck said, a square wave at 14KHz should be filtered to a very
nice little sine wave; that is what the filter is for.  A square
wave at frequency f looks something like

	sin(ft+a_1) + 1/3 sin(3ft+a_2) + 1/5 sin(5ft+a_3) . . .

where the a_i's are phase shifts.  The filter should attenuate
the third and fifth etc. harmonics almost entirely, leaving you
with a very nice sine wave.

> With a fixed sample-playback
> increment and a maximum rate of 29 KHz, the highest frequency you can
> generate is 29000/256 = 113 Hz! - just about TWO OCTAVES below A440(!)

Correct, assuming you stick with that 256 sample table.

> With this same sine wave and a variable (intergral.fractional) sampling
> increment, one could generate a maximum frequency of 14 KHz!

Yes, but because of the integral.fractional nature of your incrementing,
you are guaranteed to introduce some amount of garbage into your
sound; all your peaks won't peak at the same point, etc.  Although
this effect probably won't become really bothersome until you are up
to about 1/8 of the maximum frequency or so.

> My point is, it is the combination of a relatively low sampling rate
> *and* a simple increment method that makes the sound driver so
> inconvenient to use.  Fix one or the other if you want a high quality
> and flexible sound device (I'd pick the increment as the easier to fix,
> though I don't appreciate the subtleties of the Amiga's DMA).

But the sampling rate is variable; this is what makes it a win.
I really don't understand what is so hard about having multiple tables;
if you do octave tables, you need only twice the storage of the original
table (1+1/2+1/4...~=2).

> I enjoy playing with its synthesis capabilities, and
> wouldn't mind if one waveform of say, 256 bytes, could be used over five
> octaves - not a tall order.  I used to be able to do *that* with a 6502.

Ever feed the 6502-generated signal into a spectrum analyzer?

> Your postscript tosses off a reference to *making* the other octaves of
> sound - this is called interpolation, a process which has earned many Ph.D's
> over the last ten years.  Try interpolating 4 octaves from one sample *live*
> sometime (can you say "Cray killer?")

But it only needs be done once for each sample . . . even a full FFT,
filter, and reverse FFT doesn't take long for a 256 byte sample.  Not
real time, true, but for synthesis?  Faster than you can figure parameters
for the sample.

> >	Any further comments?
> 
> Yes.  Why is it that articles that start out with "I really don't know
> much about this but..." always turn out to be the longest ones? :-)

Well, I'm trying to learn myself, so I presented what I think I
understand to be the case, and I hope to be corrected where I am
wrong.

> 		Phil Stone	(I still love the Amiga sound driver)

-- 
    /-- Tomas Rokicki         ///  Box 2081  Stanford, CA  94309
   / o  Radical Eye Software ///                  (415) 326-5312
\ /  |  . . . or I       \\\///   Gig 'em, Aggies! (TAMU EE '85)
 V   |  won't get dressed \XX/ Bay area Amiga Developer's GroupE

cmcmanis%pepper@Sun.COM (Chuck McManis) (05/19/88)

In article <734@eos.UUCP> phil@eos.UUCP (Phil Stone) writes:
>Compute a 256-point sine wave and put it in memory (32-byte sine waves
>don't cut it in my book - even a tin ear can hear the interpolation
>noise in fixed, jagged steps that big).

Phil you still don't get it do you? If take a 32 sample sine wave
and run it through a spectrum analyzer, you will find that it has
a big fundamental at the frequency of interest, and a bunch of 
higher order frequencies that are caused by the 'interpolation' noise.
The key feature is that *all* of these frequencies are above the
'nyquist' frequency. The Amigas low pass filters start cutting of 
frequencies above 7Khz and pretty much eliminate everything above
14Khz. That means that even your golden ear may have difficulty
in hearing the differences. (You will always get .4% distortion 
because that is the monotonic difference between to 'points' in 
space.) Where's my DFT when I need it. So to determine when a 32
sample waveform is 'good' enough, run it through a DFT, and look
at the first frequency component above the fundamental. Is it below
your filter point? If so you need to lengthen your sample, if not
then your sample *cannot* be made any better so why waste the bytes?
The constants in the equation are the low pass filter, the sample
frequency, and the DAC resolution. 

--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.

phil@eos.UUCP (Phil Stone) (05/19/88)

In article <53788@sun.uucp> cmcmanis@sun.UUCP (Chuck McManis) writes:
<In article <734@eos.UUCP> phil@eos.UUCP (Phil Stone) writes:
<<Compute a 256-point sine wave and put it in memory (32-byte sine waves
<<don't cut it in my book - even a tin ear can hear the interpolation
<<noise in fixed, jagged steps that big).
<
<Phil you still don't get it do you? If take a 32 sample sine wave
<and run it through a spectrum analyzer, you will find that it has
<a big fundamental at the frequency of interest, and a bunch of 
<higher order frequencies that are caused by the 'interpolation' noise.
<The key feature is that *all* of these frequencies are above the
<'nyquist' frequency. The Amigas low pass filters start cutting of 
<frequencies above 7Khz and pretty much eliminate everything above
<14Khz.....etc.
<--Chuck McManis

Wow - now the 7Khz cutoff of the filter on the Amiga sound channels is
being touted as an advantage!  The reason the cutoff is so low (and
therefore has inspired hacks and now a 500/2000 option to bypass it 
in order to get any decent high frequency response) is precisely because
of the low sampling rate.  Saying that the low sampling rate is not a
problem because the absurdly low cutoff frequency of the filter "fixes"
it, is like equating not swimming with solving the problem of shark
attacks.  Damn, I'm not saying scrap the Amiga sound driver, just
suggesting some areas where it could be improved.  I am amazed at how
many people (not all of whom even program the sound device) have reacted
with "That's not a problem!"

I've taken the original discusion to email, as I sense that its welcome
is about to wear out here.  Please feel free to write.

>uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
>These opinions are my own and no one elses, but you knew that didn't you.

			Phil Stone

phil@eos.arc.nasa.gov
phil@eos.UUCP
{ uunet, hplabs, hao, ihnp4, decwrl, allegra, tektronix } ames!eos!phil
I'm sneaking these opinions out without my employer's knowledge.

doug-merritt@cup.portal.com (05/20/88)

A number of questions have been raised about sampled sound by several
people, and the following posting is long because it answers all of
the ones that weren't answered previously, as well as correcting some
errors in statements by previous posters. If you don't care about
high quality sound generation, don't read it.

Since Tom got a mild flame for saying he was not an expert, I guess I
should say that I *am* an expert, as far as the following goes.
Trust me. 1/2 :-)

Tom Rokicki wrote:
>	Now let's sample our 10KHz sine wave at 20.2KHz.  We
>are now slightly off our frequency, and we will see a 10KHz
>tone modulated by a 200 Hz carrier; this will sound like two
>narrowly separated frequencies beating against one another.
>Ugly as sin.

The beat frequencies are the sum and difference of the sampling
frequency and the highest frequency component in the sample.
There will always be a beat frequency, the question is what to
do with it. If you have the lowpass filter turned on (always on
the the 1000, btw), then you aim to put the beat frequency above
the range of the lowpass filter (see pg 156, Fig 5-7 of the Hardware
Reference Manual). Otherwise:

There are two ways to remove aliasing of the sampling frequency.
One is to remove it via an add-on hardware filter (a 200hz notch
filter, for instance). The other is to transform the energy of the
beat frequency into random noise, which is far less annoying to the
ear, and distributes the energy across the entire spectrum, so that
any given component of the noise will be very low energy. This is
actually the *preferred* method (in absence of a low pass filter),
according to the best minds in sampling theory (not me; but I've been
to talks on the subject). It's better than a notch filter because you
don't lose the original signal at the notch frequency.

The way that you transform the alias into noise is to randomly vary
the sampling frequency (actually ideally it should follow a Poisson
distribution, but random works pretty well). In other words, instead
of sampling exactly every N microseconds, you sample every N+random()
microseconds, where 0 <= random() <= N. Thus you still get an alias/beat,
but its frequency varies randomly on each sample.

(BTW the equivalent method for graphics is to sample on a randomly
disturbed grid, and Pixar uses this method for improving ray tracing.
The human eye does the same thing: outside the fovea, the rods are
placed by a Poisson distribution, to eliminate aliasing.)

As far as I can tell from a quick glance at the Hardware Reference
Manual, this is perfectly feasible if you use Direct (Non-DMA)
output, with a maximum resolution of 280 nanoseconds. See page 161,
The Audio State Machine. As far as DMA is concerned, intuitively
you would think you're stuck with aliasing due to a fixed period,
but you *might* be able to pull the same trick if you period-modulate
one channel with random data in another. See pg 151, Table 5-5.

Tom again:
>	Oh, so you want to know how to create the smaller samples from
>the larger ones.  I'll leave that to the experts out there.

It's easy...you just do a (weighted) average down. If you go from 256
to 32 samples then you just average each 8 adjacent samples (weight of
1 since 256 = 8*32) in the source into one sample in the original.

If you wanted to go from 256 to say 49 samples, then you'd average each
5.224 samples (5.224 = 256/49) together. In other words, the first
destination sample equals the sum of the first five source samples,
plus 0.224 times the sixth source sample, divided by 5.224. This leaves
you with 0.776 worth of the sixth sample leftover, so you for the
second destination sample you take that, plus the next 4 samples,
plus 0.448 (= 5.224-4-0.776) times the fifth sample, all divided by
5.224. And continue.

The reason this works is that averaging is the time domain equivalent
of a frequency domain low pass filter.

Now as to Phil's posting:

Phil Stone then posts to critique Tom's perfectly good article,
in particular about its length and unrealistic examples. Just for
the record, Phil's article was almost as long as Tom's (66 vs 84 lines),
and used even less realistic examples, because he concentrated on
what he wanted to see added to the system, where everyone else has
been talking mostly about what *is*. People who live in glass houses...

Phil also writes:
>Compute a 256-point sine wave and put it in memory (32-byte sine waves
>don't cut it in my book - even a tin ear can hear the interpolation
>noise in fixed, jagged steps that big).  With a fixed sample-playback
>increment and a maximum rate of 29 KHz, the highest frequency you can
>generate is 29000/256 = 113 Hz! - just about TWO OCTAVES below A440(!)

That's why Tom (or was it Chuck?) talked about 32 byte samples...they
were being realistic about the current hardware, you see. Besides, what
you're talking about has to do with accuracy of reproduction of the
higher frequency harmonics need to synthesize, say, a musical instrument's
timbre, not "the highest frequency you can generate". The highest
frequency component is strictly a function of sample rate. What you're
talking about is the highest frequency *fundamental*. And 113hz doesn't
give much range, now does it?

Nonetheless I'd have to agree that it would be nice if you could
sample faster so as to raise the frequency of the highest achievable
fundamental, while still accurately reproducing timbre. But note that
you *have* the following feature:

>With this same sine wave and a variable (intergral.fractional) sampling
>increment, one could generate a maximum frequency of 14 KHz!

My guess is that you can do this already, as I discussed above.

>Your postscript tosses off a reference to *making* the other octaves of
>sound - this is called interpolation, a process which has earned many Ph.D's
>over the last ten years.  Try interpolating 4 octaves from one sample *live*
>sometime (can you say "Cray killer?")

Gross exaggeration. The papers on the topic of interpolating down
from larger to smaller waveforms occurred a lot more than 10 years ago,
and a 68000 with a math chip is perfectly capable of keeping up with the
demands. A Cray could do a full orchestra in real time.

Then Tom posts again:
>Yes, but because of the integral.fractional nature of your incrementing,
>you are guaranteed to introduce some amount of garbage into your
>sound; all your peaks won't peak at the same point, etc.  Although
>this effect probably won't become really bothersome until you are up
>to about 1/8 of the maximum frequency or so.

Quite accurate, but there will ALWAYS be some garbage of SOME sort
introduced. The integral.fractional notion does a better job of
minimizing it than if you just truncate!!! The main problem introduced
by that method is that you can no longer have a fixed length sample that
is exactly one period long, which nominally forces you to use a non-DMA
method. Except that 1) Phil was making a wish list for something new,
and you could conceivably add hardware features to restart the sample
at the appropriate point beyond the beginning, and 2) my suggestion
about using a DMA channel for period modulation could probably fix this,
too, if that in fact works.

>But it only needs be done once for each sample . . . even a full FFT,
>filter, and reverse FFT doesn't take long for a 256 byte sample.  Not
>real time, true, but for synthesis?  Faster than you can figure parameters
>for the sample.

I guess everyone is assuming you need to do a full FFT, that's why
they have problems with speed. But the type of filtering required doesn't
need a full FFT; it's just a question of averaging.

>Well, I'm trying to learn myself, so I presented what I think I
>understand to be the case, and I hope to be corrected where I am
>wrong.

I hope Phil and Chuck feels the same way, or I'm gonna get flamed! :-)

And finally, Chuck McManis writes:

> The Amigas low pass filters start cutting of 
>frequencies above 7Khz and pretty much eliminate everything above
>14Khz.

That should be 5Khz and 7Khz, respectively. See pg 154-157, Aliasing
Distortion.

>That means that even your golden ear may have difficulty
>in hearing the differences. (You will always get .4% distortion 
>because that is the monotonic difference between to 'points' in 
>space.)

Exactly. Except that again, this is where the trick of adding a
random jitter to the sampling frequency wins, because it distributes
the distortion throughout the audio range, rather than consistently
creating the same error on every tone.

Wow, made it all the way to the end, did you? Must be real interested
in the topic!
	Doug
---
      Doug Merritt        ucbvax!sun.com!cup.portal.com!doug-merritt
                      or  ucbvax!eris!doug (doug@eris.berkeley.edu)
                      or  ucbvax!unisoft!certes!doug

augi@cbmvax.UUCP (Joe Augenbraun) (05/24/88)

In article <5637@cup.portal.com> doug-merritt@cup.portal.com writes:
> A number of questions have been raised about sampled sound by several
> people, and the following posting is long because it answers all of
> the ones that weren't answered previously, as well as correcting some
> errors in statements by previous posters. If you don't care about
> high quality sound generation, don't read it.
> 
> Since Tom got a mild flame for saying he was not an expert, I guess I
> should say that I *am* an expert, as far as the following goes.
> Trust me. 1/2 :-)
> 

I've had a couple of questions that I've been meaning to ask an expert. :-)
The top waveform (let's say) is an 18 KHz signal and the lines underneath
it are the 44 khz sampling signal used by a CD player:



       .                           .                           .
   .       .                   .       .                   .       .
 .           .               .           .               .           .
.             .             .             .             .             .
               .           .               .           .               .
                 .       .                   .       .                   .
                     .                           .                          .

       |          |          |          |          |          |          |

Resulting in the following samples:

       .                                                      . 
       |                                                      |     
       |                     .          |                     |       
       |                     |          |                     |        
       |                     |          |                     |         
       |                     |          |                     |          .
       |          |          |          |          |          |          |   

Which a normal DA converter would probably recunstruct into:

       .                                                      . 
       |.                            .                       .| .   
       |  .               .  .  .       |  .               .  |   .   
       |    .           .    |          |                .    |     .  
       |      .       .      |          |     .        .      |       . 
       |        .   .        |          |        .   .        |          .
       |          |          |          |          |          |          |   

I know that in theory a sampled signal should be recontructed using some kind
of funny exponential, but I assume that this is real hard to do in real time.
So what did I do wrong here?  Is the distortion on the waveform just the
aliased sampling frequency, and its not easily recognizable because I am
drawing in the time domain?  Or is this an artifact of not reconstructing
using the exponential?

(I just used CD parameters to give me reasonable numbers.  I am not interested
in CD issues here, just the theoretical reason of what causes the distortion
that I drew.)

							joe

-- 
Joe Augenbraun                          ucp: {uunet|ihnp4|rutgers}!cbmvax!augi
System Engineering                     	arpa: cbmvax!augi@uunet.uu.net
Commodore Business Machines		Phone: 215-431-9332 

doug-merritt@cup.portal.com (05/25/88)

Joe Augenbraun writes:
>I've had a couple of questions that I've been meaning to ask an expert. :-)

Thanks for the smiley face; I was only kidding about being an expert!

>The top waveform (let's say) is an 18 KHz signal and the lines underneath
>it are the 44 khz sampling signal used by a CD player:
>[ waveforms deleted ]

The junk that you're seeing in your example is due to 26Khz and 62Khz
aliasing. With a sampling rate of A of a sine of frequency B, you'll
always get two aliased components of frequencies A-B (here 26Khz) and
A+B (62Khz).

This isn't really a problem, since even the 26Khz frequency is beyond the
range of human hearing. You could look at it as though your ear is imposing
a low pass filter on the incoming signal, with a cutoff around 20Khz. If
you filter your example waveform through a 20Khz lowpass filter, you'd
get a nice clean 18Khz signal out of it.

As I said in the other posting, the other way (besides a high sampling rate)
to get rid of unpleasant aliasing is to randomize your sampling frequency,
which distributes the aliasing into low level white noise.

>I know that in theory a sampled signal should be recontructed using some kind
>of funny exponential, but I assume that this is real hard to do in real time.

The "funny exponential" you're referring to is simply one in the domain
of complex numbers, and happens to be equivalent to sines and cosines.
The mathematics of sampling theory, Fourier transforms, etc, can be
phrased either in terms of trigonometry (sines and cosines) or of complex
analysis (complex-domain exponentials). It's exactly the same thing either way.
See Euler's theorem in an algebra book to see why.
	Doug
--
      Doug Merritt        ucbvax!sun.com!cup.portal.com!doug-merritt
                      or  ucbvax!eris!doug (doug@eris.berkeley.edu)
                      or  ucbvax!unisoft!certes!doug

phil@eos.UUCP (Phil Stone) (05/25/88)

In article <5637@cup.portal.com> doug-merritt@cup.portal.com writes:

....Doug Merritt explains some interesting ways of avoiding sampling
aliasing using random fluctuations in sampling frequency....

>Now as to Phil's posting:
>
>Phil Stone then posts to critique Tom's perfectly good article,
>in particular about its length and unrealistic examples. Just for
>the record, Phil's article was almost as long as Tom's (66 vs 84 lines),
>and used even less realistic examples, because he concentrated on
>what he wanted to see added to the system, where everyone else has
>been talking mostly about what *is*. People who live in glass houses...
 
Never thought suggestions for improvement were unwelcome here, Doug.
I made an effort to point out that I regularly program and perform live
using the Amiga sound interface, and had encountered some practical
drawbacks.  Alot of the postings on this subject have been very 
educational treatises on sampling theory that seem to come from very
informed people, but none seemed to have the perspective of actually
writing software for the sound device.  I apologized to Tom via Email
(and now publicly) for flaming his well-written article, but it came
from a sense of people approaching the issue from a purely theoretical
point of view.  How many people who have said "29 KHz is not a problem"
actually write code for the sound device (never mind try to use it live!)

Your suggestions on direct (non-DMA) access of the sound device are,
once again, wonderful from a theoretical point of view, but would drain
so much CPU time as to make the Amiga difficult to use for other tasks
in a live context.  

Allow me to summarize my position:  I *love* the Amiga sound device,
and find no parallel to it in music: low-price, flexible programmability,
built-in to a superior microcomputer system with all that implies
(peripheral access, excellent software, etc).  But to say that it has
*no problems*, even if you back this up with a ream of sampling theory,
is pure defensiveism.  Maybe we can work some of these problems out before
the next generation of machines goes into production.

P.S. I promise to try to think a little more before following up in
the future.  Sorry, Tom.

			Phil Stone
phil@eos.arc.nasa.gov
phil@eos.UUCP
{ uunet, hplabs, hao, ihnp4, decwrl, allegra, tektronix } ames!eos!phil

stever@videovax.Tek.COM (Steven E. Rice) (05/25/88)

In article <3854@cbmvax.UUCP>, Joe Augenbraun (augi@cbmvax.UUCP) asked
how a digital system would reconstruct the original signal when the
sampling rate was not very much higher than that required to give two
samples per cycle of the signal.  He included some diagrams of an
18 kHz signal sampled at 44 kHz.  He conjectured that the D/A converter
would recreate the signal as follows:

> 
>        .                                                      . 
>        |.                            .                       .| .   
>        |  .               .  .  .       |  .               .  |   .   
>        |    .           .    |          |                .    |     .  
>        |      .       .      |          |     .        .      |       . 
>        |        .   .        |          |        .   .        |          .
>        |          |          |          |          |          |          |   
 (ref) -----------------------------------------------------------------------


Ignoring overshoots, ringing, and so forth (and assuming negligible
risetimes) the reconstructed output would actually look like this:


       .----------.                                           .----------.
       |          |                     .----------.          |          |
       |          |          .----------'          |          |          |
       |          |          |                     |          |          |
       |          |          |                     |          |          |
       |          |__________|                     |----------|          |_
       |                                                                 
(ref) -----------------------------------------------------------------------


This then goes to a "reconstruction filter" (which is just a low-pass
filter), to remove the high-frequency harmonics, leaving a faithful
reproduction of the original signal.  (There is more to it.  Email if you
are interested in the gory details.)

					Steve Rice

-----------------------------------------------------------------------------
* Every knee shall bow, and every tongue confess that Jesus Christ is Lord! *
new: stever@videovax.tv.Tek.com               [phone (503) 627-1320]
old: {decvax | hplabs | ihnp4 | uw-beaver}!tektronix!videovax!stever

doug-merritt@cup.portal.com (05/26/88)

Phil Stone wrote:
>....Doug Merritt explains some interesting ways of avoiding sampling
>aliasing using random fluctuations in sampling frequency.... [...]
>Your suggestions on direct (non-DMA) access of the sound device are,
>once again, wonderful from a theoretical point of view, but would drain
>so much CPU time as to make the Amiga difficult to use for other tasks

Totally agree. Do you know whether my idea about doing the same technique
via DMA (period modulation of another channel) would work?

>But to say that it [ the Amiga audio driver ] has *no problems*, even if
>you back this up with a ream of sampling theory, is pure defensiveism. 

Once again, totally agree. Good point. Sorry to have implied otherwise.

>Never thought suggestions for improvement were unwelcome here, Doug.

Oops! Sorry! I take it back, by all means, please do continue making
suggestions for improvements, they're more than welcome!

I meant only to rebut your criticism of Tom, not to flame you!

Actually I'd say that your ideas about fractional period support sound
very useful. As I think you implied, they may require actual hardware
support in a future system rather than just a driver change.

And while we're asking for 4K by 4K by 24 screens :-) why not ask for a
44Khz sampling rate, too? Only half kidding. Some day.
	Doug
--
      Doug Merritt        ucbvax!sun.com!cup.portal.com!doug-merritt
                      or  ucbvax!eris!doug (doug@eris.berkeley.edu)
                      or  ucbvax!unisoft!certes!doug

phil@eos.UUCP (Phil Stone) (05/28/88)

Doug Merritt wrote:
>Phil Stone wrote:
>>....Doug Merritt explains some interesting ways of avoiding sampling
>>aliasing using random fluctuations in sampling frequency.... [...]
>>Your suggestions on direct (non-DMA) access of the sound device are,
>>once again, wonderful from a theoretical point of view, but would drain
>>so much CPU time as to make the Amiga difficult to use for other tasks
>
>Totally agree. Do you know whether my idea about doing the same technique
>via DMA (period modulation of another channel) would work?
>

I thought it depended on *random* fluctuations in sampling frequency - 
wouldn't this just introduce a higher-order periodicity?  BTW - sampler
hardware would also have to do this on the input end wouldn't it?
If it *could* be worked out, it might be a great way of doing
hi-fi sampling.

>And while we're asking for 4K by 4K by 24 screens :-) why not ask for a
>44Khz sampling rate, too? Only half kidding. Some day.
>      Doug Merritt        ucbvax!sun.com!cup.portal.com!doug-merritt

Yeah! Presents some interesting possibilities for direct downloading
from compact disks.  C-A has taken the first step in making a quality,
programmable sound device built in to a great computer (Mac sound? Get
serious).  It would be great to see them develop this idea further in
future products.  Can anybody speak for C-A re: their interest in 
improving the sound device?

				Phil

augi@cbmvax.UUCP (Joe Augenbraun) (05/28/88)

First of all, for those who have pointed out that my D/A convertor is
predicting the future by drawing the nice diagonal lines to the next
sample, you are right, I was not thinking clearly.

I also agree that you need a 22khz low pass filter, and that it will
make things better.  And I have gone through all of the math proving that
in an ideal system that this is adequate (although it was several years
ago when I was an undergrad).

The thing that I don't quite see is how in the real world type system
that I drew that a low pass filter would actually output the original
signal.  Generally a low pass filter will take the 'edge' off of corners
in the time domain, and there are places in my reconstructed signal
that never reach zero, but were zero in the original signal.  Those parts
will Fourrier transform into a low frequency, and the low pass won't
touch them.  I think if you would actually low-pass my sampled signal
(or actually the correct sampled signal that someone posted just a
couple messages ago) you would find that the amplitude and phase of the
output will waver.  Does anyone have a program that would let you actually
do this?

							joe

-- 
Joe Augenbraun                          ucp: {uunet|ihnp4|rutgers}!cbmvax!augi
System Engineering                     	arpa: cbmvax!augi@uunet.uu.net
Commodore Business Machines		Phone: 215-431-9332 

doug-merritt@cup.portal.com (05/30/88)

I wrote:
> Do you know whether my idea about doing the same technique
>via DMA (period modulation of another channel) would work?

Phil Stone wrote:
>I thought it depended on *random* fluctuations in sampling frequency - 
>wouldn't this just introduce a higher-order periodicity? 

I'm not sure. Ordinarily you have problems with a sample that is not
an integral multiple of its constituents, because the discontinuity where
it wraps from end to start introduces a high frequency click. I was
thinking it might not be perceptible in the case of a sample filled with
random values, especially one that was simply period-modulating the
actual output. You could certainly detect it via autocorrelation, though,
so likely your ear could, too (for some waveforms, anyway).

Intuitively I would expect that generating a random sample that is
windowed as usual (rising from a zero amplitude envelope at the beginning,
and falling to zero again at the end) would give perfectly adequate
results. That's the usual trick with getting finite samples to behave
the way that you expect the theoretical model of an infinite Fourier
series to work.

Mainly my question is whether or not the Amiga audio subsystem works
the way I'm inferring it does...I.e. is it possible to even try this
idea using DMA? It *looks* like it is.

>BTW - sampler hardware would also have to do this on the input end wouldn't it?
>If it *could* be worked out, it might be a great way of doing hi-fi sampling.

Yes, you do want it on input as well. As I recall from the driver
available for the Applied Visions Future Sound digitizer, this is quite
possible via a software mod. I wouldn't know about other sound digitizers.
	Doug
      Doug Merritt        ucbvax!sun.com!cup.portal.com!doug-merritt
                      or  ucbvax!eris!doug (doug@eris.berkeley.edu)
                      or  ucbvax!unisoft!certes!doug

cheung@vu-vlsi.Villanova.EDU (Wilson Cheung) (06/01/88)

In article <5872@cup.portal.com>, doug-merritt@cup.portal.com writes:
> >it are the 44 khz sampling signal used by a CD player:
> >[ waveforms deleted ]
> aliasing. With a sampling rate of A of a sine of frequency B, you'll
> always get two aliased components of frequencies A-B (here 26Khz) and
> A+B (62Khz).
that aliasing is occuring here since 44 Khz is more than double 18 Khz.
What he is looking at is the result of the sampling process, repeated
spectra of the original signal.  To obtain the original signal you must
pick out one of these repeated spectra.  This is done by using a low pass
filter that cuts off around 22 Khz (half the sampling rate).  

			Wilson Cheung