Properly handle float32 samples for analyzer
This commit is contained in:
parent
e26156194d
commit
88915d15d4
|
@ -3,8 +3,10 @@ package format
|
||||||
import (
|
import (
|
||||||
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
|
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
|
||||||
"io"
|
"io"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const chanBuf = 16
|
const chanBuf = 16
|
||||||
|
@ -37,13 +39,17 @@ func NewAnalyzerChannel(source audio.Source, err error) (audio.Source, AnalyzerC
|
||||||
go func() {
|
go func() {
|
||||||
defer close(channel)
|
defer close(channel)
|
||||||
|
|
||||||
if _, ok := sources[1].(audio.TypedSource[float32]); ok {
|
if float32Source, ok := sources[1].(audio.TypedSource[float32]); ok {
|
||||||
for block := range sources[1].ToInt32(source.GetBitDepth()).GetBlocks() {
|
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{
|
channel <- &AnalyzerPacket{
|
||||||
Samples: block,
|
Samples: buf,
|
||||||
Channels: source.GetChannels(),
|
Channels: source.GetChannels(),
|
||||||
SampleRate: source.GetSampleRate(),
|
SampleRate: source.GetSampleRate(),
|
||||||
BitDepth: source.GetBitDepth(),
|
BitDepth: 32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue