48kHz for audio shield on T4

Status
Not open for further replies.

Uwe

Active member
Hello!

I read several threads regarding changing the sample frequency on a T4+Audio Shield. With each post or comment I read my confusion grows ho to do it...
Maybe one of the pros can point in the right direction...
I just want to change the samplerate to 48 kHz. It doesn't have to be possible at run-time. I do not need any other samplerate.
I'm just using record and play(all the files are 48kHz, no resampling necessary). The only additional components I use are the AudioAmplifier and AudioAnalyzePeak. No filters, effects, etc.
The communication to/from the Teensy is 'SERIAL', not 'AUDIO'.

My idea was: Just change #define AUDIO_SAMPLE_RATE_EXACT (in file AudioStream.h)
from 44100.0f to 48000.0f.
Is that all? Do I have to change code at other positions?

Uwe
 
I think you just have to #define the constant before #including AudioStream.h, as it doesn't override the define if already set.
 
Mhm, doesn't seems to be such easy...
I measured the amount of samples per second while recording and it shows 44188.(not 48k as expected)
I made a recording of a 1kHz signal (@48kHz) which shows up as a 1088Hz peak in a frequency analysis. 1088/1000 = 48000/44100.
It looks like that the hardware (the PLL) is *not* running at 48kHz but at 44.1kHz.

The good news is: If I change AUDIO_SAMPLE_RATE_EXACT in the header file itself is is working!

My sketch starts with:
#define AUDIO_SAMPLE_RATE_EXACT 48000.0f
#include <AudioStream.h>
...


I'm not quite sure why this isn't working correctly.
Someone with an idea?
 
#define AUDIO_SAMPLE_RATE_EXACT 48000.0f
#include <AudioStream.h>
...
I'm not quite sure why this isn't working correctly.
Someone with an idea?

If you change the define this way (not editing AudioStream.h), it only affects the code compiled in your sketch.

The code within the audio library still uses the original AudioStream.h. In fact, the Arduino IDE doesn't even recompile the audio library, because it can see AudioStream.h and all other files the audio library uses have not changed. You can see what Arduino is actually doing to compile your program by enabling Verbose Output in File > Preferences. Arduino always tries to reuse previously compiled libraries to speed up the compiling process. If you restart Arduino, or select a different board or other setting like CPU Speed in the Tools menu, you'll notice the first compile is much slower because it's recompiling everything. Then compiling again is much faster, because Arduino reuses the compiled libraries from the previous build.

To affect any libraries using AudioStream.h, you need to actually edit the AudioStream.h file.
 
If you change the define this way (not editing AudioStream.h), it only affects the code compiled in your sketch.

The code within the audio library still uses the original AudioStream.h. In fact, the Arduino IDE doesn't even recompile the audio library, because it can see AudioStream.h and all other files the audio library uses have not changed.

In that case I'd suggest rather than editing AudioStream.h, just touch it before compiling if you have overridden the sample
rate - that way the sources to the library aren't changed, just the timestamp.
 
I already guessed it had to do with precompiled libraries...
Thank you for the clarification.
 
Status
Not open for further replies.
Back
Top