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 (
-rflag) - Album gain calculation (
-aflag)
- Track gain calculation (
§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