Properly handle float32 samples for analyzer
This commit is contained in:
parent
e26156194d
commit
88915d15d4
|
@ -3,8 +3,10 @@ package format
|
|||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
|
||||
"io"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const chanBuf = 16
|
||||
|
@ -37,13 +39,17 @@ func NewAnalyzerChannel(source audio.Source, err error) (audio.Source, AnalyzerC
|
|||
go func() {
|
||||
defer close(channel)
|
||||
|
||||
if _, ok := sources[1].(audio.TypedSource[float32]); ok {
|
||||
for block := range sources[1].ToInt32(source.GetBitDepth()).GetBlocks() {
|
||||
if float32Source, ok := sources[1].(audio.TypedSource[float32]); ok {
|
||||
for block := range float32Source.GetBlocks() {
|
||||
//Convert float32 to int32 representation with 32 bit depth, so it hashes the same way
|
||||
buf := make([]int32, len(block))
|
||||
copy(buf, unsafe.Slice((*int32)(unsafe.Pointer(&block[0])), len(block)))
|
||||
runtime.KeepAlive(block)
|
||||
channel <- &AnalyzerPacket{
|
||||
Samples: block,
|
||||
Samples: buf,
|
||||
Channels: source.GetChannels(),
|
||||
SampleRate: source.GetSampleRate(),
|
||||
BitDepth: source.GetBitDepth(),
|
||||
BitDepth: 32,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue