Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Audio system setup

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    16

    Audio system setup

    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
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screen Shot 2021-09-08 at 7.41.38 PM.png 
Views:	15 
Size:	188.1 KB 
ID:	25777  

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,249
    You need something that generates interrupts to fire up the audio chain otherwise nothing happens. Add an I2S input or output object perhaps?

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    16
    where would I add it to the output if it is already connected to the fft_1024??

  4. #4
    Junior Member
    Join Date
    Dec 2020
    Posts
    16
    I am also confused because i2s seems to be a hardware implementation when I just want the audio input from the usb port

  5. #5
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,318
    Quote Originally Posted by amar1patel84 View Post
    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.

  6. #6
    Junior Member
    Join Date
    Dec 2020
    Posts
    16
    So in conclusion I should attempt it again with this layout and it should suffice?
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screen Shot 2021-09-09 at 10.46.46 AM.png 
Views:	14 
Size:	17.0 KB 
ID:	25782  

  7. #7
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,318
    yes, this is one option

  8. #8
    Junior Member
    Join Date
    Dec 2020
    Posts
    16
    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"
    }
    }

  9. #9
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,249
    You always need to call AudioMemory - perhaps look at a working example program for the Audio library, there are several preloaded into the IDE

  10. #10
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,750
    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

  11. #11
    Junior Member
    Join Date
    Dec 2020
    Posts
    16
    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.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screen Shot 2021-09-09 at 2.47.28 PM.png 
Views:	13 
Size:	69.0 KB 
ID:	25786  

  12. #12
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,249
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •