Problem with Teensy Audio library without the audio shield

Status
Not open for further replies.

dude8604

Member
I'm trying to use the audio library to do a FFT on the input signal. I'm following the example, except I modified it to read from the ADC instead of the audio shied and also to print all the bins instead of just 40, but it's not working. The AudioAnalyzeFFT256's available() function never returns TRUE. What am I doing wrong? Here's my code:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

// Create the Audio components.  These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioInputAnalog          audioInput(A2);    
AudioAnalyzeFFT256    myFFT;

// Connect either the live input or synthesized sine wave
AudioConnection patchCord1(audioInput, myFFT);

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

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

void loop() {
  float n;
  int i;
  if (myFFT.available()) {

    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
//    Serial.print("FFT: ");
    for (i=0; i<127; i++) {
      n = myFFT.read(i);
      //if (n >= 0.01) {
        Serial.print(n);
        Serial.print(" ");
      //} else {
      //  Serial.print("  -  "); // don't print "0.00"
      //}
    }
    Serial.println();
  }
}

Thanks.
 
I'm running it on a board here. Seems to work fine.

Perhaps you've got an older version of the library?

screen.png
 
I have the one that comes with Teensyduino 1.20. Is that the latest version?

Also, I noticed I didn't put a Serial.begin(). What's the default baud rate?
 
Yup, the one in 1.20 is the latest.

Serial.begin() isn't needed on Teensy, and even if you do use it, the baud rate is ignored (USB full speed 12 Mbit/sec is always used).

Perhaps you have some other device selected in Tools > Serial Port, so when you open the serial monitor, you're seeing "nothing" from a non-Teensy device, while the Teensy is trying to send all those numbers to you?
 
I'm sure it was the right COM port, I had debugging messages which came through. Anything else you can think of? Is it possible my Teensy is damaged?
 
It is working on a Teensy here. I tested only with the input floating, but it's definitely printing those numbers, as you can see in the screenshot. I have no idea why it's not working for you.

Maybe you could try programming the blink example (File > Examples > 01.Basics > Blink) or other simple examples to test if your Teensy is still working properly?
 
I finally was able to make it work. The problem was that I was using the 72Mhz clock speed, but when I lowered it to 48Mhz it started working. Is there some reason that shouldn't work or is that a limitation of the audio library?

I also had one other question. Is there any way to use the audio library on non-audio frequencies and/or to focus on a smaller range of frequencies in more detail? If not, do you have any suggestions on how to do that on a Teensy? Thanks.
 
Status
Not open for further replies.
Back
Top