0

I'm trying to write a custom xaudio2 effect that involves a fourier transform. However, the number of samples given to the process method each call is not a power of 2 (a precondition of the fourier transform implementation I have).

Is there a way to force power of 2 sized samples? Is there a technique to allow working with non power of 2 sizes?

Craig Gidney
  • 17,763
  • 5
  • 68
  • 136

2 Answers2

1

If your implementation requires that you have a power of 2 sample size, then you can pad the sample to force it to accept. Zero padding seems to be the easiest/most straight forward.

Here is an article that explains another way to do it:

The Chirp z-Transform Algorithm and Its Application

NominSim
  • 8,447
  • 3
  • 28
  • 38
  • That won't introduce artefacts in the output of the FFT that ultimately cause 'bad' audio after making changes in frequency space and transforming back? – Craig Gidney Jul 23 '12 at 20:09
  • Any padding is going to introduce some noise into the FFT. If you only have an implementation that accepts power of 2 sample size though I don't know of any other option. – NominSim Jul 23 '12 at 20:16
  • @Strilanc : If you plan on making changes in the frequency domain, then you may have to zero-pad. It's part of the overlap-add/save fast convolution filtering process. – hotpaw2 Oct 20 '12 at 14:36
1

Don't send samples to the FFT every call that you are given samples. Buffer (save) them up till you have at least a power-of-2 samples or more and then process the power-of-2 number of samples from your intermediate buffer. Rinse and repeat.

Also, newer FFTs will often allow sizes with prime factors larger than 2.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • This the stop-gap solution I've been using. It introduces a bit of delay on the audio, though, due to the queuing. If I naively chained many effects together that would add up. – Craig Gidney Jul 24 '12 at 01:32
  • You might try testing using a smaller power-of-2 to see if that works and helps with latency. – hotpaw2 Jul 24 '12 at 01:39