refactor(tracker): Rewrote the sequencer loop to use simple mutex

This commit is contained in:
Veikko Sariola
2020-12-29 16:30:44 +02:00
parent 8029dbd1a8
commit cd498e775b
14 changed files with 315 additions and 166 deletions

29
oto/convertbuffer.go Normal file
View File

@ -0,0 +1,29 @@
package oto
import (
"bytes"
"encoding/binary"
"fmt"
"math"
)
// FloatBufferTo16BitLE is a naive helper method to convert []float32 buffers to
// 16-bit little-endian integer buffers.
// TODO: optimize/refactor this, current is far from the best solution
func FloatBufferTo16BitLE(buff []float32) ([]byte, error) {
var buf bytes.Buffer
for i, v := range buff {
var uv int16
if v < -1.0 {
uv = -math.MaxInt16
} else if v > 1.0 {
uv = math.MaxInt16
} else {
uv = int16(v * math.MaxInt16)
}
if err := binary.Write(&buf, binary.LittleEndian, uv); err != nil {
return nil, fmt.Errorf("error converting buffer (@ %v, value %v) to bytes: %w", i, v, err)
}
}
return buf.Bytes(), nil
}