fix wav2flac encoding
This commit is contained in:
parent
3c16c77da5
commit
18f6041006
|
@ -88,7 +88,7 @@ func wav2flac(wavPath string, force bool) error {
|
|||
return errors.WithStack(err)
|
||||
}
|
||||
// Number of samples per channel and block.
|
||||
const nsamplesPerChannel = 16
|
||||
const nsamplesPerChannel = 4096
|
||||
nsamplesPerBlock := nchannels * nsamplesPerChannel
|
||||
buf := &audio.IntBuffer{
|
||||
Format: &audio.Format{
|
||||
|
@ -116,6 +116,10 @@ func wav2flac(wavPath string, force bool) error {
|
|||
if n == 0 {
|
||||
break
|
||||
}
|
||||
if n < 16*nchannels {
|
||||
n = 16
|
||||
//break
|
||||
}
|
||||
for _, subframe := range subframes {
|
||||
subHdr := frame.SubHeader{
|
||||
// Specifies the prediction method used to encode the audio sample of the
|
||||
|
@ -130,7 +134,7 @@ func wav2flac(wavPath string, force bool) error {
|
|||
subframe.NSamples = n / nchannels
|
||||
subframe.Samples = subframe.Samples[:subframe.NSamples]
|
||||
}
|
||||
for i, sample := range buf.Data {
|
||||
for i, sample := range buf.Data[:n] {
|
||||
subframe := subframes[i%nchannels]
|
||||
subframe.Samples[i/nchannels] = int32(sample)
|
||||
}
|
||||
|
@ -160,7 +164,7 @@ func wav2flac(wavPath string, force bool) error {
|
|||
HasFixedBlockSize: false,
|
||||
// Block size in inter-channel samples, i.e. the number of audio samples
|
||||
// in each subframe.
|
||||
BlockSize: uint16(nsamplesPerChannel),
|
||||
BlockSize: uint16(subframes[0].NSamples),
|
||||
// Sample rate in Hz; a 0 value implies unknown, get sample rate from
|
||||
// StreamInfo.
|
||||
SampleRate: uint32(sampleRate),
|
||||
|
|
4
go.mod
4
go.mod
|
@ -1,6 +1,6 @@
|
|||
module git.gammaspectra.live/S.O.N.G/flacgo
|
||||
|
||||
go 1.14
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-audio/audio v1.0.0
|
||||
|
@ -9,3 +9,5 @@ require (
|
|||
github.com/mewkiz/pkg v0.0.0-20211102230744-16a6ce8f1b77
|
||||
github.com/pkg/errors v0.9.1
|
||||
)
|
||||
|
||||
require github.com/go-audio/riff v1.0.0 // indirect
|
||||
|
|
Loading…
Reference in a new issue