Support any amount of channels on Opus decoding
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-07-21 16:18:48 +02:00
parent 8ce63bec9b
commit 1a8c741c35
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
4 changed files with 20 additions and 8 deletions

View file

@ -18,7 +18,7 @@ Collection of audio utilities for decoding/encoding/processing files and streams
| **FLAC** | [FLAC](https://xiph.org/flac/format.html), [Ogg](https://xiph.org/flac/ogg_mapping.html) | ✅ | `int32` | ✅ | Adjustable encoding compression level and block size.<br/>Decoding/encoding by [libFLAC](https://github.com/xiph/flac) via [goflac](https://git.gammaspectra.live/S.O.N.G/goflac).<br/>If [goflac](https://git.gammaspectra.live/S.O.N.G/goflac) codec is disabled, [mewkiz/flac](https://github.com/mewkiz/flac) decoder will be used. |
| **TTA** | [TTA](https://www.tausoft.org/en/true_audio_codec_format/) | ✅ | `int16, int32` | ✅ | Decoding/encoding via [S.O.N.G/go-tta](https://git.gammaspectra.live/S.O.N.G/go-tta). |
| **MP3** | [MP3](http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html) | ✅ | `2ch. int16` | ✅ | Adjustable encoding bitrate and mode.<br/>Decoding via [minimp3](https://github.com/kvark128/minimp3), encoding by [LAME](https://lame.sourceforge.io/) via [go-lame](https://github.com/viert/go-lame). |
| **Opus** | [Ogg](https://www.xiph.org/ogg/doc/framing.html) | ✅ | `2ch. int16` | ✅ | Adjustable encoding bitrate.<br/>Decoding/encoding by [libopus](https://github.com/xiph/opus) via [go-pus](https://git.gammaspectra.live/S.O.N.G/go-pus). |
| **Opus** | [Ogg](https://www.xiph.org/ogg/doc/framing.html) | ✅ | `int16` | ✅ | Adjustable encoding bitrate.<br/>Decoding/encoding by [libopus](https://github.com/xiph/opus) via [go-pus](https://git.gammaspectra.live/S.O.N.G/go-pus). Linked Ogg streams of different channel count are not supported. |
| **Vorbis** | [Ogg](https://www.xiph.org/ogg/doc/framing.html) | ✅ | `float32` | ❌ | Decoding by [jfreymuth/vorbis](https://github.com/jfreymuth/vorbis) via [jfreymuth/oggvorbis](https://github.com/jfreymuth/oggvorbis). |
| **AAC** | [ADTS](https://wiki.multimedia.cx/index.php/ADTS), ADIF*, MP4** | ✅ | `int16` | ✅ | Adjustable encoding bitrate and mode (LC, HEv1, HEv2).<br/>Decoding/encoding by [FDK-AAC](https://github.com/mstorsjo/fdk-aac) via [go-fdkaac](https://git.gammaspectra.live/S.O.N.G/go-fdkaac).<br/>If [go-fdkaac](https://git.gammaspectra.live/S.O.N.G/go-fdkaac) codec is disabled, [VisualOn AAC encoder](https://github.com/gen2brain/aac-go) will be used for limited encoding support.<br/>*ADIF only supported on encoding.<br/>**MP4 only supported on encoding, and fragmented MP4 currently. |
| **ALAC** | MP4* | ✅ | `int16, int32` | ✅ | Decoding/encoding by [libalac](https://git.gammaspectra.live/S.O.N.G/alac) via [go-alac](https://git.gammaspectra.live/S.O.N.G/go-alac).<br/>Disabled by default.<br/>*MP4 encoding only supported on fragmented MP4 currently. |

View file

@ -4,6 +4,7 @@ package opus
import (
"bytes"
"errors"
"fmt"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/filter"
@ -39,23 +40,34 @@ func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
return nil, err
}
source := audio.NewInt16Source(16, FixedSampleRate, 2)
info := stream.Info()
if info == nil {
return nil, errors.New("could not get stream information")
}
channelCount := info.ChannelCount
source := audio.NewInt16Source(16, FixedSampleRate, channelCount)
go func() {
defer stream.Close()
defer source.Close()
buf := make([]int16, 120*FixedSampleRate*2)
buf := make([]int16, 120*FixedSampleRate*channelCount)
for {
//Check channels each try to see if new links have different channel count
if stream.Channels() != channelCount {
//Channel count changed!
return
}
n, err := stream.ReadStereo(buf)
n, err := stream.Read(buf)
if err != nil {
return
}
if n > 0 {
source.IngestInt16(buf[:n*2], 16)
source.IngestInt16(buf[:n*channelCount], 16)
}
}
}()

2
go.mod
View file

@ -6,7 +6,7 @@ require (
git.gammaspectra.live/S.O.N.G/go-alac v0.0.0-20220421115623-d0b3bfe57e0f
git.gammaspectra.live/S.O.N.G/go-ebur128 v0.0.0-20220720163421-db0c1911921d
git.gammaspectra.live/S.O.N.G/go-fdkaac v0.0.0-20220515171305-ffb0aafe2a61
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220720100458-4421c708d144
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220721130634-3d5460c48ab6
git.gammaspectra.live/S.O.N.G/go-tta v0.2.1-0.20220226150007-096de1072bd6
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220515172202-6e490998d2a0
github.com/aam335/aac-go v0.0.0-20200408070016-52c23bd38988

4
go.sum
View file

@ -4,8 +4,8 @@ git.gammaspectra.live/S.O.N.G/go-ebur128 v0.0.0-20220720163421-db0c1911921d h1:3
git.gammaspectra.live/S.O.N.G/go-ebur128 v0.0.0-20220720163421-db0c1911921d/go.mod h1:5H4eVW9uknpn8REFr+C3ejhvXdncgm/pbGqKGC43gFY=
git.gammaspectra.live/S.O.N.G/go-fdkaac v0.0.0-20220515171305-ffb0aafe2a61 h1:YufhSTCS59H5CStqokGMb60RnSsqrp+GoZvzmC29wm4=
git.gammaspectra.live/S.O.N.G/go-fdkaac v0.0.0-20220515171305-ffb0aafe2a61/go.mod h1:pkWt//S9hLVEQaJDPu/cHHPk8vPpo/0+zHy0me4LIP4=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220720100458-4421c708d144 h1:mLKRevX5BbHTtBXXBEKlMOYwL9puZVPlG3+VsLb2IXk=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220720100458-4421c708d144/go.mod h1:vkoHSHVM9p6vAUmXAik0gvaLcIfiQYrD6bQqVpOulUk=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220721130634-3d5460c48ab6 h1:xWv02pzrOrQDtNGgcjDw9ZZvJCAuxLbZ6+h5QVVyqvk=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220721130634-3d5460c48ab6/go.mod h1:vkoHSHVM9p6vAUmXAik0gvaLcIfiQYrD6bQqVpOulUk=
git.gammaspectra.live/S.O.N.G/go-tta v0.2.1-0.20220226150007-096de1072bd6 h1:ITVVisbHPnUclp3PBkCbXFeBhOCBcOjPdgjJ9wRH3TI=
git.gammaspectra.live/S.O.N.G/go-tta v0.2.1-0.20220226150007-096de1072bd6/go.mod h1:cobkT8u8vq/+ngLy+feKS2M2ZT2HoCec5riA/0Cex3Q=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220515172202-6e490998d2a0 h1:imcnwHUqaAJzws41B8sCSp/sUmVranNjAX205Jr4Jc0=