opus-go/internal/bitdepth/bitdepth.go
Sean DuBois 733188ab17 Implement bitdepth conversion and upsampling
bitdepth package takes F32LE -> S16LE and handles upsampling
from 16Khz -> 48Khz
2022-09-30 21:56:49 -06:00

23 lines
406 B
Go

package bitdepth
import (
"math"
)
func ConvertFloat32LittleEndianToSigned16LittleEndian(in []float32, out []byte, resampleCount int) error {
currIndex := 0
for i := range in {
res := int16(math.Floor(float64(in[i] * 32767)))
for j := resampleCount; j > 0; j-- {
out[currIndex] = byte(res & 0b11111111)
currIndex++
out[currIndex] = (byte(res >> 8))
currIndex++
}
}
return nil
}