How to stop analyzing notefrequency

Status
Not open for further replies.

walpre

Member
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?
 
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.
 
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();

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; }
 
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();
  }
}
 
Status
Not open for further replies.
Back
Top