Use direct ReadStereo, then convert floats ourselves

This commit is contained in:
DataHoarder 2022-02-25 22:12:12 +01:00
parent 7840b686f2
commit 8b450fee0b

View file

@ -1,5 +1,10 @@
package opus
/*
#cgo CFLAGS: -I"${SRCDIR}/../../../cgo" -march=native -Ofast -std=c99
#include "audio.h"
*/
import "C"
import (
"bytes"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
@ -31,24 +36,20 @@ func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
defer stream.Close()
defer close(newChannel)
blockSize := BlockSize * 2
buf := make([]int16, 120*FixedSampleRate*2)
for {
buf := make([]float32, blockSize)
n, err := stream.ReadStereoFloat32(buf)
n, err := stream.ReadStereo(buf)
if err != nil {
return
}
blockSize = n
if blockSize < 1024 {
blockSize = 1024
}
buffer := make([]float32, n*2)
C.audio_int16_to_float32((*C.int16_t)(&buf[0]), C.size_t(n*2), (*C.float)(&buffer[0]), C.int(16))
if n > 0 {
newChannel <- buf[:n*2]
newChannel <- buffer
}
}
}()