Below is a link to a simple and valuable tutorial function in C by Stephan M. Bernsee, called smbPitchShift.cpp, which can raise or lower the pitch of a musical signal.
I was able to also use it to slow-down or speed-up music without changing its pitch. If you want to instead do a time-stretch without altering the original pitch, you may have to apply Re-Sampling.
Looks like Bernsee has created some changes to his code since the version linked at GitHub. His newer code is available for download from his website -- it may increase the range of shifting from his original specification. I tweaked his original code so that I could pitch shift up by 8x.