Using two instances of AudioAnalyzeFFT1024 at the same time

Status
Not open for further replies.

jmaag15

New member
I am fairly new to the Teensy Audio library, so I hope this is a valid question.

I would like to use two instances of the FFT with 1024 samples for two separate ADC inputs. I am working off of the FFT example in the Audio library.
Right now I have code working by using the ADC stereo input (AudioInputAnalogStereo) and two separate patch cords where each patch cord takes one of the two stereo inputs.
When I attempt to create two FFT's with 1024 samples the code does not print anything (as in the FFT.availble() for both FFT's is never true).
However, when I use the FFT with 256 samples as my second FFT the code executes and analyzes both ADC inputs.
Is there something I am missing or is this a limitation of the library? If anybody could point me to the source code I could modify to make two FFT-1024 samples work in the same sketch, it would be greatly appreciated.

I am using a Teensy 3.6 and the default ADC input pins (A3 and A2)

Thanks

Code:
// FFT Test
//
// Compute a 1024 point Fast Fourier Transform (spectrum analysis)
// on audio connected to the Left Line-In pin.  By changing code,
// a synthetic sine wave can be input instead.
//
// The first 40 (of 512) frequency analysis bins are printed to
// the Arduino Serial Monitor.  Viewing the raw data can help you
// understand how the FFT works and what results to expect when
// using the data to control LEDs, motors, or other fun things!
//
// This example code is in the public domain.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

//const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;

// Create the Audio components.  These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioInputAnalogStereo         adcInput;         // audio shield: mic or line-in
AudioAnalyzeFFT1024    myFFT;



//This works
AudioAnalyzeFFT256    myFFT1;

//This does not
//AudioAnalyzeFFT1024    myFFT1;


// Connect either the live input or synthesized sine wave
AudioConnection patchCord1(adcInput, 0, myFFT, 0);
AudioConnection patchCord2(adcInput, 1, myFFT1, 0);



void setup() {
  Serial.begin(9600);
 
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(12);

  // Configure the window algorithm to use
  
  myFFT.windowFunction(AudioWindowHanning1024);

  myFFT1.windowFunction(AudioWindowHanning1024);
  


}

void loop() {
  float n;
  int i;


    if (myFFT1.available()) {
    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
    //Serial.print("FFT: ");
    
    Serial.print('*');
    for (i=0; i<512; i++) {
      n = myFFT1.read(i);

      if (n >= 0.01) {
        
        Serial.print(n);
        Serial.print(" ");
      } else {
        Serial.print("  -  "); // don't print "0.00";
      }
    }
    Serial.println();
    }

  if (myFFT.available()) {
    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
    //Serial.print("FFT: ");
    
    Serial.print('!');
    for (i=0; i<512; i++) {
      n = myFFT.read(i);

      if (n >= 0.01) {
        Serial.print(n);
        Serial.print(" ");
      } else {
        Serial.print("  -  "); // don't print "0.00";
      }
    }
    
    
    Serial.println();
  }
}
 
If I'm reading the code correctly, at any one time the FFT1024 library can save up to 8 audio buffers without releasing them. This means that with two FFT1024 objects, you'd need to allocate at least 16 buffers with AudioMemory. Try bumping it up to 20 or more.

Pete
 
Status
Not open for further replies.
Back
Top