faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.08k stars 152 forks source link

A small clamping inaccuracy in the oto Speaker writer #88

Open ajzaff opened 4 years ago

ajzaff commented 4 years ago

https://github.com/faiface/beep/blob/b573886bdf0f6ac1b8e7f8931a2a2b249c90666b/speaker/speaker.go#L121

Currently this returns the wrong values for an input of -1.

I believe this should fix it:

valInt16 = int16((-1<<15)+(val+1)/2*(1<<16-1))

https://play.golang.org/p/E-8wkFoIHQ3

MarkKremer commented 1 year ago

Fun fact, in the latest release of Oto the samples get converted back to floats. Maybe a better option to just pass raw float bytes to Oto and skip the conversion altogether.