Changing the sample rate

If you want to change the sample rate of the Tympan, you can look at the example program 01-Basics\ChangeSampleRate.ino.

The only line that you need to change is

const float sample_rate_Hz = 24000.0f ;

This will set the Tympan to run at a sample rate of 24 kHz. If you want to run at another speech, simply change the value!

When changing the value, be aware that it will only work for a discrete number of choices. Right now, the list of valid values is set in the file in the Tympan library “output_i2s_f32.cpp”. In there, there is a line with all the valid choices:

{ 2000, 8000, 11025, 16000, 22050, 24000, 32000, 44100, (int)44117.64706 , 48000, 88200, (int)(44117.64706 * 2), 96000, 176400, (int)(44117.64706 * 4), 192000};

If you choose a different value, the system will probably not work. But, if one of these values works for you, feel free to make the change.

If you’re going to run the computationally-intensive algorithms, you may not be able to run at the higher sample rates. But, if you’ve got a relatively light amount of processing, you can run the Tympan up into the ultrasound!

Chip

Here’s the GitHub link to the example sketch: https://github.com/Tympan/Tympan_Library/blob/master/examples/01-Basic/ChangeSampleRate/ChangeSampleRate.ino

The full chunk of code that sets the sample rate (and that sets the size of the audio blocks passing through the system) is:

//set the sample rate and block size
const float sample_rate_Hz = 24000.0f ; //24000 or 44117 (or other frequencies in the table in AudioOutputI2S_F32)
const int audio_block_samples = 32;     //do not make bigger than AUDIO_BLOCK_SAMPLES from AudioStream.h (which is 128)
AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples);

In this example, it uses a sample rate of 24 kHz and a block size of 32.

For other sample rates, you can have sample rates up to 192 kHz (though I’ve only ever used up to 96 kHz) . Currently, you cannot choose any value you like, as there is a lookup table that is used to interpret the value that you enter. The table of allowed values is buried in AudioOutputI2S_F32. Scroll down and look for the variable ‘samplefreqs’. That holds the allowed values. If you want a different value, you/we could create new entries in the table.

As for the audio block size, you can (I think) choose any value between 1 and 128. I’ve only ever run it down at 4 samples, as it becomes less and less CPU efficient for smaller block sizes. By contract, I’ve run 128 sample blocks many times as it is the fixed standard for the Teensy Audio library. Longer block sizes might be desirable in some situations, but the Tympan library doesn’t current support it (because of its underlying limit in the Teensy Audio library).

Chip