maddyblue / go-dsp

Digital Signal Processing for Go
http://godoc.org/github.com/mjibson/go-dsp
ISC License
847 stars 89 forks source link

Fix problem reading 16-bit samples #4

Closed r9y9 closed 10 years ago

r9y9 commented 10 years ago

A slight bug is fixed in this commit to correctly read 16-bit samples.

maddyblue commented 10 years ago

Could you describe the problem and why this fixes it?

r9y9 commented 10 years ago

I apologize for the lack of explanation. The problem is that the original code fetches 16-bit samples for each 8-bit (not 16-bit).

e.g. In the for roop: w.Data16[ch][0] = bLEtoInt16(data, 0_int(w.NumChannels)+ch) // fetchs data[0], e.g. where NumChannels is 1 and ch is 0 w.Data16[ch][1] = bLEtoInt16(data, 1_int(w.NumChannels)+ch) // fetches data[1] // should be data[2] w.Data16[ch][2] = bLEtoInt16(data, 2*int(w.NumChannels)+ch) // fetches data[2] // should be data[4]

I fix the index of reading data variable to fetch samples for each 16-bit (2-byte) by simply adding 2 multiplier to the roop variavle i. I hope this answers your question.

maddyblue commented 10 years ago

Great, thanks.