How to geat PEAK and FFT values from AudioPlaySdWav (always null)

Fuzzy

Active member
Hmm, not sure what I am doing wrong... When doing peak.available() or fft.available() its always returning 0
:(


Screen Shot 2022-07-16 at 8.14.18 AM.jpg


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

// GUItool: begin automatically generated code
AudioPlaySdWav           playWav1;     //xy=186,294
AudioMixer4              mixer1;         //xy=376,275
AudioAnalyzePeak         peak1;          //xy=563,260
AudioOutputI2S           i2s1;           //xy=572,213
AudioAnalyzeFFT256       fft256_1;       //xy=595,296
AudioConnection          patchCord1(playWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playWav1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, peak1);
AudioConnection          patchCord4(mixer1, fft256_1);
AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
AudioConnection          patchCord6(mixer1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=341,160
// GUItool: end automatically generated code

// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN    BUILTIN_SDCARD
#define SDCARD_MOSI_PIN  11  // not actually used
#define SDCARD_SCK_PIN   13  // not actually used

long loopcounter = 0;

void setup() {
  Serial.begin(9600);

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

  // Comment these out if not using the audio adaptor board.
  // This may wait forever if the SDA & SCL pins lack
  // pullup resistors
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.25);

//  SPI.setMOSI(SDCARD_MOSI_PIN);
//  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void playFile(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.println(filename);

  // Start playing the file.  This sketch continues to
  // run while the file plays.
  playWav1.play(filename);

  // A brief delay for the library read WAV info
  delay(25); 

}


void loop() {
  
  if(playWav1.isPlaying()==false){ //loop it
    playFile("LOOP2.WAV"); 
  }

  loopcounter++;
  if(loopcounter%100==0){
    Serial.print("fft available: ");Serial.println(fft256_1.available());
    Serial.print("peak available: ");Serial.println(peak1.available());
  }
  
}

OUTPUT:
Screen Shot 2022-07-16 at 8.13.41 AM.png
 
Looking at peak in the audio library

Code:
bool available(void) {
		__disable_irq();
		bool flag = new_output;
		if (flag) new_output = false;
		__enable_irq();
		return flag;
             }

you can see that the available flag gets reset when you read it. Since you a reading it over and over it clears and you mostly print out a zero for available.
Each 3ms ( approx audio library update time ) you will print out a 1.
 
Back
Top