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

Thread: How to stop analyzing notefrequency

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

    How to stop analyzing notefrequency

    I'm using a Teensy 3.2 with the audio library and speaker and a microphone.

    For testing, if the speaker works, I send a special frequency (e.g. 1000 Hz) to the speaker and analayze the note frequency with the microphone.
    This works well.

    Now, if the speaker test is succussfully, I want to stop analyzing note frequency.

    Is there a function (e.g. notefreq.stop()) to stop or suspend AudioAnalyzeNoteFrequency?

  2. #2
    Senior Member
    Join Date
    Feb 2017
    Posts
    156
    Far from an expert here, but you could route the signal that you're sending to the AudioAnalyzeNoteFrequency through a mixer first. If you set the gain of that mixer channel to zero, the input to the AudioAnalyzeNoteFrequency will be all zeros. I believe that stops the block from processing its input data.

  3. #3
    Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    33
    That was my initial thought too, so I had a look at the code. If I'm not mistaken, it only stops processing when it stops receiving audio blocks. If that's the case, I can think of 2 more options.

    Use the new AudioConnections disconnect() member in upcoming teensyduino 1.41.
    Code:
    patchCord2notefreq.disconnect();
    Quote Originally Posted by walpre View Post
    Is there a function (e.g. notefreq.stop()) to stop or suspend AudioAnalyzeNoteFrequency?
    No there isn't but if you feel adventurous, add it yourself by adding this line to the public section in analyze_notefreq.h
    Code:
        void stop( void ) { enabled = false; }

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,745
    Quote Originally Posted by neurofun View Post
    No there isn't but if you feel adventurous, add it yourself by adding this line to the public section in analyze_notefreq.h
    Code:
        void stop( void ) { enabled = false; }
    Or even creating a dedicated audioSwitch object as demonstrated here
    Code:
    #include <Audio.h>
    
    class AudioSwitch : public AudioStream {
    public:
        AudioSwitch( void ) : AudioStream( 1, inputQueueArray ), enabled( true ) { }
        void setSwitch(bool state) { enabled = state;}
        virtual void update( void ) {
          audio_block_t *block;
          block = receiveReadOnly(); 
          if (block)
          { if (enabled ) transmit(block);
            release(block);
          }
        }
      
    private:
        bool enabled;
        audio_block_t *inputQueueArray[1];
    } audioSwitch;
    
    // GUItool: begin automatically generated code
    AudioSynthWaveformSine   sine1;          //xy=157,501
    AudioOutputAnalog        dac1;           //xy=406,499
    AudioConnection          patchCord1(sine1, audioSwitch);
    AudioConnection          patchCord2(audioSwitch, dac1);
    // GUItool: end automatically generated code
    
    void setup() {
      // put your setup code here, to run once:
      AudioMemory(4);
        
      dac1.analogReference(INTERNAL);
      sine1.amplitude(0.5);
      sine1.frequency(1000.0);
      
      pinMode(13,OUTPUT);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      static uint32_t t0;
      if(millis()>t0+5000) // select tone or led
      { audioSwitch.setSwitch((bool) digitalReadFast(13));
        digitalWriteFast(13, !digitalReadFast(13));
        t0=millis();
      }
    }

Posting Permissions

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