Getting amplitudes from wav file (SOLVED)

Hi, I have a question about sound after a long time. I have a simple script for getting amplitudes from a wav file, which returns values between 0 and 65535 (approximately), but should return values ranging from -32768 to 32767. Don’t know how to modify the script correctly?
Thank you for every answer.

    f = assert(io.open("C:\\Users\\karel\\downloads\\a.wav", "rb"))
	f:seek("cur", 44)
	count = 0
	while true do
	bytes = f:read(1)
	if not bytes then print(count) break end

	b = string.byte(bytes, 1, -1)
	b = string.format("%02x", b)
	bytes = f:read(1)
	b1 = string.byte(bytes, 1, -1)
	b1 = string.format("%02x ", b1)

	x = b .. b1
	x = tonumber(x, 16)

	print(x)
	f:seek("cur", 2)
	count = count + 1
	end

If you performed math.floor after subtracting 32767.5 from the value you should get a corresponding number between -32767 and 32767.

1 Like

I’m glad it’s that simple, I wasn’t sure. Thank you very much for your answer @bryanrieger.

1 Like