Using C++ to transpose a song to a different key?

I want to make a program that takes a music file (mp3 or similar format) as input and transposes it to a different musical key after providing the desired change up or down in half steps (for example, from G minor to F# minor). Some questions come to mind:

1. How difficult would this be?
2. What libraries, IDEs, etc. could be used for the task?
3. If not feasible in C++, what is a good programming language?
Well, some google shows this:

https://www.fcreyf.com/article/mp3-decoding-in-c++

It looks like an entry point for you.
Not easy to do from a sampled format like mp3.

Can you work from basic midi files? Then transposition should be easy, since the actual notes are stored.

Googling "c++ and midi" seems to produce a lot of software, although I haven't tried any of them.
In addition to the already difficult task of decoding the mp3 file itself (which I suggest using a library, either the one that coder777 linked or perhaps something from: https://stackoverflow.com/a/3658379/8690169), it'll be a LOT of work to make the output of your program actually sound good. It's easy enough to change the frequencies as a whole with filters, but transposing notes that way would be really hard; I don't even know where you'd begin except for just looking at the spectrogram at each sample of the song, and shifting the individual frequency bins to what you want. But this probably will induce a lot of distortion.

For FFTs, either use FFTW (not free for commercial use), or other libraries such as what you can find from searching for "fft library github". I've used kissFFT, though I imagine it's slower than FFTW.

I suggest using open formats instead of mp3. You'll still have almost all the same challenges, but at least you won't have to deal with the legality of using mp3. Edit: Just did a search, it says mp3 is license-free as of 2017 in the US because the patents have expired. But I'm not a lawyer.
Last edited on
Topic archived. No new replies allowed.