Hi everyone,
I'm doing an audio project on Teensy 4.0 integrating with Audio Shield. Two sensors are connected on the Audio Shield with one emitting signals and the other receiving them.
For the emitter, I use "waveform" from audio lib to generate signal at a specific frequency, and I use "queue" to record data for the receiver. I tend to record the received data and use them to plot FFT spectrogram, in order to see what their FFT looks like.
The problem is I could always "collect " the emitting signals, even when both of the sensors are disconnected. I mean no input or output to the audio shield, but still I could always see the corresponding peak on FFT at the frequency that I set for the emitting signal. Seems like "queue" would always capture some info from "waveform", even when the audio shield connects to nothing. What I expect here is I should only record signals that emitted by the emitter, and received from the other sensor (receiver).
Is Teeny able to emit and receive signals simultaneously, just like what I've been doing here? Or it's the problem with the code?
Here is the code for Teensy:
I also attached the python files for saving data ("read_serial") and for plotting FFT ("plot_fft"), in case you'd like to play around!
Please leave message if you got any idea!
Thank you!
I'm doing an audio project on Teensy 4.0 integrating with Audio Shield. Two sensors are connected on the Audio Shield with one emitting signals and the other receiving them.
For the emitter, I use "waveform" from audio lib to generate signal at a specific frequency, and I use "queue" to record data for the receiver. I tend to record the received data and use them to plot FFT spectrogram, in order to see what their FFT looks like.
The problem is I could always "collect " the emitting signals, even when both of the sensors are disconnected. I mean no input or output to the audio shield, but still I could always see the corresponding peak on FFT at the frequency that I set for the emitting signal. Seems like "queue" would always capture some info from "waveform", even when the audio shield connects to nothing. What I expect here is I should only record signals that emitted by the emitter, and received from the other sensor (receiver).
Is Teeny able to emit and receive signals simultaneously, just like what I've been doing here? Or it's the problem with the code?
Here is the code for Teensy:
Code:
#include <Audio.h>
#include <SerialFlash.h>
// Setup for receiver
AudioInputI2S i2s1;
AudioRecordQueue queue; // Use a queue object to record data into the buffer
AudioConnection patchCord1(i2s1, queue);
AudioControlSGTL5000 sgtl5000_1;
// Setup for speaker
AudioSynthWaveform waveform;
AudioOutputI2S i2s2;
AudioConnection patchCord2(waveform, 0, i2s2, 0); // L LINE_OUT
const int myInput = AUDIO_INPUT_LINEIN;
void setup() {
Serial.begin(9600);
AudioMemory(60);
sgtl5000_1.enable();
sgtl5000_1.inputSelect(myInput);
sgtl5000_1.volume(1);
sgtl5000_1.lineInLevel(15); // 0-15, default 5, set input sensitivity
sgtl5000_1.lineOutLevel(13); // 13-31, default 29, set output voltage
waveform.begin(1, 10000, WAVEFORM_SINE); // Set amplitude and frequency for speaker
queue.begin();
}
void loop() {
if (queue.available() > 0) {
int16_t *buffer = queue.readBuffer();
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
Serial.print(buffer[i]);
if (i < AUDIO_BLOCK_SAMPLES - 1) Serial.print(",");
}
Serial.println();
queue.freeBuffer();
}
}
Please leave message if you got any idea!
Thank you!