So far I was using the Fast Fourier Transform (FFT) functionality of my “Arduino Audio Tools Library” for analyzing the audio. This week I spent some time to make sure that we also support the inverse FFT properly.

The inverse FFT is generating audio samples in the time domain from the spektrum information. This functionality is executed automatically when we read the data from the fft source: The spektrum information can be set in the callback.

My implementation also supports a stride and a window function: In this case the samples are combined using the overlap add method.

The output is automatically scaled, therefore the max input values are not really important. In the example we just use 1.0.

Here is an example that generates a tone across the full spektrum:

#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioRealFFT.h" // using RealFFT

AudioInfo info(44100, 2, 16);
AudioRealFFT afft; // or AudioKissFFT
//CsvOutput<int16_t> out(Serial);
I2SStream out;
StreamCopy copier(out, afft);
int bin_idx = 0;

// provide fft frequency
void fftSelectFrequencies(AudioFFTBase &fft) {
  fft.clearBins();
  FFTBin bin{1.0f,1.0f};
  fft.setBin(bin_idx, bin);

  // increase bin: restart from first bin
  if (++bin_idx>=fft.size()) bin_idx = 0;
}

void setup() {
  AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);

  // Setup FFT
  auto tcfg = afft.defaultConfig(RX_MODE);
  tcfg.copyFrom(info);
  tcfg.length = 1024;
  tcfg.callback = fftSelectFrequencies;
  afft.begin(tcfg);

  // setup output
  auto ocfg = out.defaultConfig(TX_MODE);
  ocfg.copyFrom(info);
  out.begin(ocfg);
}

void loop() { copier.copy(); }

Dependencies

  • https://github.com/pschatzmann/arduino-audio-tools
Categories: ArduinoMachine Sound

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *