processing / processing-sound-archive

Archived Sound Library for Processing
125 stars 62 forks source link

FFT analysis with small number of bands distorts the sound #39

Open shiffman opened 9 years ago

shiffman commented 9 years ago

When I run the following code, everything works as expected.

import processing.sound.*;

SoundFile song;
FFT fft;

void setup() {
  size(512, 360);
  song = new SoundFile(this, "beat.mp3");
  song.loop();
  fft = new FFT(this, 512);
  fft.input(song);
}

However, if I run the same exact code analyzing a smaller number of bands, the sound plays back distorted. I don't believe this is the expected behavior, am I mistaken?

  fft = new FFT(this, 128);  // Changing from 512 to 128.

This is Mac OS X with the library built from source today (not the current public release).

wirsing commented 9 years ago

Sorry for the late reply @shiffman. You can avoid the distortion if you set an AudioDevice specifically to the same buffersize as the FFT. I haven't figured out on how to get around this in the C++ library, it's on the list. If you check out the FFT Demo you'll see how to include the Audio Device.

shiffman commented 9 years ago

Thanks for the clarification. Would it make sense to just create the AudioDevice behind the scenes when an FFT object is made or is that too much magic and might mess up other things? I can revise my examples to include an AudioDevice.