Public feed #532996

Someone

public text v1 · immutable
Raw Edit
·published 2007-06-03 09:49 UTC
rendered paste body
Function getdeltatime(fs)
	Local ok=0,bt,n

;Delta-time is a
;variable-length encoded value. This format, While confusing, allows large
;numbers To use as many bytes as they need, without requiring small numbers To
;waste bytes by filling with zeros. The number is converted into 7-bit bytes,
;And the most-significant bit of Each byte is 1 except For the Last byte of the
;number, which has a msb of 0. This allows the number To be Read one byte at a
;time, And when you see a msb of 0, you know that it was the Last (least
;significant) byte of the number. According To the MIDI spec, the entire delta-
;time should be at most 4 bytes long. 

	For n=1 To 4
		mididelta[n]=0
	Next
	
	For n=1 To 4
		n2%=readbyte2(fs)
		n3=n2 And 128
		n2=n2 Mod 128
		Mididelta[n]=n2:
		If n3<128 Then n=555:Exit
	Next
	time=(Mididelta[4]*128*128*128)+(Mididelta[3]*128*128)+(Mididelta[2]*128)+(Mididelta[1])
	Return time
End Function