Skip to main content

Crate mp3rgain

Crate mp3rgain 

Source
Expand description

§mp3rgain

Lossless MP3 volume adjustment library - a modern mp3gain replacement.

This library provides lossless MP3 volume adjustment by modifying the global_gain field in each frame’s side information.

§Features

  • Lossless: No re-encoding, preserves audio quality
  • Fast: Direct binary manipulation, no audio decoding
  • Compatible: Works with all MP3 files (MPEG1/2/2.5 Layer III)
  • Reversible: Changes can be undone by applying negative gain

§Optional Features

  • replaygain: Enable ReplayGain analysis (requires symphonia)
    • Track gain calculation (-r flag)
    • Album gain calculation (-a flag)

§Example

use mp3rgain::{apply_gain, apply_gain_db, analyze, GainOptions, Channel};
use std::path::Path;

// Simple gain adjustment: +2 steps (+3.0 dB)
let frames = apply_gain(Path::new("song.mp3"), 2).unwrap();
println!("Modified {} frames", frames);

// Or specify gain in dB directly
let frames = apply_gain_db(Path::new("song.mp3"), 4.5).unwrap();

// Builder pattern for advanced options
GainOptions::new(5)
    .wrap(true)
    .undo(true)
    .apply(Path::new("song.mp3")).unwrap();

// Channel-specific gain with undo support
GainOptions::new(3)
    .channel(Channel::Left)
    .undo(true)
    .apply(Path::new("song.mp3")).unwrap();

§Modules

  • analysis - MP3 file analysis and amplitude detection
  • gain - Gain adjustment operations and the GainOptions builder
  • ape - APEv2 tag reading, writing, and management
  • replaygain - ReplayGain loudness analysis
  • mp4meta - MP4/M4A metadata handling
  • aac - AAC bitstream parsing (feature-gated)

§Technical Details

Each gain step equals 1.5 dB (fixed by MP3 specification). The global_gain field is 8 bits, allowing values 0-255.

Re-exports§

pub use analysis::analyze;
pub use analysis::find_max_amplitude;
pub use analysis::is_mono;
pub use analysis::ChannelMode;
pub use analysis::MaxAmplitudeResult;
pub use analysis::Mp3Analysis;
pub use analysis::MpegVersion;
pub use ape::delete_ape_tag;
pub use ape::read_ape_tag;
pub use ape::read_ape_tag_from_file;
pub use ape::write_ape_tag;
pub use ape::ApeItem;
pub use ape::ApeTag;
pub use ape::TAG_MP3GAIN_ALBUM_MINMAX;
pub use ape::TAG_MP3GAIN_MINMAX;
pub use ape::TAG_MP3GAIN_UNDO;
pub use ape::TAG_REPLAYGAIN_ALBUM_GAIN;
pub use ape::TAG_REPLAYGAIN_ALBUM_PEAK;
pub use ape::TAG_REPLAYGAIN_TRACK_GAIN;
pub use ape::TAG_REPLAYGAIN_TRACK_PEAK;
pub use error::Error;
pub use error::Result;
pub use gain::apply_gain;
pub use gain::apply_gain_db;
pub use gain::db_to_steps;
pub use gain::steps_to_db;
pub use gain::undo_gain;
pub use gain::Channel;
pub use gain::GainOptions;
pub use gain::GAIN_STEP_DB;
pub use gain::MAX_GAIN;
pub use gain::MIN_GAIN;
pub use id3v2::delete_id3v2_replaygain;
pub use id3v2::read_id3v2_replaygain;
pub use id3v2::undo_gain_id3v2;
pub use id3v2::write_id3v2_replaygain;
pub use id3v2::write_id3v2_undo;
pub use id3v2::Id3v2ReplayGain;

Modules§

aac
AAC bitstream parser for locating global_gain fields in M4A/MP4 files.
analysis
ape
error
Custom error types for mp3rgain.
gain
id3v2
ID3v2 TXXX frame storage for ReplayGain and undo tags.
mp4meta
MP4/M4A metadata handling for ReplayGain tags
replaygain
ReplayGain analysis module