Just solved that as I needed it to work for my project.
The problem is that this code is trying to modify variables that are global within the tmrpcm library code, but not your program. It works if you put it inside the tmrpcm library.
(For me, the tmrpcm library is stored in my sketch folder in a folder called libraries, the files needing modifying are Arduino/libraries/TMRpcm/TMRpcm.h and Arduino/libraries/TMRpcm/TMRpcm.cpp)
(These can't be modified from Arduino IDE but must be modified with a text editor eg. Notepad or KWrite)
Create a function in the TMRpcm.cpp file, which contains the code which Lucario448 wrote. I called this 'changespeed', so my function declaration was this:
void TMRpcm::changespeed(unsigned int newspeed){
unsigned long newSR = map(newspeed, 0, 1023, 8000, 44100);
if (bitRead(optionByte,6)) *ICRn[tt] = 10 * (800000 / newSR);
else *ICRn[tt] = 10 * (1600000 / newSR);
}
and I put this at line 448, just before the area marked
//***************************************************************************************
//********************** Functions for single track playback ****************************
(though I could probably have put this anywhere in the tmrpcm.cpp file).
Then, I modified the 'TMRpcm.h' file accordingly, to add the new function to the list of available functions or the compiler gets confused if you don't. Again, I added this before the play function (line 31)
void changespeed(unsigned int newspeed);
Now, I can call this function from anywhere in my code whenever I want to change the playback speed, if I want to control if from analog0, I just call tmrpcm.changespeed(analogRead(A0));
Please note, when I updated libraries this function got forgotten. I don't know how to block Arduino IDE from updating this library and forgetting this change, but also keeping a copy of those 2 modified files elsewhere could be a good idea just i case