46 KiB
Kirika
Collection of audio utilities for decoding/encoding/processing files and streams.
- Not based on ffmpeg/libav/libavcodec/libavformat and alike
- Channel-based audio consumption/filter chain
- Raw decoded samples exposed
- AnalyzerChannel channels / mergers / splitters / trimmers
- Audio resampler
- Audio downmixing to stereo/mono
- Multi-codec decoder and encoder
- Multi-format packetizers
- ReplayGain 2.0 track/album calculator
Codecs supported
Codec | Containers | Decoder | Sample Analyzer | Sample Format | Encoder | Notes |
---|---|---|---|---|---|---|
FLAC | FLAC, Ogg | ✅ | ✅ | int32 |
✅ | Adjustable encoding compression level and block size. Decoding/encoding by libFLAC via goflac. If goflac codec is disabled, flacgo decoder/encoder will be used. |
TTA | TTA | ✅ | ✅ | int32 |
✅ | Decoding/encoding via S.O.N.G/go-tta. |
MP3 | MP3 | ✅ | ❌ | float32 |
✅ | Adjustable encoding bitrate and mode. Decoding via S.O.N.G/minimp3, encoding by LAME via go-lame. |
Opus | Ogg | ✅ | ❌ | float32 |
✅ | Adjustable encoding bitrate. Decoding/encoding by libopus via go-pus. Linked Ogg streams of different channel count are not supported. |
Vorbis | Ogg | ✅ | ❌ | float32 |
✅ | Decoding/encoding by libvorbis via go-vorbis. If go-vorbis is disabled, jfreymuth/vorbis via jfreymuth/oggvorbis decoder will be used. Linked Ogg streams of different channel count are not supported. |
AAC | ADTS, ADIF*, MP4** | ✅ | ❌ | int16 |
✅ | Adjustable encoding bitrate and mode (LC, HEv1, HEv2). Decoding/encoding by FDK-AAC via go-fdkaac. If go-fdkaac codec is disabled, VisualOn AAC encoder will be used for limited encoding support. *ADIF only supported on encoding. **MP4 only supported on encoding, and fragmented MP4 currently. |
ALAC | MP4* | ✅ | ✅ | int32 |
✅ | Decoding/encoding by libalac via go-alac. Disabled by default. *MP4 encoding only supported on fragmented MP4 currently. |
Container packetizers supported
Only output from Kirika's own encoders is supported.
Container | Packetizer | Keep Mode | Sample Numbers | Offset | Notes |
---|---|---|---|---|---|
FLAC | ✅ | ✅ | ✅ | ✅ | Uses custom Kirika packetizer. |
TTA | ❌ | - | - | - | |
MP3 | ✅ | ✅ | ✅ | ✅ | Uses sssgun/mp3 as a frame parser. |
Ogg | ✅ | ✅ | ✅* | ✅ | Uses custom Kirika packetizer. *Sample numbers (absolute granule position in Ogg) depend on underlying codec implementing it. Has been tested as working for Opus, FLAC |
ADTS | ✅ | ✅ | ✅ | ✅ | Uses Eyevinn/mp4ff for its ADTS frame parser. |
MP4 | ❌ | - | - | - | |
ADIF | ❌ | - | - | - |
Filters
Filter | Native Sample Format | Notes |
---|---|---|
Resample | float32 |
Changes input source sample rate to a different sample rate. If source sample rate equals sampleRate , returns source. |
Source Format | float32 int16 int32 |
Changes input source to a different format. |
Buffer | float32 int16 int32 |
Makes output source a buffered channel of the specified size. |
Block Size | float32 int16 int32 |
Adjusts input source blocks to a normalized block size. |
Real Time | float32 int16 int32 |
Outputs enough samples per second equal to the source sample rate. |
Volume | float32 int16 int32 |
Adjusts volume of all samples equally. If adjustement equals 1.0 , returns source. |
Stereo | float32 int16 int32 |
Makes input stereo. If source channels equals 2 , returns source. |
Mono | float32 int16 int32 |
Makes input mono. If source channels equals 1 , returns source. |
ReplayGain | float32 int16 int32 |
Creates a Volume filter with the specified ReplayGain parameters. |
Normalization | float32 |
Automatically adjusts volume according to short term audio loudness. |
Filter Chain
Allows chaining different filters together where one's output is the next one input.
Hashers
Several audio Analyzer hashers are implemented. List of current ones:
- CRC32
- SHA256
- SHA1
- MD5
- AccurateRipV1
- AccurateRipV1 (Start mode)
- AccurateRipV2
- AccurateRipV2 (Start mode)
Dependencies
Go >= 1.20
libFLAC (required by goflac)
sudo apt install libflac-dev
libopus and libopusfile (required by go-pus)
sudo apt install libopus-dev libopusfile-dev
libopusenc (required by go-pus)
git clone --depth 1 https://gitlab.xiph.org/xiph/libopusenc.git
cd libopusenc
./autogen.sh
./configure --prefix /usr
make
sudo make install
libvorbis (required by go-vorbis)
sudo apt install libvorbis-dev
FDK AAC Codec Library (required by go-fdkaac)
sudo apt install libfdk-aac-dev
Alternatively if package cannot be found under your distribution:
git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git
cd fdk-aac
./autogen.sh
./configure --prefix /usr
make -j$(nproc)
sudo make install
libalac (required by go-alac)
git clone --depth 1 https://git.gammaspectra.live/S.O.N.G/alac.git
cd alac
autoreconf -fi
./configure --prefix /usr
make -j$(nproc)
sudo make install
LAME (required by go-lame)
sudo apt install libmp3lame-dev
libsamplerate (required by gosamplerate)
sudo apt install libsamplerate0-dev
libebur128 (required by go-ebur128)
sudo apt install libebur128-dev
Build tags
Several Golang build tags exist to change which features are included in the project.
CGO_ENABLED=0
This tag disables CGO support, and disables any formats/codecs that require it. Some other features will degrade or be less performant, or alternative decoders be used.
Additionally, libebur128 (used for normalization) will be disabled.
Some tests cannot be completed in this mode.
Codecs supported, CGO_ENABLED=0
Codec | Containers | Decoder | Sample Analyzer | Sample Format | Encoder | Notes |
---|---|---|---|---|---|---|
FLAC | FLAC | ✅ | ✅ | int32 |
✅* | Decoding/encoding by flacgo. *Encoder only supports Verbatim / Constant frame prediction modes, offering almost no compression. |
TTA | TTA | ✅ | ✅ | int32 |
✅ | Decoding/encoding by S.O.N.G/go-tta. |
MP3 | MP3 | ✅ | ❌ | 2ch. float32 |
❌ | Decoding by S.O.N.G/go-mp3. |
Opus | - | ❌ | - | - | ❌ | |
Vorbis | Ogg | ✅ | ❌ | float32 |
❌ | Decoding by jfreymuth/vorbis via jfreymuth/oggvorbis. |
AAC | - | ❌ | - | - | ❌ | |
ALAC | - | ❌ | - | - | ❌ |
disable_format_[format]
This tag disables support for the specified format/codec. This does not affect packetizers.
Current implemented [format]: aac, alac, flac, mp3, opus, tta, vorbis
. Disabling flac
will break tests.
disable_codec_libfdk-aac
This tag disables the libfdk-aac support for decoding/encoding AAC. This is available for specific problems with the FDK license that conflicts with your needs or policy.
If this tag is enabled, yet aac
support remains enabled, an AAC encoder (but not decoder) will be built with the VisualOn AAC encoder bindings, which are vastly worse.
disable_codec_libflac
This tag disables the libFLAC support for decoding/encoding FLAC.
If this tag is enabled, yet flac
support remains enabled, flacgo FLAC decoder/encoder will be used.
disable_codec_libvorbis
This tag disables the libvorbis support for decoding/encoding Vorbis.
If this tag is enabled, yet vorbis
support remains enabled, jfreymuth/vorbis via jfreymuth/oggvorbis Vorbis decoder will be used.
disable_codec_lame
This tag disables the LAME support for encoding MP3. This is available for specific problems with the LGPL v2 license that conflicts with your needs or policy.
MP3 decoding is not affected by this tag.
disable_codec_tta
This tag disables the TTA support for decoding/encoding TTA. This is available for specific problems with the LGPL v3 license that conflicts with your needs or policy.
This is equivalent to disable_format_tta
.
enable_codec_libalac
This tag enables the libalac support for decoding/encoding ALAC.
This library has vast security issues, enable on your own risk. An alternate codec for decoding might be added in the future.
Utilities
cmd/decode
Example application that decodes files and provides some general information about the decoded streams, and produces an MD5 hash of the sample data.
Run via $ go run git.gammaspectra.live/S.O.N.G/Kirika/cmd/decode -input "resources/samples/cYsmix - Haunted House/11. The Great Rigid Desert.flac"
Example output:
2023/01/29 12:58:27 File: resources/samples/cYsmix - Haunted House/11. The Great Rigid Desert.flac
2023/01/29 12:58:27 Available decoders:
2023/01/29 12:58:27 flac: reference libFLAC 1.3.3 20190804 (S.O.N.G/goflac) (analyzer)
2023/01/29 12:58:27 Decoding as int32 24-bit @ 44100Hz 2 channel(s)
2023/01/29 12:58:27 Decoded 17323031 sample(s)
2023/01/29 12:58:27 Processed 4230 blocks(s) (avg 4095.28 sample(s) per block)
2023/01/29 12:58:27 Duration 6m32.812494331s
2023/01/29 12:58:27 MD5 hash: c1a62472ca433e6c4b02e842a8348660
2023/01/29 12:58:27 Check via $ ffmpeg -hide_banner -loglevel error -i "resources/samples/cYsmix - Haunted House/11. The Great Rigid Desert.flac" -vn -c:a pcm_s24le -f md5 -
2023/01/29 12:58:27 Took 385.02864ms
Licenses
Kirika
Copyright (c) 2022 Kirika Contributors All rights reserved.
Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Dependencies
Subdependencies that are not cgo-based are denoted in cursive.
Dependency | Language | License | Notes |
---|---|---|---|
S.O.N.G/go-alac | Go | BSD 2-Clause | |
S.O.N.G/alac | C++/C | Apache 2.0 | Can be linked by cgo as a shared library. |
S.O.N.G/go-ebur128 | Go | BSD 2-Clause | |
jiixyj/libebur128 | C | MIT | Can be linked by cgo as a shared library. |
S.O.N.G/go-fdkaac | Go | MIT | |
mstorsjo/fdk-aac | C++/C | FDK License, BSD-like | Does not include patent grants. Considered free by Red hat, Fedora, GNU, FSF; and non-free by Debian. Can be linked by cgo as a shared library. |
S.O.N.G/go-pus | Go | MIT | |
xiph/opus | C | BSD 3-Clause | Read extra license details on the official site. Can be linked by cgo as a shared library. |
xiph/opusfile | C | BSD 3-Clause | Can be linked by cgo as a shared library. |
xiph/ogg | C | BSD 3-Clause | Can be linked by cgo as a shared library. |
xiph/libopusenc | C | BSD 3-Clause | Can be linked by cgo as a shared library. |
S.O.N.G/go-vorbis | Go | BSD 2-Clause | |
xiph/vorbis | C | BSD 3-Clause | Can be linked by cgo as a shared library. |
S.O.N.G/go-tta | Go | LGPL v3 | |
S.O.N.G/goflac | Go | BSD 3-Clause | |
xiph/flac | C | BSD 3-Clause | Read extra license details on the official site. Can be linked by cgo as a shared library. |
dh1tw/gosamplerate | Go | BSD 2-Clause | |
libsndfile/libsamplerate | C | BSD 2-Clause | Can be linked by cgo as a shared library. |
Eyevinn/mp4ff | Go | MIT | |
S.O.N.G/voaac-go | Go | Apache 2.0 | |
mstorsjo/vo-aacenc | C | Apache 2.0 | Subdependency and included as part of S.O.N.G/voaac-go. |
S.O.N.G/go-mp3 | Go | Apache 2.0 | |
jfreymuth/oggvorbis | Go | MIT | |
jfreymuth/vorbis | Go | MIT | Subdependency of jfreymuth/oggvorbis. |
S.O.N.G/minimp3 | Go | MIT | |
lieff/minimp3 | C | CC0 1.0 | Subdependency and included as part of S.O.N.G/minimp3. |
S.O.N.G/flacgo | Go | The Unlicense | |
icza/bitio | Go | Apache 2.0 or LGPL v2.1 | Subdependency of S.O.N.G/flacgo. |
sssgun/mp3 | Go | MIT | |
viert/go-lame | Go | MIT | |
LAME | C | LGPL v2 | Can be linked by cgo as a shared library. |