I wrote a wavetable oscillator that scans a file and extracts grains etc. The sound doesnt seem clear and I think it has aliasing.

What are ways to be able to play the audio file at any frequency without aliasing?

I know there should be interpolation, is there any specific type of interpolation that is better suited for recorded audio files?

Are there any other techniques to reduce this aliasing during playback?

I am unable to visualize how an audio file at any frequency, that is played back at different frequencies by jumping samples during indexing, aliases back into the waveform, and what depth of interpolation is needed.

Will scanning an audio file at higher frequencies cause aliasing due to index jumping, or is it rather precision loss? If the audio is already recorded, without aliasing, 44khz sample rate, bandwidth of 22khz and playback rate up to +6 octaves, is the aliasing added inside the real time signal?

  • $\begingroup$ "sound doesnt seem clear" is not suffcient to deduce the presence of aliasing. To be sure, just define the signal bandwith and sampling rate and playback rate. If these are not available, provide signal frequency and a more detailed explanation of sound production mechanism. At this stage of ambiguity any suggestion would be a blind speculation. $\endgroup$
    – Fat32
    Feb 16, 2016 at 18:19
  • $\begingroup$ @Fat32 - thanks, my question was also more general, will scanning an audio file at higher frequencies cause aliasing due to index jumping, or is it rather precision loss? If the audio is already recorded, without aliasing, 44khz sample rate, bandwidth of 22khz and playback rate up to +6 octaves, is the aliasing added inside the real time signal? $\endgroup$
    – some_id
    Feb 16, 2016 at 19:03

3 Answers 3


i am a little confused by the first sentence. i dunno how a wavetable oscillator scans a sound file at all. some algorithm can scan a file and extract either grains (or little "wavelets", which is a term i have misused in the past) or single-cycle wavetable "snapshots". but the wavetable oscillator starts with wavetable(s) and outputs a periodic or quasiperiodic tone.

about aliasing, if you extract wavetables from a real tone (and let's assume you have a decent pitch detector, so you know how long each period is to a precision of fraction of sample, and decent interpolation, so you you can resample the period to a, say, 256 or 1024 point wavetable) and you up-pitch the tone by more than a couple of semitones, there is a danger of aliasing unless you remove some of the higher harmonics. you can remove these higher harmonics by performing a DFT (a.k.a. FFT) on the wavetable and zero some of the bins centered around bin N/2 . then inverse DFT back to a wavetable.

actually, the number of bins centered around bin N/2 that are already zero is dependent on the degree of upsampling in the interpolation when the period in the soundfile is converted into a wavetable. consider this example: suppose the sample rate of the sound file is 44100 Hz and you have a note that is at middle C, with a fundamental at 261.6255653 Hz. this means that your period length is 168.5615 samples and a really good pitch detector can return a period value with that precision (even though i doubt it would be that accurate, precision and accuracy are different things). now a 128-sample wavetable would be insufficient to represent that waveform, or at least possibly insufficient to represent all of the harmonics of that waveform. there are conceptually 84 harmonics. a 256-samplewavetable would be sufficient to represent all of the harmonics, but let's say, for playback reasons, you resample that 168.5615 sample period to a 1024-sample wavetable, $x[n]$. that means you have a step size (the reciprocal of the sample-rate-conversion ratio) of 168.5615/1024 = 0.16461084 .

now, if you were to FFT that 1024-sample wavetable, you would possibly have non-zero bins for $X[0]$ up to $X[84]$ (and also the mirror image of $X[1024-84]$ up to $X[1023]$ . all of the bins from $X[85]$ to $X[1024-85]$ should be zero if the interpolation kernel was any good.

now, when you play that wavetable back at the same note, middle C, then the sample stride would be the reciprocal of the step size above, or 6.074934 wavetable samples per output sample (assuming the same 44100 Hz sample rate). and you would have no aliasing because all of those harmonics above the 84th harmonic are zero. but if you start pitching that note higher, your stride will be longer. if you pitched it 7 semitones higher (to G), then the stride would be 9.1021167 wavetable samples per output sample. but then your 84th harmonic gets bumped up to around 33 kHz which is above Nyquist and you will have aliasing.

so what you need to do, if you plan to pitch that note up 7 semitones (i would not pitch a sampled piano up that far, because it will sound "plinky"), you must lose all of those harmonics above the 56th harmonic. ($56 \approx 84 \times 2^{-7/12} $). you do that with the FFT, zeroing bins, and then inverse FFT

  • $\begingroup$ Thanks Robert. By scanning, I just meant reading through an array of sample values. I get this for standard tones, but I meant more for turning any arbitrary waveform into an oscillator at all frequencies up to the Nyquist limit. "then your 84th harmonic gets bumped up to around 33 kHz which is above Nyquist and you will have aliasing" How is this calculated? $\endgroup$
    – some_id
    Feb 17, 2016 at 4:08
  • 1
    $\begingroup$ G above middle C is $261.625 \times 2^{7/12}$. that's the fundamental. multiply that by 84. $\endgroup$ Feb 17, 2016 at 4:24
  • 1
    $\begingroup$ wavetable synthesis is for periodic or quasi-periodic waveforms. not for general waveforms. $\endgroup$ Feb 17, 2016 at 4:26
  • $\begingroup$ That's one thing I need to figure out, how to turn an audio sample recording into a wavetable, essentially an oscillator. $\endgroup$
    – some_id
    Feb 17, 2016 at 4:35
  • 1
    $\begingroup$ it has to be an audio sample recording (like a .wav file) of a single note. what i call a "quasi-periodic" waveform. you will need a tracking pitch detector. and what comes out will be a sequence of wavetables. you then can cull some of the wavetables if the note or tone is sufficiently periodic. $\endgroup$ Feb 17, 2016 at 4:41

You don't seem to fully understand what wavetable synthesis / scanning with higher jump lengths than the original signal was sampled with is meant to be doing:

Of course you will see aliasing; but that's the whole point!

If you want to actually resample the original signal, you would have to implement a $\frac 1M$-band lowpass filter to avoid signal from higher frequencies alias into yours.

Now, with wavetable synthesis, you normally strive to get exactly these spectral repitions, allowing you to not only generate higher frequency versions of the original signal, but also lower frequency versions of it.

For example, suppose you have a $f_{signal}=100\,\text{Hz}$ signal that you sample with $f_{sample}=16\,\text{kHz}$ for a full period, ie. you get 160 samples.

signal:100Hz f_sample:16kHz

Now, you take that wavetable and go through it with a jump size of $M=2$, and play back the resulting signal with a 16kHz DAC. Of course, your full period will now only be 5 samples long, and your signal will have a frequency of $\frac{f_{signal}}{M}=200\,\text{Hz}$. Obviously, that would also work for jump sizes like $M=4$ or $M=16$.


Now, suppose you have another wavetable, again thought to be sampled at 16kHz, and you got a 5kHz sine in there:

undersampling and aliasing

Now, $M=4$ undersampling leads to a lower frequency, instead of a higher one, due to desired aliasing.

  • 2
    $\begingroup$ Marcus, i love your little slogan: "Spending two days in a lab can easily save you up to one hour reading literature" . $\endgroup$ Feb 16, 2016 at 20:48
  • $\begingroup$ ok. this is good. another up vote and you are now above 1k. $\endgroup$
    – Fat32
    Feb 16, 2016 at 21:56
  • $\begingroup$ Thanks for the answer, how does M = 2, result in 5 samples and isn't it Fsig (100Hz) * 2? For the last example, I understand it leads to downsampling, although I thought jumping lead to a higher frequency. Is this due to preexisting aliasing inside the recorded audio, being played back? $\endgroup$
    – some_id
    Feb 17, 2016 at 3:58
  • $\begingroup$ @helium3 no, this is due to aliasing happening when you undersample the wave table, as my answer strived to explain! $\endgroup$ Feb 17, 2016 at 8:29

It appears that you might be trying to play a segment of a sound file at a wide range of varying rates by skipping or repeating samples (which can sound terrible), instead of by interpolating samples using a windowed Sinc interpolation kernel of a suitable width.

You may also have put a confusing title on your question.

  • $\begingroup$ Thanks, I will research the windowed Sinc interpolation kernel. Please edit the question title if it's confusing. $\endgroup$
    – some_id
    Feb 17, 2016 at 4:11
  • 1
    $\begingroup$ See the bibliography on my web page regarding interpolation for resampling: nicholson.com/rhn/dsp.html#3 $\endgroup$
    – hotpaw2
    Feb 17, 2016 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.