buffer lenght...
The problem is you are using the number~ object which translates from audio rate data to control rate messages it does this at a speed set in ms so it's not sample accurate. I suggest you read the MSP help page entitled 'How MSP works'.
Max Patch
Copy patch and select New From Clipboard in Max.
As you are setting the start and end of the recording you don't need to waste your time trying to measure the outlet of record~ just use translate to get the record length in MS.
thank you
laurent