Could you repost the code as text? That way it would be easier to diff
it against the original one (which you may also want to link to for reference).
Time-scaling a real-time input is complicated (impossible): you cannot speed up a sound because you'll run out of input data and you cannot speed it down because the input/output latency will keep growing over time.
With the above restrictions in mind, the normal approach at time-scaling with FFT while preserving pitch is to use the FFT to change the pitch of a signal first and obtain a time-domain version of the signal with a different pitch. Then you change the playback rate of the output signal to go back to the original pitch with a different duration. For instance, to speed up the sound by 2x you would:
- pitch shift down by one octave
- play back at rate 2x
conversely, to play at half speed, you would do:
- pitch shift up by one octave
- play back at rate 0.5x
As to how to change the playback rate, you would normally apply some interpolation to the signal. For integer ratios, linear interpolation could be fine, but at least 4-point cubic or something more elaborate are recommended for decent results and arbitrary ratios. There has been a conversation on the Pd mailing list recently that could be of interest: https://lists.puredata.info/pipermail/pd-list/2021-04/129511.html