diff --git a/audio/format/analyzer.go b/audio/format/analyzer.go index a4602b9..19df2fc 100644 --- a/audio/format/analyzer.go +++ b/audio/format/analyzer.go @@ -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 {