This commit is contained in:
parent
96cfa831a0
commit
d8fbe580ce
|
@ -11,6 +11,7 @@ import (
|
|||
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/mp3"
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/opus"
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/tta"
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/vorbis"
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/audio/packetizer"
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/hasher"
|
||||
"io"
|
||||
|
@ -75,6 +76,9 @@ func TestOpusDecode(t *testing.T) {
|
|||
func TestMP3Decode(t *testing.T) {
|
||||
doTest(mp3.NewFormat(), ".mp3", t)
|
||||
}
|
||||
func TestVorbisDecode(t *testing.T) {
|
||||
doTest(vorbis.NewFormat(), ".vorbis", t)
|
||||
}
|
||||
|
||||
func TestHasher24(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
16
README.md
16
README.md
|
@ -12,13 +12,14 @@ Collection of audio utilities for decoding/encoding files and streams.
|
|||
|
||||
## Codecs supported
|
||||
|
||||
| Codec | Container | Decoder | Analyzer | Encoder | Notes |
|
||||
|:--------:|:---------:|:-------:|:--------:|:-------:|:------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| **FLAC** | FLAC, Ogg | ✅ | ✅ | ✅ | Adjustable encoding compression level and block size. |
|
||||
| **TTA** | TTA | ✅ | ✅ | ✅ | Only 16bit encoding |
|
||||
| **MP3** | MP3 | ✅ | - | ✅ | Adjustable encoding bitrate and mode. Decoding via [minimp3](https://github.com/kvark128/minimp3), encoding via [LAME](https://lame.sourceforge.io/). |
|
||||
| **Opus** | Ogg | ✅ | - | ✅ | Adjustable encoding bitrate. |
|
||||
| **AAC** | ADTS | ❌ | - | ✅ | Adjustable encoding bitrate and mode (LC, HEv2). |
|
||||
| Codec | Containers | Decoder | Analyzer | Encoder | Notes |
|
||||
|:----------:|:----------:|:-------:|:--------:|:-------:|:------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| **FLAC** | FLAC, Ogg | ✅ | ✅ | ✅ | Adjustable encoding compression level and block size. |
|
||||
| **TTA** | TTA | ✅ | ✅ | ✅ | Only 16bit encoding |
|
||||
| **MP3** | MP3 | ✅ | - | ✅ | Adjustable encoding bitrate and mode. Decoding via [minimp3](https://github.com/kvark128/minimp3), encoding via [LAME](https://lame.sourceforge.io/). |
|
||||
| **Opus** | Ogg | ✅ | - | ✅ | Adjustable encoding bitrate. |
|
||||
| **Vorbis** | Ogg | ✅ | - | ❌ | |
|
||||
| **AAC** | ADTS | ❌ | - | ✅ | Adjustable encoding bitrate and mode (LC, HEv2). |
|
||||
|
||||
## Container packetizers supported
|
||||
| Container | Packetizer | Keep Mode | Sample Number |
|
||||
|
@ -29,6 +30,7 @@ Collection of audio utilities for decoding/encoding files and streams.
|
|||
| **Ogg** | ✅ | ✅ | ✅* |
|
||||
| **ADTS** | ✅ | ✅ | ✅ |
|
||||
|
||||
*Sample number (absolute granule position) of Ogg depends on underlying codec implementing it.
|
||||
|
||||
## Dependencies
|
||||
### Go >= 1.18
|
||||
|
|
53
audio/format/vorbis/vorbis.go
Normal file
53
audio/format/vorbis/vorbis.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package vorbis
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
|
||||
libvorbis "github.com/jfreymuth/oggvorbis"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Format struct {
|
||||
}
|
||||
|
||||
func NewFormat() Format {
|
||||
return Format{}
|
||||
}
|
||||
|
||||
func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
|
||||
reader, err := libvorbis.NewReader(r)
|
||||
if err != nil {
|
||||
return audio.Source{}, err
|
||||
}
|
||||
|
||||
newChannel := make(chan []float32)
|
||||
|
||||
go func() {
|
||||
defer close(newChannel)
|
||||
|
||||
for {
|
||||
|
||||
buffer := make([]float32, 8192)
|
||||
|
||||
n, err := reader.Read(buffer)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if n > 0 {
|
||||
newChannel <- buffer[:n]
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
//We always get two channels via stereo api
|
||||
return audio.Source{
|
||||
Channels: reader.Channels(),
|
||||
SampleRate: reader.SampleRate(),
|
||||
Blocks: newChannel,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f Format) Identify(peek []byte, extension string) bool {
|
||||
return bytes.Compare(peek[:4], []byte{'O', 'g', 'g', 'S'}) == 0 || extension == "vorbis" || extension == "ogg"
|
||||
}
|
2
go.mod
2
go.mod
|
@ -9,6 +9,7 @@ require (
|
|||
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220305093419-2fd5e3285566
|
||||
github.com/dh1tw/gosamplerate v0.1.2
|
||||
github.com/edgeware/mp4ff v0.26.1
|
||||
github.com/jfreymuth/oggvorbis v1.0.3
|
||||
github.com/kvark128/minimp3 v0.0.0-20211109174940-101188771a65
|
||||
github.com/mewkiz/flac v1.0.7
|
||||
github.com/sssgun/mp3 v0.0.0-20170810093403-85f2ec632081
|
||||
|
@ -17,6 +18,7 @@ require (
|
|||
|
||||
require (
|
||||
github.com/icza/bitio v1.0.0 // indirect
|
||||
github.com/jfreymuth/vorbis v1.0.2 // indirect
|
||||
github.com/klauspost/cpuid v1.3.1 // indirect
|
||||
github.com/mewkiz/pkg v0.0.0-20190919212034-518ade7978e2 // indirect
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -21,6 +21,10 @@ github.com/icza/bitio v1.0.0 h1:squ/m1SHyFeCA6+6Gyol1AxV9nmPPlJFT8c2vKdj3U8=
|
|||
github.com/icza/bitio v1.0.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
|
||||
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k=
|
||||
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
|
||||
github.com/jfreymuth/oggvorbis v1.0.3 h1:MLNGGyhOMiVcvea9Dp5+gbs2SAwqwQbtrWnonYa0M0Y=
|
||||
github.com/jfreymuth/oggvorbis v1.0.3/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
|
||||
github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE=
|
||||
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
|
||||
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
|
||||
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
|
||||
github.com/kvark128/minimp3 v0.0.0-20211109174940-101188771a65 h1:8qfVQv7MSACDXadEwl1yjUKJ68yC9B7nR4cioEoCfH0=
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 76753f74f70be29619e3d4bfe7351c6d2e520e56
|
||||
Subproject commit af63704c59aa7f028cf261e95cf092b3a89fa0a5
|
Loading…
Reference in a new issue