Hi Zach,
I’ve not tried to run the Tympan Library on the Teensy audio board in a long, long time. Years and years. So, I don’t remember all the subtle issues.
The biggest issue is that the classes that control the hardware will need to be swapped out. So, instead of creating an instance of the Tympan class (ie, the thing that is “myTympan”), you’ll need to swap that out for an instance of AudioControlSGTL5000. As an example for how to create and use the SGTL5000 class, look at the Teensy Audio example for “PassThroughStereo” (https://github.com/PaulStoffregen/Audio/blob/master/examples/HardwareTesting/PassThroughStereo/PassThroughStereo.ino)
After swapping in the AudioControlSGTL5000, you’ll also need to swap out any function names attached to the Tympan class. The function names used by the Tympan class to control the Tympan hardware are not necessarily the same function names as used by the SGTL5000 class to control the SGTL5000 hardware. Your question about how to select the audio input is an excellent example of this. In this case, the function name is OK, but the arguments passed to the function need to be changed.
-
For the Tympan, there would be a line like: myTympan.inputSelect(TYMPAN_INPUT_JACK_AS_LINEIN);
.
-
But, for the SGTL5000 class (according to the PassThroughStereo example), you’d write something like: sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
You’ll need to look through your code and find every function attached to the myTympan class. Each one will need to be replaced by some sort of corresponding method in the SGTL5000 class (or, you can simply try to remove the function from your sketch).
OK, great. All of the advice above relates to trying to swap any Tympan example sketch over to run with the SGTL5000. But, you may ask, are there any concerns specifically with running AFC on the SGTL5000? The short answer is that I’ve never done it, so I don’t really know what the pitfalls are. Sorry. But I can think of one potential issue…
Specific to AFC, my Tympan examples use a highpass filter prior to the AFC algorithm receiving the audio. In my examples, I happen to employ a digital filter that is built into the Tympan hardware. In my example code, look for a line like myTympan.setHPFonADC
. I don’t believe that there is any corresponding function call for using a filter built into the SGTL5000. So, what do you do?
The purpose of this filter is to remove the low-frequency audio content from the audio stream. AFC algorithms often have difficulty dealing with low-frequency audio. So, to avoid this problem, I simply filtered it away. In my example, I used a digital filter that is built into the Tympan hardware. If you’re not using the Tympan hardware, you can use a (software) filter from the Tympan Library instead. No problem. You can steal the highpass filter stuff from the basic Tympan example “TrebleBoost”.
You’d add the Biquad filter to this section of code:
//create audio library objects for handling the audio
Tympan myTympan(TympanRev::E,audio_settings); //only tested on Tympan RevE
AudioInputI2S_F32 i2s_in(audio_settings); //Digital audio *from* the Tympan AIC.
AudioFilterBiquad_F32 hp_filt1(audio_settings); //Biquad (IIR) filter doing a highpass filter.
AudioFeedbackCancelNLMS_F32 afc(audio_settings); //adaptive feedback cancelation (AFC), NLMS method
AudioEffectGain_F32 gain1(audio_settings); //Applies digital gain to audio data.
AudioOutputI2S_F32 i2s_out(audio_settings); //Digital audio *to* the Tympan AIC. Always list last to minimize latency
AudioLoopBack_F32 afc_loopback(audio_settings); //here's how we close the loop on the AFC
You’d connect the filter in this section of code
//Make all of the audio connections
AudioConnection_F32 patchCord10(i2s_in, 0, hp_filt1, 0); //connect the left input to the highpass filter
AudioConnection_F32 patchCord15(hp_filt1, 0, afc, 0); //connect the filter to the afc
AudioConnection_F32 patchCord20(afc, 0, gain1, 0); //connect to the AFC to your audio processing
AudioConnection_F32 patchCord30(gain1, 0, i2s_out, 0); //output to the Left output
AudioConnection_F32 patchCord31(gain1, 0, i2s_out, 1); //output to the Right output
AudioConnection_F32 patchCord40(gain1, 0, afc_loopback, 0); //close the loop with the AFC
And, somewhere in the main sketch’s setup()
function, you would add this line of code to configure the filter as highpass and to set the cutoff frequency:
float cutoff_Hz = 100.0; //choose the desired filter cutoff frequency
hp_filt1.setHighpass(0, cutoff_Hz); //configure the biquad filter
Chip