Let's say you have an 8 second clip at 44100Hz.
To acheive standard playback at the original sample rate you want to scan from zero to t * sr in t seconds, that's 0 to 352800 in 8000ms (line gens are specified in milliseconds)
You could say
[352800, 8000( | [line~]
But you want to be able to vary the rate, so fixing it in a message isn't so good.
A line generator is usually normalised, so whatever the rate/time we often make it scan from 0 to 1. You then multiply that by the total size, so
[1, 8000( [44100( sr in samps/second | | [line~] [* 8] time in seconds | / [*~ ] | [tabread~]
Substituting the time in the message
time -------
/ | [1, $1( rate | | | | [line~] [* ] time in seconds | / [*~ ] | [tabread~]
Now you can vary your rate and time.
I want to use tabread4~ in conjunction with other objects in one case to change the speed and keep the sample at the same pitch
You cannot do this with a simple tabread~, what you describe is timestretching and that's another story.
and in another case to just change the pitch and keep the sound length the same.
Sadly that's also not something you can do with simple playback/reading either, what you describe is pitchshifting, a whole new can of worms.
Is there a way to do this?
Yes indeed, there are several ways, but try and master the standard playback methods first because the pitchshift and timestretch methods are quite complicated and you will need to fully understand sample playback before moving forwards.