Hey, I'm working on a project where I'd like to be able to speed up and down the playback of a mp3 file - I don't care about the audio getting warped. I'm using Frank B's great MP3 library with the Teensy Audio lib (thanks to Frank B and Paul and everyone else who contributed! This is a really impressive community project!). I've successfully played MP3 files from winbond serial flash. I know there are a few ways to change the audio speed, and I've (possibly wrongly) concluded that changing the sample rate as the file is being decoded would be the most straightforward.
I dove into the MP3 library, but I'm not getting very far with modifications that aren't breaking the code (Teensy blocks or hangs).
Here's how I understand it now (as a summary for myself + check my understanding against reality):
What I tried:
changing the initial samprate (overwriting it in play(void) after decodeMp3 returns) - no effect
overriding the samprate in MP3GetNextFrameInfo() and MP3GetLastFrameInfo() and printing the value in update(). Causes hangs/code blocking so I can't see the serial data and no audio plays. I suspect there are calculations somewhere that depend on the sample rate value.
So my questions:
Thanks in advance for your time!
I dove into the MP3 library, but I'm not getting very far with modifications that aren't breaking the code (Teensy blocks or hangs).
Here's how I understand it now (as a summary for myself + check my understanding against reality):
Main sketch calls play(*filename), which calls play(void) after opening the file (play_sd_mp3.h)
play(void) (play_sd_mp3.cpp) (only describing relevant parts):
MP3GetNextFrameInfo() and MP3GetLastFrameInfo() do affect samplerate, and the latter is called by decodeMp3, but I can't find where that gets called. From _vectorsRam[IRQ_AUDIOCODEC + 16]?
play(void) (play_sd_mp3.cpp) (only describing relevant parts):
mp3objptr = this;
calls decodeMp3(mp3objptr, ...):
sets isr flag: playing = codec_playing;
The ISR calls update(), but that doesn't seem to affect samprate.calls decodeMp3(mp3objptr, ...):
AudioPlaySdMp3 *o = mp3objptr;
MP3Decode(o->hMP3Decoder, ...); (mp3dec.c)
initSwi();MP3Decode(o->hMP3Decoder, ...); (mp3dec.c)
this calls UnpackFrameHeader which fills samprate from the header
sets isr flag: playing = codec_playing;
MP3GetNextFrameInfo() and MP3GetLastFrameInfo() do affect samplerate, and the latter is called by decodeMp3, but I can't find where that gets called. From _vectorsRam[IRQ_AUDIOCODEC + 16]?
What I tried:
changing the initial samprate (overwriting it in play(void) after decodeMp3 returns) - no effect
overriding the samprate in MP3GetNextFrameInfo() and MP3GetLastFrameInfo() and printing the value in update(). Causes hangs/code blocking so I can't see the serial data and no audio plays. I suspect there are calculations somewhere that depend on the sample rate value.
So my questions:
- Is changing sample rate the best way to speed up/down playback of the mp3 from serial flash? If not, what is?
- If it is, how can I change the sample rate* and any supporting values (bitsPerSample?) so that this works? *either while the file is playing or by smoothly stopping the file and starting it from that position at the changed speed
- What is the proper term for the playback "speed" of the song?
Thanks in advance for your time!
Last edited: