Trying to output quadrature test waveforms, I found that waveform.phase(90) produces the correct result for sine and square waveforms but incorrectly
renders a 45 degree phase shift for triangle and ramp waveforms. T 3.2 with audio shield, Arduino 1.8.2.
Example code to reproduce this issue is attached (look at right and left audio
outputs on a scope to see the phase error).
For the time being I will fudge a factor of two when the 'problem' waveforms are selected (i.e., ask for 180 when you want 90).
Hope this helps someone,
zike
renders a 45 degree phase shift for triangle and ramp waveforms. T 3.2 with audio shield, Arduino 1.8.2.
Example code to reproduce this issue is attached (look at right and left audio
outputs on a scope to see the phase error).
For the time being I will fudge a factor of two when the 'problem' waveforms are selected (i.e., ask for 180 when you want 90).
Hope this helps someone,
zike
Code:
#include <Audio.h>
#include <SPI.h>
#include <SD.h>
#include <TeensyView.h>
#define skipButton 0 // can be any free digital pin
#define volPot 15 // hard wired to pad for pot wiper on audio adapter board
#define ledPin 13 // built-in LED
# define freq 440
AudioControlSGTL5000 sgtl5000_1;
AudioSynthWaveform waveform1;
AudioSynthWaveform waveform2;
AudioMixer4 mixerLefty; // left channel
AudioMixer4 mixerRight; // right channel
AudioOutputI2S audioOutput;
AudioConnection patchCord5(waveform1, 0, mixerLefty, 2);
AudioConnection patchCord6(waveform2, 0, mixerRight, 2);
AudioConnection patchCord9(mixerLefty, 0, audioOutput, 0);
AudioConnection patchCord10(mixerRight, 0, audioOutput, 1);
int wave_type[] = {
WAVEFORM_SINE,
WAVEFORM_TRIANGLE,
WAVEFORM_SAWTOOTH,
WAVEFORM_SQUARE
};
void setup() {
Serial.begin(9600);
Serial.println("Test phase adjust for teensy audio lib waveform generators");
Serial.println("MEZ 12/12/2017");
AudioMemory(20);
sgtl5000_1.enable();
sgtl5000_1.volume(0.1); // start at low volume
sgtl5000_1.lineOutLevel(13); // 13 makes full 3.3Vpp DAC range available
waveform1.amplitude(0); // waveform 1 off
waveform2.amplitude(0); // waveform 2 off
mixerLefty.gain(2, 1);
mixerRight.gain(2, 1);
}
void loop() {
playTestSignal();
}
void playTestSignal() {
AudioNoInterrupts();
for (int j = 0; j < sizeof(wave_type) / sizeof(wave_type[0]) ; j++) {
Serial.print("waveform ");
Serial.println(wave_type[j]);
waveform1.begin(1, freq, wave_type[j]);
waveform2.begin(1, freq, wave_type[j]);
waveform2.phase(90);
AudioInterrupts();
delay(3000);
}
}