Filters with FFT = no output

Status
Not open for further replies.

insane

Active member
It's very nice working with the Audio System Design Tool, but I've run into a problem that stumps me. I'm trying to combine a couple of concepts from the Audio Workshop Tutorial that don't seem to work--well, I'm sure there's way; I just can't figure it out!

So I'm using a Teensy 3.2 with an Audio Shield and the 1.6.8 Arduino IDE.

The objective is to select either an audio file from the SD card (on the shield), play a guitar clip from RAM, or play a generated tone--this is pretty-much straight from the Tutorial. Additionally, I want to patch the output to FFT, but first pass it through low-pass and high-pass filters. Each of these is again separately borrowed from the workshop Tutorial. My twist is that besides sending the FFT data to the serial monitor, I'm lighting up an Adafruit NeoPixel strip with it. All this works well, separately.

The problem is that when I put it all together, there is no sound output. However, if I comment out the patchCord to the FFT object in the Design Tool, then sound plays--but obviously without FFT data.

Here's the source code and Design Tool image--should look pretty familiar:


DesignTool.jpg


Code:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN            3
#define NUMPIXELS      30

#include "AudioSampleGuitar.h"
#include <Bounce.h>

Bounce button0 = Bounce(0, 15);
Bounce button1 = Bounce(1, 15);
Bounce button2 = Bounce(2, 15);

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

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

// GUItool: begin automatically generated code
AudioPlayMemory          playMem1;       //xy=87.19999694824219,134.1999969482422
AudioSynthWaveform       waveform1;      //xy=91.19999694824219,194.1999969482422
AudioPlaySdWav           playSdWav1;     //xy=94.19999694824219,69.19999694824219
AudioMixer4              mixer1;         //xy=303.20001220703125,50.19999694824219
AudioFilterStateVariable filter1;        //xy=389.20001220703125,139.1999969482422
AudioMixer4              mixer2;         //xy=504.20001220703125,234.1999969482422
AudioFilterStateVariable filter2;        //xy=522.2000122070312,138.1999969482422
AudioAnalyzeFFT1024      fft1024_1;      //xy=714.2000122070312,217.1999969482422
AudioOutputI2S           i2s1;           //xy=717.2000122070312,124.19999694824219
AudioConnection          patchCord1(playMem1, 0, mixer1, 2);
AudioConnection          patchCord2(waveform1, 0, mixer1, 3);
AudioConnection          patchCord3(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord4(playSdWav1, 1, mixer1, 1);
AudioConnection          patchCord5(mixer1, 0, filter1, 0);
AudioConnection          patchCord6(filter1, 2, filter2, 0);
AudioConnection          patchCord7(mixer2, 0, i2s1, 0);
AudioConnection          patchCord8(mixer2, 0, i2s1, 1);
AudioConnection          patchCord9(mixer2, fft1024_1);     // <--- 
AudioConnection          patchCord10(filter2, 0, mixer2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=264.20001220703125,272.20001220703125
// GUItool: end automatically generated code
///////////////////////////////////


void setup() {
  Serial.begin(9600);
  pixels.begin(); // This initializes the NeoPixel library.
  pixels.show();  // Initialize all pixels to 'off'

  AudioMemory(10);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);

  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  mixer1.gain(0, 0.5);    // soundwave L
  mixer1.gain(1, 0.5);    // soundwave R
  mixer1.gain(2, 0.0);    // memory
  mixer1.gain(3, 0.0);    // waveform
  mixer2.gain(0, 1.0);    // filtered audio
  mixer2.gain(1, 0.0);
  mixer2.gain(2, 0.0);
  mixer2.gain(3, 0.0);
  filter1.frequency(80);
  filter2.frequency(9000);
  delay(1000);
  playSdWav1.play("SDTEST1.WAV");
}

int fileNumber = 0;
const char * filenames[4] = {
  "SDTEST1.WAV", "SDTEST2.WAV", "SDTEST3.WAV", "SDTEST4.WAV",
};

int noteNumber = 0;
const float noteFrequency[49] = {
440.00,   //  A
466.16,   //  A#
493.88,   //  B
523.25,   //  C
554.37,   //  C#
587.33,   //  D
622.25,   //  D#
659.26,   //  E
698.46,   //  F
739.99,   //  F#
783.99,   //  G
830.61,   //  G#
};


void loop() {
  if (fft1024_1.available()) {
    Serial.print("FFT: ");
    for (int i=0; i<30; i++) {
      float n = fft1024_1.read(i);
      printNumber(n);
      pixels.setPixelColor(i, pixels.Color(0, n*1000 ,0));
    }
    pixels.show(); // This sends the updated pixel color to the hardware.
    Serial.println();
  }
  
  button0.update();
  button1.update();
  button2.update();

  // Left button starts playing a new song
  if (button0.fallingEdge()) {
    mixer1.gain(2, 0.0);
    mixer1.gain(3, 0.0);
    fileNumber = fileNumber + 1;
    if (fileNumber >= 10) fileNumber = 0;
    playMem1.stop();
    playSdWav1.play(filenames[fileNumber]);
    mixer1.gain(0, 0.5);
    mixer1.gain(1, 0.5);
  }

  // Middle button plays Guitar sample
  if (button1.fallingEdge()) {
    mixer1.gain(0, 0.0);
    mixer1.gain(1, 0.0);
    mixer1.gain(3, 0.0);
    playSdWav1.stop();
    playMem1.play(AudioSampleGuitar);
    mixer1.gain(2, 1.0);
  }

  // Right button plays a pure sine wave tone
  if (button2.fallingEdge()) {
    mixer1.gain(0, 0.0);
    mixer1.gain(1, 0.0);
    mixer1.gain(2, 0.0);
    playSdWav1.stop();
    playMem1.stop();
    waveform1.begin(1.0, noteFrequency[noteNumber], WAVEFORM_SINE);
    noteNumber = noteNumber + 1;
    if (noteNumber >= 49) noteNumber = 0;
    mixer1.gain(3, 1.0);
  }
  if (button2.risingEdge()) {
    waveform1.amplitude(0);
  }

  // read the knob and adjust the filter frequency
  int knobL = analogRead(A2);
  int knobH = analogRead(A3);
  // quick and dirty equation for exp scale frequency adjust
  float freqL =  expf((float)knobL / 150.0) * 10.0 + 80.0;
  float freqH =  expf((float)knobH / 150.0) * 10.0 + 80.0;
  filter1.frequency(freqL);
  filter2.frequency(freqH);
  Serial.print("low frequency limit  = ");
  Serial.println(freqL);
  Serial.print("high frequency limit = ");
  Serial.println(freqH);
  delay(200);
}

void printNumber(float n) {
  
  if (n >= 0.004) {
    Serial.print(n, 3);
    Serial.print(" ");
  } else {
    Serial.print("   -  "); // don't print "0.00"
  }
}
 
hmm.... didn't think of that

tried to increase
AudioMemory(10);

?

I did not even think to try that; kinda makes sense, though. Have you had some sort of experience to the effect, or is it an educated guess?

I'll try it on Monday when I get back to the lab. Thanks.

-Michael (insane)
 
I did not even think to try that; kinda makes sense, though. Have you had some sort of experience to the effect, or is it an educated guess?

I'll try it on Monday when I get back to the lab. Thanks.

-Michael (insane)

Wow...it worked. I bumped AudioMemory from 10 to 20 and it worked. Thanks, man.
 
Status
Not open for further replies.
Back
Top