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};
use std::path::Path;

// Apply +2 gain 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();

§Technical Details

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

Modules§

replaygain
ReplayGain analysis module

Structs§

ApeItem
APEv2 tag item
ApeTag
APEv2 tag collection
Mp3Analysis
Result of MP3 file analysis

Enums§

Channel
Channel selection for independent gain adjustment

Constants§

GAIN_STEP_DB
MP3 gain step size in dB (fixed by format specification)
MAX_GAIN
Maximum global_gain value
MIN_GAIN
Minimum global_gain value
TAG_MP3GAIN_ALBUM_MINMAX
TAG_MP3GAIN_MINMAX
TAG_MP3GAIN_UNDO
MP3Gain specific tag keys
TAG_REPLAYGAIN_ALBUM_GAIN
TAG_REPLAYGAIN_ALBUM_PEAK
TAG_REPLAYGAIN_TRACK_GAIN
ReplayGain tag keys
TAG_REPLAYGAIN_TRACK_PEAK

Functions§

analyze
Analyze an MP3 file and return gain statistics
apply_gain
Apply gain adjustment to MP3 file (lossless)
apply_gain_channel
Apply gain adjustment to a specific channel only (lossless)
apply_gain_channel_with_undo
Apply channel-specific gain and store undo information in APEv2 tag
apply_gain_db
Apply gain adjustment in dB (converted to nearest step)
apply_gain_with_undo
Apply gain and store undo information in APEv2 tag
apply_gain_with_undo_wrap
Apply gain with wrapping and store undo information in APEv2 tag
apply_gain_wrap
Apply gain with wrapping (values wrap around instead of clamping)
db_to_steps
Convert dB gain to MP3 gain steps
delete_ape_tag
Delete APEv2 tag from file
find_max_amplitude
Find maximum amplitude in an MP3 file Returns (max_amplitude, max_global_gain, min_global_gain)
is_mono
Check if an MP3 file is mono
read_ape_tag
Read APEv2 tag from file data
read_ape_tag_from_file
Read APEv2 tag from file
steps_to_db
Convert MP3 gain steps to dB
undo_gain
Undo gain changes based on APEv2 tag information
write_ape_tag
Write APEv2 tag to file