Problems with AudioSynthWaveform at higher frequencies

Status
Not open for further replies.

beldenfox

New member
I'm using AudioSynthWaveform on a Teensy 3.2 to generate square wave tones based on MIDI notes. When playing an ascending scale the audible tone sometimes goes down even though the frequency I'm passing to begin() goes up but this is only true at the upper end of the MIDI note range. Any idea what's going on? Using Arduino 1.8.8 on an iMac with Teensyduino 1.45. Sorry I don't have information on how the speaker is hooked up, that's the hardware guy's department. Can provide details if necessary.

Code:
#include <Audio.h>

AudioOutputAnalog   audio_output;
AudioSynthWaveform  tone_player;
AudioConnection     fc(tone_player, 0, audio_output, 0);

void note_on(byte note)
{
  float f = pow(2.0f, (note - 69) / 12.f) * 440.0f;
  tone_player.begin(0.2, f, WAVEFORM_SQUARE);
}

void note_off()
{
  tone_player.amplitude(0);
  tone_player.frequency(0);
}

void setup()   {
  AudioMemory(10);
  audio_output.analogReference(INTERNAL);

  for (byte note = 100; note <= 127; ++note)
  {
    note_on(note);
    delay(700);
    note_off();
    delay(300);
  }
}

void loop()
{
}
 
Status
Not open for further replies.
Back
Top