Change Speed of MP3 file

Writing software that inputs and/or outputs audio and performs DSP algorithms such as filters, new codecs or audio effects.
JamesCooper
User
Posts: 2
Joined: Wed 2021-06-16 1:16

Change Speed of MP3 file

Post by JamesCooper »

I have a VS1053 and 4 short sound files of car engine noises. I want to be able to run the MP3 or wave files and either speed them up or down, alter the volume. I don't think i will have an issue with pitch if the speed goes up This will ultimately be linked to the car's speed.
I have 4 short audio file loops that will repeat and change dependent on the car's speed.
There are systems available that pick up the speed of the engine, via the alternator, but My car will be electric
Does anybody have the code that I can do this?
I'm a novice with Arduino but familiar with some programming. and TLA's spin me out.
User avatar
pasi
VLSI Staff
Posts: 2006
Joined: Thu 2010-07-15 16:04

Re: Change Speed of MP3 file

Post by pasi »

You can write to the SCI_AUDATA to change the actual playback rate (mp3 decoding won't override it unless the samplerate in the mp3 audio itself changes), or use a more fool-proof method: lie about the XTAL frequency through SCI_CLOCKF.

If you're using the vs1053b patches package, you can also use the samplerate finetune control.

All of the methods are limited by their adjustment range and the 48000Hz maximum samplerate for the 12.288MHz crystal.

(Naturally SCI_VOL can be used to alter volume.)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
JamesCooper
User
Posts: 2
Joined: Wed 2021-06-16 1:16

Re: Change Speed of MP3 file

Post by JamesCooper »

Thanks so much for getting back so promptly, good to see a fellow cyclist. Come and ride my Penny Farthing. Do you have a snippet of code that would help, I am sorry but what you say is like Chinese to me. But usually if i get a bit of code it may make sense. I am using the MP3 Button Player 2
User avatar
pasi
VLSI Staff
Posts: 2006
Joined: Thu 2010-07-15 16:04

Re: Change Speed of MP3 file

Post by pasi »

I thought that you already had the player part, and only needed to adjust the samplerate.

Unfortunately I can't help much with the Arduino. If you have a working player, you may need to dig a little deeper to find the main play loop, or some kind of callback function that gets called during play, so that you can then perform the required control register writes through the Serial Control Interface (SCI).

You can also check the microcontroller examples thread from viewforum.php?f=11 .

For looping WAV, you would first send a WAV RIFF header (indicates the data format, number of channels, and initial samplerate) with the data chunk size set to 0 (see the datasheet for an example), then you can use the vs1053b as a DAC, sending the audio loops, and optionally adjusting the samplerate on the fly.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
jtlechem
User
Posts: 15
Joined: Tue 2022-05-10 23:54

Re: Change Speed of MP3 file

Post by jtlechem »

I'm interested in a similar use of the vs1053. I'd like to change the speed/tempo/rate of my audio files (but not the pitch/frequency) with a knob or buttons while the sound is playing. My audio files are custom sine waves generated numerically in matlab which has a function to save them as WAV files. They work successfully on the Adafruit Audio FX Mini Sound Board (with the vs1000) but there's not much else I can do with that board besides play/pause. So I've heard that the vs1053 is the way to go.

I read in previous comment and in the datasheet about using SCI_AUDATA or SCI_CLOCKF or the samplerate finetune control. So sounds like you can speed up playback by either altering the samplerate or the microcontroller's clock frequency?
Does this change the pitch or only the speed?

Also looking for any guidance on how to get a knob to control that playback speed. Could it be done? should I get the vs1053 by itself or get the breakout board? is there another sound board better suited for this?

Thanks for any input
User avatar
pasi
VLSI Staff
Posts: 2006
Joined: Thu 2010-07-15 16:04

Re: Change Speed of MP3 file

Post by pasi »

jtlechem wrote: Wed 2022-05-11 0:26I read in previous comment and in the datasheet about using SCI_AUDATA or SCI_CLOCKF or the samplerate finetune control. So sounds like you can speed up playback by either altering the samplerate or the microcontroller's clock frequency?
Does this change the pitch or only the speed?
Playing the samples faster or slower will change both the tempo and the pitch.
jtlechem wrote: Wed 2022-05-11 0:26Also looking for any guidance on how to get a knob to control that playback speed. Could it be done?
See the vs1053b Patches Package ( https://www.vlsi.fi/en/support/software ... tches.html ). There is one variant which includes the pitch/tempo shifter.

The vs1053b prototyping board is probably easiest to connect to an existing microcontroller board.


There is more than one sine wave in the signal, right? If you only had one sine, you could just use the sine generator on the vs10xx (or even vs1000) and not care about tempo or pitch and only adjust the generated frequency. Also, if there are only a few sine waves, you could still generate the combined signal in the vs10xx / vs1000. So, are you able to tell a bit more about the custom signal you generate?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
jtlechem
User
Posts: 15
Joined: Tue 2022-05-10 23:54

Re: Change Speed of MP3 file

Post by jtlechem »

Thanks for the tips.
Is there a difference between changing the sample rate and changing the clock frequency? Do both of those methods change the pitch? I need to keep the frequency of my sine waves the same, and just change how fast they come out of the player. Like changing playback speed on youtube.

So my sine waves are written such that their amplitude rises and falls at specific times. There are 4 sine waves that do this, each playing on their own speaker. Each wave rises and falls in a specific sequence of my design, and they just play on a continuous loop. So the speakers end up sort of chasing each other, or in other words the high amplitude segments are perceived to be traveling between the 4 speakers. (using two of the mini sound boards to get 4 signals to play, since each board just has 2 channels i believe)
So anyway, using a sine generator on a vs10xx may not work for that. But mostly I'm just hoping to integrate a turning knob/dial to change the playback speed (without changing pitch/frequency) on demand.
User avatar
pasi
VLSI Staff
Posts: 2006
Joined: Thu 2010-07-15 16:04

Re: Change Speed of MP3 file

Post by pasi »

Hi,

It seems to me could do all this by keeping a sine wave of the desired frequency playing using sinetest, and then just adjust the volume of each channel (two vs10xx). You can use volume of e.g. -90dB to "turn off" the sine of other channels, and set 0dB on the one that should output the signal.

And you can use a few steps of fade, or cross-fade in real-time.

It is also possible to implement everything on the vs10xx itself, booting from SPI FLASH and using another vs10xx as a slave, and reading values using the ADC. But if you have a favorite microcontroller, using that and two vs10xx is probably quicker and more cost-effective for small quantities.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
jtlechem
User
Posts: 15
Joined: Tue 2022-05-10 23:54

Re: Change Speed of MP3 file

Post by jtlechem »

That's an interesting idea for making these sine waves, I'll try that out. I'll probably use my own microcontroller or an arduino along with two vs1053's - seems like I ought to be able to program each wave's volume to ramp up/down when I want, and play that on a continuous loop. Thanks for that tip.

So as for playback speed, I can't quite tell the difference between SCI_AUDATA and SCI_CLOCKF. It seems that they both effect the sample rate, which you said changes both tempo and pitch.
In the 1053b Patches Package, there's the "pitch/tempo" shifter but i can't tell if that means it can change pitch OR tempo, or if it means that pitch and tempo still change together.
Wondering if I need to find some kind of algorithm for changing playback speed without changing pitch.

Thanks again for all the help here
User avatar
pasi
VLSI Staff
Posts: 2006
Joined: Thu 2010-07-15 16:04

Re: Change Speed of MP3 file

Post by pasi »

SCI_AUDATA sets the samplerate the playback is performed at. SCI_CLOCKF tells the system what is the XTAL (input) frequency, and the samplerate control value is calculated from that and the current desired samplerate. If you "lie" about the XTAL frequency, the control value is off by the corresponding amount and the actual playback samplerate is off by the same amount.

In your case, as I have understood it, your "tempo" is coming from the turning on/off the sine wave, so you only need to write SCI_VOL by the controller at the right times.

Yes, the vs1053b patches package contains a pitch/tempo shifter, which can adjust one without affecting the other. (I.e. to play slower or faster with the same pitch, or play with the same tempo with higher or lower pitch.) But if I have understood your application correctly, you won't need that. (And the pitch/tempo shifter can't be used with the sine test, only with normal decoding.)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Post Reply