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

Thread: I2S input - Analog output - Note frequency analyzer

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    12

    I2S input - Analog output - Note frequency analyzer

    I have an I2S microphone as input and an analog output to a amplifier with connected speaker and a Teensy 3.2. With the speaker I generate a sine wave frequency and record it with the microphone.

    I tested this in a test environment (without other features of my project) and it works well.

    This ist the code of this test environment:
    Code:
    #include "TeensyThreads.h"
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=177,216
    //AudioInputAnalog            i2s1;           //xy=177,216
    AudioSynthWaveformSineHires sine_hires1;    //xy=183,212
    AudioEffectEnvelope      envelope1;      //xy=405,206
    AudioMixer4              mixer1;         //xy=637,227
    AudioOutputAnalog        dac1;           //xy=889,228
    AudioAnalyzeNoteFrequency notefreq1;      //xy=418,374
    AudioAnalyzeRMS          rms1;
    AudioConnection          patchCord1(i2s1, 0, notefreq1, 0);
    AudioConnection          patchCord5(i2s1, 0, rms1, 0);
    AudioConnection          patchCord2(sine_hires1, 0, envelope1, 0);
    AudioConnection          patchCord3(envelope1, 0, mixer1, 0);
    AudioConnection          patchCord4(mixer1, dac1);
    // GUItool: end automatically generated code
    
    void play_tone(float tone_frequency) {
      AudioNoInterrupts();
      sine_hires1.amplitude(1.0);
      sine_hires1.frequency(tone_frequency);
    
      // define envelope
      envelope1.attack(75);
      envelope1.hold(250);
      envelope1.decay(10);
      envelope1.sustain(0);
      envelope1.release(50);
    
      mixer1.gain(0, 0.3);
    
      envelope1.noteOn();
      AudioInterrupts();
    }
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(30);
      dac1.analogReference(EXTERNAL);
      notefreq1.begin(.15);
      delay(100);
    }
    float note, prob;
    elapsedMillis fps;
    void loop() {
      if (fps > 2000) {
        fps = 0;
        play_tone(10);
      }
     if (notefreq1.available()) {
            note = notefreq1.read();
            //prob = notefreq1.probability();
            Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
      }
      if (rms1.available()) {
            float volume_level = rms1.read() * 100.0;
            //Serial.printf("Volume level: %3.2f", volume_level);
            //Serial.print("Volume level: ");
            //Serial.println(volume_level);
      }
     delay(5);
    }
    If I include the functionality in my project, the "notefreq1.available()" always return false.
    Here is the Audio Configuration:

    Code:
    AudioInputI2S            i2s1;           //xy=145,489
    //AudioInputAnalog            i2s1;           //xy=145,489
    AudioSynthWaveformSineHires sine_hires4;    //xy=156,316
    AudioSynthWaveformSineHires sine_hires3;    //xy=157,240
    AudioSynthWaveformSineHires sine_hires2;    //xy=159,169
    AudioSynthWaveformSineHires sine_hires1;    //xy=160,99
    AudioEffectEnvelope      envelope4;      //xy=373,319
    AudioEffectEnvelope      envelope1;      //xy=382,100
    AudioEffectEnvelope      envelope2;      //xy=383,173
    AudioEffectEnvelope      envelope3;      //xy=384,243
    AudioMixer4              mixer1;         //xy=649,203
    AudioOutputAnalog        dac1;           //xy=888,200
    AudioAnalyzeNoteFrequency notefreq1;      //xy=369,598
    AudioAnalyzeRMS          rms1;           //xy=361,529
    AudioConnection          patchCord1(i2s1, 0, notefreq1, 0);
    AudioConnection          patchCord2(i2s1, 0, rms1, 0);
    AudioConnection          patchCord3(sine_hires4, 0, envelope4, 0);
    AudioConnection          patchCord4(sine_hires3, 0, envelope3, 0);
    AudioConnection          patchCord5(sine_hires2, 0, envelope2, 0);
    AudioConnection          patchCord6(sine_hires1, 0, envelope1, 0);
    AudioConnection          patchCord7(envelope4, 0, mixer1, 3);
    AudioConnection          patchCord8(envelope1, 0, mixer1, 0);
    AudioConnection          patchCord9(envelope2, 0, mixer1, 1);
    AudioConnection          patchCord10(envelope3, 0, mixer1, 2);
    AudioConnection          patchCord11(mixer1, dac1);
    I also have a analog microphone. If I use this microphone my project code works well.

    Does anyone have an idea or a hint what I could do?
    Last edited by Theremingenieur; 01-10-2018 at 04:27 PM.

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,636
    For the I2S input you need the sgtl500 control
    (check the audio/recorder example for typical commands (enable, setline etc)

  3. #3
    Junior Member
    Join Date
    Dec 2017
    Posts
    12
    In the code example - see above - that I use in my test environment I don't have a sgtl500 control and it works well.

    Also I don't use an audio shield!?

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,636
    Quote Originally Posted by walpre View Post
    Also I don't use an audio shield!?
    Sorry, I read but forgot about it.

  5. #5
    Junior Member
    Join Date
    Dec 2017
    Posts
    12
    Found the solution: In my project the I2S input pin 13 was set to output.

  6. #6
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,636
    Quote Originally Posted by walpre View Post
    Found the solution: In my project the I2S input pin 13 was set to output.
    which can not be seen in the code you resented.

  7. #7
    Junior Member
    Join Date
    Dec 2017
    Posts
    12
    No, you can't. The code that I sent was the test environment code. The project code is much larger, about 10 files.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,032
    Glad you solved it. But next time, please try to post which actually shows the problem. Code that works and only a fragment associated with the problem doesn't give us enough to help you. It only wastes everyone's valuable time.

Posting Permissions

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