MoosicBox Audio Encoder
Basic audio encoding utilities with feature-gated support for multiple formats.
Overview
The MoosicBox Audio Encoder package provides:
- Feature-Gated Modules: Optional encoding support for different audio formats
- Format-Specific Encoders: Separate modules for different encoding formats
- Minimal Core: Lightweight base with optional format extensions
- Encode Info Structure: Basic encoding result information
Current Implementation
Core Components
- EncodeInfo: Structure containing encoding results (output size, input consumed)
- Feature-Gated Modules: Format-specific encoding implementations
Available Features
aac: Advanced Audio Coding encoder moduleflac: Free Lossless Audio Codec encoder modulemp3: MPEG Layer III encoder moduleopus: Opus codec encoder module
Installation
Cargo Dependencies
# All features enabled by default
[]
= { = "../audio_encoder" }
# Or disable default features and enable specific formats only
= {
path = "../audio_encoder",
= false,
= ["mp3", "flac"]
}
Usage
Basic Encode Info
use EncodeInfo;
Format-Specific Encoding
// AAC encoding (requires "aac" feature)
use ;
// FLAC encoding (requires "flac" feature)
use ;
// MP3 encoding (requires "mp3" feature)
use ;
// Opus encoding (requires "opus" feature)
use ;
Implementation Notes
- The package provides a minimal core with feature-gated format modules
- Each audio format is implemented in its own module behind a feature flag
- The
EncodeInfostruct provides standardized encoding result information - Actual encoding functionality is contained within the format-specific modules
- All features are enabled by default, but can be disabled if needed
Module APIs
Each encoder module provides consistent functions:
- AAC (
aacfeature):encoder_aac()creates encoder,encode_aac(encoder, input, buf)encodes i16 PCM data - FLAC (
flacfeature):encoder_flac()creates encoder,encode_flac(encoder, input, buf)encodes i32 PCM data - MP3 (
mp3feature):encoder_mp3()creates encoder,encode_mp3(encoder, input)encodes i16 PCM data and returns output buffer - Opus (
opusfeature):encoder_opus()creates encoder,encode_opus_float(encoder, input, output)encodes f32 PCM data, andencode_audiopus(samples)produces length-prefixed Opus packets
Opus/Ogg helpers exported by the opus module:
OpusWrite::new(path)creates an Ogg/Opus stream writer that implementsstd::io::Writewrite_ogg(file, content)writes one Ogg packet with end-of-stream markerread_write_ogg(read, write)copies packets from one Ogg stream to another
Features
- Default: All encoding formats are enabled by default (
aac,flac,mp3,opus) aac: Enables AAC encoding module via fdk-aacflac: Enables FLAC encoding module via flacencmp3: Enables MP3 encoding module via mp3lame-encoderopus: Enables Opus encoding module via audiopus/opus, includes OGG container support
Development Status
This package currently provides:
- Core Structure:
EncodeInfofor encoding results - Module Framework: Feature-gated organization for different encoders
- Extensible Design: Easy addition of new encoding formats
The actual encoding implementations are contained within the feature-gated modules. Check the individual module documentation for specific encoding capabilities and APIs.
Usage Patterns
// Always available - core types
use EncodeInfo;
// Feature-gated - format-specific encoders
use ;
use ;
This design allows consumers to include only the encoding formats they need by disabling default features, reducing binary size and dependencies.