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

Thread: Measuring microphone amplitude

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    1

    Measuring microphone amplitude

    Hi,

    I'm very new to teensy so this is probably a simple question but I'm still a bit stumped after searching the forums and tutorials.

    I am trying to print out a real time amplitude value of the incoming microphone signal. I have modified the microphone test example to do this:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=149,228
    AudioAnalyzePeak         peak1;          //xy=407,266
    AudioOutputI2S           i2s2;           //xy=447,200
    AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
    AudioConnection          patchCord2(i2s1, 0, i2s2, 1);
    AudioConnection          patchCord3(i2s1, 0, peak1, 0);
    AudioControlSGTL5000     sgtl5000_1;     //xy=339,338
    // GUItool: end automatically generated code
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(8);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
      sgtl5000_1.micGain(36);
      delay(1000);
    }
    
    void loop() {
      Serial.println(peak1.read());
    }
    The only output it get is 1.0 with an occasional 0.0. This remains unchanged even if I unplug the microphone. The microphone seems to be fine as I can hear the signal.

    I am using a Teensy 3.2 with the audio shield.

    Thanks.

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,379
    Quote Originally Posted by Pseudoabdul View Post
    Hi,

    I'm very new to teensy so this is probably a simple question but I'm still a bit stumped after searching the forums and tutorials.

    I am trying to print out a real time amplitude value of the incoming microphone signal. I have modified the microphone test example to do this:

    ......


    The only output it get is 1.0 with an occasional 0.0. This remains unchanged even if I unplug the microphone. The microphone seems to be fine as I can hear the signal.

    I am using a Teensy 3.2 with the audio shield.

    Thanks.
    Before you go on with trying to understand the (non)results, you should slow down the printout. The teensy is far too fast, so that
    Code:
    void loop() {
      Serial.println(peak1.read());
    }
    will overwhelm the PC, risking further to get a non-responsive USB connection to the teensy

    To start I would do a peak reading say 10 times per second , so you can read the value on the screen by inserting a delay(100);
    Code:
    void loop() {
      Serial.println(peak1.read());
      delay(100);
    }
    later on you you can always shorten the delay.
    However, going below 3 ms , is not useful as audio data are processed in chunks of about 3 ms

  3. #3
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,065
    FWIW, your sketch works for me with delay(500); in loop(), i get values from 0.02 to 0.88 for various noises into mic

    Try delay(5) and multiply peak by 100 and feed into Serial Plotter in IDE

    i am using the Teensy microphone attached to the audio adaptor
    Last edited by manitou; 09-14-2017 at 12:50 PM.

Posting Permissions

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