Crate replaygain [−] [src]
This is little more than a wrapper around the replaygain analysis functionality provided by ffmpeg's af_replaygain. Unlike af_replaygain however, this gives you the actual values instead of just printing them to the console and then throwing them away. So close, yet so far.
Prerequisites
- Stereo audio (no other channel counts supported)
- Supported sample rates: 8000, 11025, 12000, 16000, 18900, 22050, 24000, 32000, 37800, 44100, 48000, 56000, 64000, 88200, 96000, 112000, 128000, 144000, 176400, 192000 (Hz)
- Float encoding (endianness handled on your side)
It sure doesn't lack irony that most users of this crate would probably actually use ffmpeg to convert their audio to a compatible format.
Usage
use replaygain::ReplayGain; let mut rg = ReplayGain::new(44100).unwrap(); let samples = []; // get data from somewhere rg.process_frame(&samples); let (gain, peak) = rg.finish();
Example
use std::{env, io, slice}; use std::io::Read; use replaygain::ReplayGain; fn main() { let mut args = env::args(); args.next().unwrap(); // executable name let param1 = args.next().unwrap(); let sample_rate = param1.parse().unwrap(); let mut rg = ReplayGain::new(sample_rate).unwrap(); // Just buffer everything up to keep things simple let mut input = Vec::new(); { let stdin = io::stdin(); let mut lock = stdin.lock(); lock.read_to_end(&mut input).unwrap(); } // Quick and dirty conversion let floats = unsafe { slice::from_raw_parts(&input[..] as *const _ as *const f32, input.len() / 4) }; rg.process_samples(floats); let (gain, peak) = rg.finish(); println!("track_gain = {} dB", gain); println!("track_peak = {}", peak); }
Structs
ReplayGain |