Audio system setup

Status
Not open for further replies.
All I want is to get a fourier transform able to print on the console from audio playing on my computer. What am I doing wrong? Is there something wrong with my setup? This seemed to work in the past but now it doesnt print anything
 

Attachments

  • Screen Shot 2021-09-08 at 7.41.38 PM.png
    Screen Shot 2021-09-08 at 7.41.38 PM.png
    188.1 KB · Views: 41
You need something that generates interrupts to fire up the audio chain otherwise nothing happens. Add an I2S input or output object perhaps?
 
I am also confused because i2s seems to be a hardware implementation when I just want the audio input from the usb port

Simply adding a I2S without any connection will keep the audio system running.
USB input/output is not capable of doing so. USB is a special case, as it interacts with PC following special rules.
consider this a work around solution.
you can also add an adc object.
 
So in conclusion I should attempt it again with this layout and it should suffice?
 

Attachments

  • Screen Shot 2021-09-09 at 10.46.46 AM.png
    Screen Shot 2021-09-09 at 10.46.46 AM.png
    17 KB · Views: 35
So I am still having the same error, the console continues to print "Spectrum not available". I added the i2s module but it still will not work. Here is my code. Any advice would be greatly appreciated.


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

// GUItool: begin automatically generated code
AudioInputUSB usb1; //xy=149,269
AudioInputI2S i2s1; //xy=202,375
AudioMixer4 mixer1; //xy=329,292
AudioAnalyzeFFT1024 fft1024_1; //xy=489,283
AudioConnection patchCord1(usb1, 0, mixer1, 0);
AudioConnection patchCord2(usb1, 1, mixer1, 1);
AudioConnection patchCord3(mixer1, fft1024_1);
AudioControlSGTL5000 sgtl5000_1; //xy=461,377
// GUItool: end automatically generated code


void setup(){

}

void loop() {
if (fft1024_1.available()) {
Serial.print("FFT: ");
printNumber(fft1024_1.read(0));
printNumber(fft1024_1.read(1));
printNumber(fft1024_1.read(2,3));
printNumber(fft1024_1.read(4,6));
printNumber(fft1024_1.read(7,10));
printNumber(fft1024_1.read(11,15));
printNumber(fft1024_1.read(16,22));
printNumber(fft1024_1.read(23,32));
printNumber(fft1024_1.read(33,46));
printNumber(fft1024_1.read(47,66));
printNumber(fft1024_1.read(67,93));
printNumber(fft1024_1.read(94,131));
printNumber(fft1024_1.read(132,184));
printNumber(fft1024_1.read(185,257));
printNumber(fft1024_1.read(258,359));
printNumber(fft1024_1.read(360,511));
Serial.println();
delay(1000);
}else{
Serial.println("Spectrum not available");
}
}

void printNumber(float n) {
if (n >= 0.024) {
// digitalWrite(ledPin, HIGH);
Serial.print(n, 3);
Serial.print(" ");
} else {
// digitalWrite(ledPin, LOW);
Serial.print(" - "); // don't print "0.00"
}
}
 
You always need to call AudioMemory - perhaps look at a working example program for the Audio library, there are several preloaded into the IDE
 
Use this for the setup function:
Code:
void setup()
{
  AudioMemory(12);

  // Enable the audio shield and set the output volume.
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  mixer1.gain(0,0.5);
  mixer1.gain(1,0.5);
}

If you print "Spectrum not available", it occurs thousands of times more than the FFT and you won't be able to see the FFT output. Comment it:
Code:
//Serial.println("Spectrum not available");

If you add some spaces to the output of the hyphen, it will make the output columns align so that the output is easier to read:
Code:
    Serial.print(" -    "); // don't print "0.00"

Pete
 
Thank you, this seems to work. I am also wondering how I can get the same spectrum values to show, despite the volume of my computer. Right now, when I increase the volume of spotify, the numbers get larger. I am trying to avoid this because I want the same spectrum to show regardless of the volume level. Any advice would be greatly appreciated.
 

Attachments

  • Screen Shot 2021-09-09 at 2.47.28 PM.png
    Screen Shot 2021-09-09 at 2.47.28 PM.png
    69 KB · Views: 39
A bare FFT produces an amplitude spectrum - the values are related to the power in each frequency bin, so more level
means larger values. If you want to normalize this somehow you have to decide how to normalize - by total power,
max bin level, or whatever, and scale appropriately. So you'll have to scan the bins to calculate a normalization value first.

Its common to display spectra in decibels, so you may need to calculate 20*log10(value/normalization) for each bin too.
 
Status
Not open for further replies.
Back
Top