Hello all,
First off, thanks for the audio library. It's been a lot of fun to mess around with. However, there's something that I've come across that seems off and I was wondering if someone could help me out.
Hardware: Teensy 3.2 & 3.6 + Audioshield. Issue occurs on both Teensys.
I am trying to generate a sine wave to be output on the audio shield's line out while also taking data in from the onboard microphone to a AudioRecordQueue. The problem is, the AudioRecordQueue is seeing
the sine wave that I am generating even when no speakers are attached.
Simple diagram:
AudioSynthWaveformSine ---> AudioOutputI2S // The Sine data is getting into the audiorecord queue
AudioInputI2S ---> AudioRecordQueue
Am I doing something wrong with my code or is this a known hardware limitation? The magnitude of the detected signal is significantly smaller than when it is actually playing on a speaker, but still very easily visually identifiable and I need
to eliminate it as best I can for my project.
The attached code demonstrates the issue with just a teensy + audioshield and the arduino serial monitor/plotter. Every second or so you should see the output transition to a pretty obvious sine wave and then back to noise.
If you swap the comments around line 16 (it says where) then the issue goes away, perhaps because no data is being sent to the codec.
If there's anything I'm doing wrong or can do to try to mitigate this I would appreciate any advice! Thanks.
First off, thanks for the audio library. It's been a lot of fun to mess around with. However, there's something that I've come across that seems off and I was wondering if someone could help me out.
Hardware: Teensy 3.2 & 3.6 + Audioshield. Issue occurs on both Teensys.
I am trying to generate a sine wave to be output on the audio shield's line out while also taking data in from the onboard microphone to a AudioRecordQueue. The problem is, the AudioRecordQueue is seeing
the sine wave that I am generating even when no speakers are attached.
Simple diagram:
AudioSynthWaveformSine ---> AudioOutputI2S // The Sine data is getting into the audiorecord queue
AudioInputI2S ---> AudioRecordQueue
Am I doing something wrong with my code or is this a known hardware limitation? The magnitude of the detected signal is significantly smaller than when it is actually playing on a speaker, but still very easily visually identifiable and I need
to eliminate it as best I can for my project.
The attached code demonstrates the issue with just a teensy + audioshield and the arduino serial monitor/plotter. Every second or so you should see the output transition to a pretty obvious sine wave and then back to noise.
If you swap the comments around line 16 (it says where) then the issue goes away, perhaps because no data is being sent to the codec.
If there's anything I'm doing wrong or can do to try to mitigate this I would appreciate any advice! Thanks.
Code:
// The Short, Self Contained, Compilable Example
#include <Audio.h>
AudioInputI2S audioIn;
AudioOutputI2S audioOut;
AudioSynthWaveformSine sineGenerator;
// Incoming microphone/line in data goes here.
AudioRecordQueue inputQueue;
// Sine can go here or to audio out
AudioRecordQueue sineQueue;
// Comment out the next line and uncomment the one below it
// to see the change in behavior.
AudioConnection cord1(sineGenerator, 0, audioOut, 0);
//AudioConnection cord1(sineGenerator, 0, sineQueue, 0);
AudioConnection cord2(audioIn, 0, inputQueue, 0);
// Works for MIC as well, but LINEIN is less noisy when
// nothing is attached.
const int inputSource = AUDIO_INPUT_LINEIN;
AudioControlSGTL5000 audioShield;
unsigned long prevTime = millis();
bool play = false;
void setup() {
// Fast serial
Serial.begin(115200);
delay(10);
// Yuuuge amounts of memory
AudioMemory(40);
audioShield.enable();
audioShield.inputSelect(inputSource);
audioShield.volume(0.6);
sineGenerator.amplitude(0.6);
sineGenerator.frequency(8000);
inputQueue.begin();
sineQueue.begin();
}
void loop() {
if (inputQueue.available()) {
// Process our incoming data.
int16_t* samples = inputQueue.readBuffer();
// Spits out sample values for visualization in
// serial plotter (or just look at magnitude in monitor)
for (int i = 0; i < 128; i++) {
Serial.println(samples[i]);
}
// Free our buffer at the end.
inputQueue.freeBuffer();
}
// Just to keep queue happy
if (sineQueue.available()) {
sineQueue.readBuffer();
sineQueue.freeBuffer();
}
// Turn signal on/off to make change apparent
if (millis() - prevTime > 1000) {
play = !play;
play ? sineGenerator.amplitude(0.6) : sineGenerator.amplitude(0);
prevTime = millis();
}
}