Use new FLAC bindings fork, change interface of format.Encode

This commit is contained in:
DataHoarder 2022-02-23 16:40:38 +01:00
parent 4f6b2801ea
commit 4990f9ca21
4 changed files with 37 additions and 14 deletions

View file

@ -9,7 +9,7 @@ import (
"bytes"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
libflac "github.com/cocoonlife/goflac"
libflac "git.gammaspectra.live/S.O.N.G/goflac"
"io"
)
@ -120,21 +120,48 @@ func (f Format) OpenAnalyzer(r io.ReadSeekCloser) (audio.Source, format.Analyzer
}, analyzerChannel, nil
}
func (f Format) Encode(source audio.Source, writer format.WriteSeekCloser, options map[string]interface{}) error {
func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[string]interface{}) error {
var bitsPerSample = 16
var compressionLevel = 8
var blockSize = 0
var streamable = true
if options != nil {
var val interface{}
var ok bool
var intVal int
var boolVal bool
if val, ok = options["bitdepth"]; ok {
if intVal, ok = val.(int); ok {
bitsPerSample = intVal
}
}
if val, ok = options["compression_level"]; ok {
if intVal, ok = val.(int); ok {
compressionLevel = intVal
}
}
if val, ok = options["block_size"]; ok {
if intVal, ok = val.(int); ok {
blockSize = intVal
}
}
if val, ok = options["streamable"]; ok {
if boolVal, ok = val.(bool); ok {
streamable = boolVal
}
}
}
var encoder *libflac.Encoder
var err error
if writeSeeker, ok := writer.(libflac.FlacWriter); ok {
encoder, err = libflac.NewEncoderWriteSeeker(writeSeeker, source.Channels, bitsPerSample, source.SampleRate, compressionLevel, streamable, blockSize)
} else {
encoder, err = libflac.NewEncoderWriter(writer, source.Channels, bitsPerSample, source.SampleRate, compressionLevel, streamable, blockSize)
}
encoder, err := libflac.NewEncoderWriter(writer, source.Channels, bitsPerSample, source.SampleRate)
if err != nil {
return err
}

View file

@ -21,8 +21,8 @@ type WriteSeekCloser interface {
type Encoder interface {
Format
// Encode Receives an audio.Source and encodes it into a writer
Encode(source audio.Source, writer WriteSeekCloser, options map[string]interface{}) error
// Encode Receives an audio.Source and encodes it into a writer. Some formats can do special operations if writer is also an io.Seeker
Encode(source audio.Source, writer io.WriteCloser, options map[string]interface{}) error
}
type AnalyzerPacket struct {

9
go.mod
View file

@ -4,13 +4,10 @@ go 1.18
require (
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220130003320-c9b07c6bec7a
github.com/cocoonlife/goflac v0.0.0-20170210142907-50ea06ed5a9d
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220223152921-827e6c3f729f
github.com/dh1tw/gosamplerate v0.1.2
github.com/dsonck92/tta v0.2.0
github.com/kvark128/minimp3 v0.0.0-20211109174940-101188771a65
)
require (
github.com/cocoonlife/testify v0.0.0-20160218172820-792cc1faeb64 // indirect
github.com/dsonck92/tta v0.2.0 // indirect
github.com/klauspost/cpuid v1.3.1 // indirect
)
require github.com/klauspost/cpuid v1.3.1 // indirect

5
go.sum
View file

@ -1,9 +1,8 @@
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220130003320-c9b07c6bec7a h1:LxrTp9gf4w5KnFHRPFLXYfoxC58GCSEmZrHI6Ogtrm0=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220130003320-c9b07c6bec7a/go.mod h1:vkoHSHVM9p6vAUmXAik0gvaLcIfiQYrD6bQqVpOulUk=
github.com/cocoonlife/goflac v0.0.0-20170210142907-50ea06ed5a9d h1:utj98F6D5jVv2tHYMsYzM6Z5sG71/W12Ivkd/SnFiN0=
github.com/cocoonlife/goflac v0.0.0-20170210142907-50ea06ed5a9d/go.mod h1:swNVb00X8NOH/qeHuqnqiyfecAnWlThLX+NbH8r6yHw=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220223152921-827e6c3f729f h1:4Dkx1l5Ex7pG/Xbs57L4IQd7mBgd6TO5rhP0BKP9PiI=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220223152921-827e6c3f729f/go.mod h1:/po1QgOh3xynbvi4sxdY6Iw8m5WPJfGGmry2boZD8fs=
github.com/cocoonlife/testify v0.0.0-20160218172820-792cc1faeb64 h1:LjPYdzoFSAJ5Tr/ElL8kzTJghXgpnOjJVbgd1UvZB1o=
github.com/cocoonlife/testify v0.0.0-20160218172820-792cc1faeb64/go.mod h1:LoCAz53rbPcqs8Da2BjB/yDy4gxMtiSQmqnYI/DGH+U=
github.com/dh1tw/gosamplerate v0.1.2 h1:oyqtZk67xB9B4l+vIZCZ3F0RYV/z66W58VOah11/ktI=
github.com/dh1tw/gosamplerate v0.1.2/go.mod h1:zooTyHpoR7hE+FLfdE3yjLHb2QA2NpMusNfuaZqEACM=
github.com/dsonck92/tta v0.2.0 h1:S0icGZIqhQpdOD67sA4FZPlrv88aLjDsUaE7cN03Kf0=