Hi all,
I have an odd problem regarding a strange 344Hz buzz which I'm hearing from the teensy audio shield. My setup is as follows:
electret mic (biased w/ 3.3V and 4.7k resistor)-->100uF cap --> LM386 amplifier --> Audio Shield Line-in L
The strange thing is that I only hear this buzzing when I'm adjusting volume each time a 128-sample block is available (see code below). If I comment out the lines
Then the buzzing goes away. My hunch is that this buzzing is caused by some kind "blip" every time the sgtl5000.volume() command is called (1/44100*128=2.9us --> 1/2.9us=344Hz).
What's even stranger is I don't have any of these issues when I use the teensy mic-input.
In my larger project I use audioRecordQueue and audioPlayQueue to do some other effects that I won't get into here.
Has anyone run into an issue like this before? I can't figure out the relationship between headphone volume adjustments and line-in buzzing.
I have an odd problem regarding a strange 344Hz buzz which I'm hearing from the teensy audio shield. My setup is as follows:
electret mic (biased w/ 3.3V and 4.7k resistor)-->100uF cap --> LM386 amplifier --> Audio Shield Line-in L
The strange thing is that I only hear this buzzing when I'm adjusting volume each time a 128-sample block is available (see code below). If I comment out the lines
Code:
int knob2 = analogRead(A2);
float vol = knob2 / 1023.0;
if(vol<0.01) vol=0.0; //threshold filtering out the noise floor of potentiometer measurement
sgtl5000.volume(vol);
What's even stranger is I don't have any of these issues when I use the teensy mic-input.
In my larger project I use audioRecordQueue and audioPlayQueue to do some other effects that I won't get into here.
Has anyone run into an issue like this before? I can't figure out the relationship between headphone volume adjustments and line-in buzzing.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <SerialFlash.h>
#include <Bounce.h>
const int baudRate = 115200;
const uint32_t blockSize=AUDIO_BLOCK_SAMPLES;
//Create pointers to be assigned to input and output buffers, create input/output arrays for LMS filter
//Teensy audio library works on int16_t (equivalent in size with q15 data), the LMS filter is running on f32 data
int16_t * ptr_in;
int16_t * ptr_out;
//Instantiate audio library objects, make connections
AudioInputI2S i2s_in; //Audio input
AudioOutputI2S i2s_out; //Audio output
AudioRecordQueue Q_1_rec; //Object for storing audio blocks and accessing as arrays
AudioPlayQueue Q_1_play; //object to write array to for output
AudioConnection patchcord1(i2s_in,0,Q_1_rec,0);
AudioConnection patchcord2(Q_1_play,0,i2s_out,0);
AudioConnection patchcord3(Q_1_play,0,i2s_out,1);
AudioControlSGTL5000 sgtl5000;
//Define input to system. Uncomment the input you want to use
//const int input = AUDIO_INPUT_MIC;
const int input = AUDIO_INPUT_LINEIN;
void setup() {
pinMode(13,OUTPUT); //for onboard indicator LED
Serial.begin(baudRate);
AudioMemory(10);
//enable audio shield, select input/mic gain, and initialize output level
sgtl5000.enable();
if(input == AUDIO_INPUT_MIC){
sgtl5000.inputSelect(AUDIO_INPUT_MIC);
sgtl5000.micGain(30);
sgtl5000.volume(0.2);
Serial.print("Teensy Audio Shield mic input selected \n");
}
else{
sgtl5000.inputSelect(AUDIO_INPUT_LINEIN);
sgtl5000.lineInLevel(7);
sgtl5000.volume(0.5);
Serial.print("Teensy Audio Shield line-in input selected \n");
}
//Begin the record audio queue
Q_1_rec.begin();
/*
Serial.print("AUDIO_BLOCK_SAMPLES = ");
Serial.print(AUDIO_BLOCK_SAMPLES);
Serial.print("\n");
Serial.print("Setup Complete \n");
*/
digitalWrite(13,HIGH); //onboard LED indicator to show setup sucessful
}
void loop() {
//check to see if there is a queue block available
if(Q_1_rec.available()){
//Set the output volume level by reading potentiometer
int knob2 = analogRead(A2);
float vol = knob2 / 1023.0;
if(vol<0.01) vol=0.0; //threshold filtering out the noise floor of potentiometer measurement
sgtl5000.volume(vol);
//copy addresses of 128 samples in queue block to ptr_1
ptr_in = Q_1_rec.readBuffer();
//get pointer to output buffer "empty" array
ptr_out = Q_1_play.getBuffer();
for(uint8_t i=0;i<blockSize;i++){
ptr_out[i]=ptr_in[i];
}
//Output the buffer to be played
Q_1_rec.freeBuffer();
Q_1_play.playBuffer();
}
}