I am trying to create a patch in Max that records sound over a portion of a given length of time, then plays back the recording to fill out the remaining portion of time with the speed of playback adjusted, such that the complete recording of the first portion is heard within the second portion.
The total length is given as an integer of minutes 1-180.
I have a timer set up that records the length of the recording in milliseconds.
I converted the minutes to seconds by multiplying that number by 60, and the milliseconds to minutes by multiplying that number by .001 (please correct me if I have that wrong!)
I know I can determine the length of the playback (of the remaining portion) by subtracting the length of the recording (of the first portion) from the total length.
However, I don't know how to calculate the speed at which the recording needs to play in order to fill up the remaining portion of time. (I also don't know how to write this as math formulas).
Abstractly, I understand that the speed would be less than 1 if the recorded portion takes less than half the total length. The speed would be 1 if the recorded portion is exactly half the total length. And, the speed would be greater than 1 if the recorded portion is more than half the total length.
I appreciate any help you can give me.
First please observe that speed refers to units of the type something per unit of time; for instance kilometers per hour, liters per seconds, etc. Here you are looking for an unit whose type is seconds per seconds, in which case I guess a more appropriate name would be a speed ratio
Let $T$ be the total length, $D$ the duration of the original recording, and $\lambda$ the speed ratio at which you want to play the recording the second time to fill the total duration.
So you basically have $T = D + \lambda D$. As you mentioned if $D = T/2$ then the second recording is played at the same speed as the first one, aka $\lambda=1$. By solving the above equation for $\lambda$ you find:
$$\lambda = (T-D)/D$$
Note that I have not mentioned the units of time (seconds, minutes etc.) but you need to make sure they all are in the same units.