Documentation
¶
Overview ¶
Package mp3 provides a pure-Go MP3 encoder used to compress completed call audio before it is streamed to broadcast aggregators (Broadcastify Calls, RdioScanner, OpenMHz, Icecast).
It wraps the fixed-point Shine encoder, so the daemon keeps its zero-CGO single-binary guarantee — no libmp3lame / libshine at build or runtime. Shine supports the MPEG-1, MPEG-2 and MPEG-2.5 sample-rate families, so 8 kHz digital-voice audio encodes directly with no resample stage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BitrateFor ¶ added in v0.6.6
BitrateFor returns the CBR bitrate, in bits per second, the encoder uses for audio at sampleRate. Shine hard-codes 128 kbps, which is wrong on two counts for the low sample rates GopherTrunk records at:
- 128 kbps is not even a legal Layer-III bitrate for the MPEG-2.5 family (8/11.025/12 kHz), so Shine writes an out-of-range bitrate index that corrupts every frame header.
- More subtly, Shine's single-granule frames (every rate below 32 kHz) desync their bit-reservoir stuffing once the per-frame budget grows past roughly 3300 bits (~420 bytes/frame), emitting oversized frames that no demuxer can follow. This is why an 8 kHz call uploaded to Rdio Scanner transcodes to silence / "Invalid data found".
So each single-granule family gets the highest standard bitrate that keeps a frame comfortably under that limit — 32 kbps for MPEG-2.5, 64 kbps for MPEG-2 — both well above transparent for 8 kHz mono voice. The MPEG-1 rates (≥32 kHz) split each frame into two granules, halving the per-granule budget, so they keep Shine's 128 kbps default. Callers that pace a stream by bitrate (Icecast) use this so their timing tracks the real encoder output.
func Encode ¶
Encode compresses mono 16-bit PCM sampled at sampleRate Hz into a complete MP3 byte stream. The input is treated as a single channel; callers with stereo audio must downmix first.
func EncodeWAVFile ¶
EncodeWAVFile reads a 16-bit PCM mono WAV file from path and returns the equivalent MP3 byte stream plus the source sample rate.
Types ¶
This section is empty.