Can Tympan software work on Teensy 4.1?

I’m trying to figure out another way to run the Tympan software since the board is out of stock. The Rev F is compatible with the Teensy 4.1, so does that mean we could just get a Teensy 4.1 with an Audio Shield and run Tympan on that?

What software changes would that require? Just changing pin numbers, or something else?

Thanks for any advice you have

Hi Soarise!

I’m sorry that the hardware is out of stock.

The Tympan is a Teensy 4.1 inside, so running on Teensy 4.1 is no problem at all.

Running with the Teensy Audio Shield instead of the Tympan audio hardware…that’s is a little more difficult, but should work fine (though I haven’t done it myself in many years).

There are two basic approaches to getting started: (1) start from an example program from the Teensy Audio library, or (2) start from an example program from the Tympan Library.

If your main goal is to mainly use Tympan’s audio processing algorithms, I would start from one of the Tympan Library examples and adapt it for the Teensy audio hardware…

STARTING FROM TYMPAN LIBRARY EXAMPLES

There are many Tympan Library examples that you can build from. To use them without the Tympan hardware, you’ll need to remove the references to the Tympan audio hardware and, in some cases, replace them with references to the Teensy Audio hardware.

  • Find the line that is like Tympan myTympan(TympanRev::F); and replace it with the standard Teensy line AudioControlSGTL5000 sgtl5000;
  • Any time the Tympan code uses the myTympan to set the system volume or whatever, you’ll have to comment it out or you’ll have to replace it with corresponding call to sgtl5000.

If this is the route that you choose to try (it’s the one that I would try), you cannot hurt anything simply by trying it out. Have no fear! Dive in!

STARTING FROM TEENSY AUDIO EXAMPLES

Alternatively, if you need to use deeper features of the Teensy audio hardware (like the SD card), you should probably start from a Teensy Audio library example. In this case, the main challenge is inserting references to the Tympan Library so that you can use its audio processing algorithms.

  • At the start of a Teeny example, add #include <Tympan_Library.h> at the top of the *.ino file. This enables you to use any of the Tympan_Library audio processing blocks.
  • When the Teensy audio objects and Teensy audio connections are created, you should swap out all of the Teensy audio lines and replace them with Tympan Library processing blocks and audio connections instead.

The reason that you want to swap from Teensy audio blocks to Tympan audio blocks is that the two libraries represent the audio data differently. The Tympan blocks represent audio using a floating-point data type whereas the Teensy Audio library uses a fixed-point data type. It is possible to mix-and-match between the two representations if you must, but you’ll need to add special conversion steps, which is annoying. Ask, if this is something that you need to do.

TL;DR

Yes, you should be able to use a Teensy 4.1 + an audio shield, but it will require a little trial-and-error debugging to get it to work the first time. Like always, Serial.println() is your friend for debugging.

If you want to try a Tympan-based example on the Teensy-only hardware, you can try the code below.

This code started as the Tympan Library example Basic Gain. I made all the changes that I think need to be made for it to run with the Teensy Audio board instead of the Tympan. This code does successfully compile on my computer, but I don’t have a Teensy Audio board anymore, so I can’t actually test it. Sorry.

To find the specific changes that I made, search this code for “MAR 2025”. Hopefully, you can follow these changes and make it work with your hardware!

/*
*   BasicGain_TeensyAudio
*
*   Created: Chip Audette, Nov 2016
*   Purpose: Process audio using Tympan by applying gain.
*
*   MODIFIED: Use Teensy Audio hardware instead of Tympan audio hardware (MAR 2025)
*     Original "BasicGain" example was here: https://github.com/Tympan/Tympan_Library/blob/main/examples/01-Basic/BasicGain/BasicGain.ino
*
*   Uses default sample rate of 44100 Hz with Block Size of 128
*
*   MIT License.  use at your own risk.
*/

//here are the libraries that we need
#include <Tympan_Library.h>  //include the Tympan Library
#include <Audio.h>  //include the Teensy Audio library (MAR 2025)

//create audio library objects for handling the audio
//Tympan                    myTympan(TympanRev::F); // remove the reference to the Tympan hardware (MAR 2025)
AudioControlSGTL5000      sgtl5000_1;                 //add a reference to the Teensy Audio interface (MAR 2025)
AudioInputI2S_F32         i2s_in;                 //Digital audio *from* the audio chip (either Tympan or Teensy).
AudioEffectGain_F32       gain1, gain2;           //Applies digital gain to audio data.
AudioOutputI2S_F32        i2s_out;                //Digital audio *to* the audio chip (either Tympan or Teensy).

//Make all of the audio connections
AudioConnection_F32       patchCord1(i2s_in, 0, gain1, 0);    //connect the Left input
AudioConnection_F32       patchCord2(i2s_in, 1, gain2, 0);    //connect the Right input
AudioConnection_F32       patchCord11(gain1, 0, i2s_out, 0);  //connect the Left gain to the Left output
AudioConnection_F32       patchCord12(gain2, 0, i2s_out, 1);  //connect the Right gain to the Right output


// define the setup() function, the function that is called once when the device is booting
const float input_gain_dB = 20.0f; //gain on the microphone
float vol_knob_gain_dB = 0.0;      //will be overridden by volume knob
void setup() {

  //begin the serial comms (for debugging)
  Serial.begin(115200);  delay(500);
  Serial.println("BasicGain_TeensyAudio: starting setup()...");

  //allocate the dynamic memory for audio processing blocks
  AudioMemory_F32(10); 

  //Enable the Tympan to start the audio flowing!
  //myTympan.enable(); // activate the Tympan's audio module. Remove refereces to myTympan (MAR 2025)
  sgtl5000_1.enable(); // add line to activate the Teensy auduio module (MAR 2025)

  //Choose the desired input
  //myTympan.inputSelect(TYMPAN_INPUT_ON_BOARD_MIC);     // remove reference to myTympan (MAR 2025)
   sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);  //or AUDIO_INPUT_MIC.  Add line to control Teensy Audio interface.  (MAR 2025)


  //Set the desired volume levels
  //myTympan.volume_dB(0);                   // Remove references to myTympan (MAR 2025)
  //myTympan.setInputGain_dB(input_gain_dB); // Remove refereces to myTympan (MAR 2025)
  sgtl5000_1.volume(0.5);                    // Add line to control volume of Teensy audio interface (MAR 2025)

  // check the volume knob
  //servicePotentiometer(millis(),0);  //Remove reference to Tympan-specific functionality (MAR 2025)

  //set the gain of the Gain processing block ...added MAR 2025
  float gain_dB = 6.0;
  gain1.setGain_dB(gain_dB);  //set the gain of the Left-channel gain processor
  gain2.setGain_dB(gain_dB);  //set the gain of the Right-channel gain processor

  Serial.println("Setup complete.");
} //end setup()


// define the loop() function, the function that is repeated over and over for the life of the device
void loop() {

  //check the potentiometer
  //servicePotentiometer(millis(),100); //remove reference to Tympan-specific functionality (MAR 2025)

  //let's blink the LEDs!
  //myTympan.serviceLEDs(millis());   //remove reference to Tympan-specific functionality (MAR 2025)

} //end loop();


// ///////////////// Servicing routines

// I removed these functions here because they were specific to Tympan (MAR 2025)

Thanks so much for all your help! The device is for a friend of mine, so I’ll ask them if they need the SD card functionality and go from there. When I get it working I’ll let you know how it went

@soairse
I am sorry that our inventory was not updated on the store site.
I actually have 2 Tympan Rev F ready to ship!