Search code examples
c++qtqmediaplayerplayback-rate

Changin mp3 speed in Qt and C++ [QMediaPlayer]


I'm trying to develop a little application in which you can load a mp3 file and play it in variable speeds! (I know it already exists :-) )

I'm using Qt and C++. I already have the basic player but I'm stuck with the rate thing, because I want to change the rate smoothly (like in Mixxx) without stopping the playback! The QMediaPlayer always stops if I change the value and creates a gap in the sound. Also I don't want the pitch to change!

I already found something called "SoundTouch" but now I'm completely clueless what to do with it, how to process my mp3 data and how to get it to the player! The "SoundTouch" Library is capable of doing what I want, i got that from the samples on the homepage.

  • How do I have to import the mp3 file, so I can process it with the SoundTouch functions
  • How can I play the output from the SoundTouch function? (Perhaps QMediaPlayer can do the job?)
  • How is that stuff done live? I have to do some kind of stream I guess? So I can change the speed during play and keep on playing without gaps. Graphicaly in my head it has to be something that sits between the data and the player, where all data has to go through live, with a small buffer (20-50 ms or so) behind to avoid gaps during processing future data.

Any help appreciated! I'm also open to any another solution then "SoundTouch" as long as I can stay with Qt/C++!

(Second thing: I want to view a waveform overview aswell as moving part of it (around actual position of the song), so I could also use hints on how to get the waveform data)

Thanks in advance!


Solution

  • As of now (Qt 5.5) this is impossible to do with QMediaPlayer only. You need to do the following:

    This strategy uses Qt as much as possible, and brings you the best platform coverage (you still lose Android though as it does not support QAudioOutput)