pub struct WaveformAnalyzer { /* private fields */ }Expand description
Computes peak and RMS amplitude per time interval for an audio file.
Decodes audio via AudioDecoder (requesting packed f32 output so that
per-sample arithmetic needs no format dispatch) and computes, for each
configurable interval, the peak and RMS amplitudes in dBFS. The resulting
Vec<WaveformSample> is designed for waveform display rendering.
§Examples
use ff_decode::WaveformAnalyzer;
use std::time::Duration;
let samples = WaveformAnalyzer::new("audio.mp3")
.interval(Duration::from_millis(50))
.run()?;
for s in &samples {
println!("{:?}: peak={:.1} dBFS rms={:.1} dBFS",
s.timestamp, s.peak_db, s.rms_db);
}Implementations§
Source§impl WaveformAnalyzer
impl WaveformAnalyzer
Sourcepub fn new(input: impl AsRef<Path>) -> Self
pub fn new(input: impl AsRef<Path>) -> Self
Creates a new analyzer for the given audio file.
The default sampling interval is 100 ms. Call
interval to override it.
Sourcepub fn interval(self, d: Duration) -> Self
pub fn interval(self, d: Duration) -> Self
Sets the sampling interval.
Peak and RMS are computed independently for each interval of this
length. Passing Duration::ZERO causes run to
return DecodeError::AnalysisFailed.
Default: 100 ms.
Sourcepub fn run(self) -> Result<Vec<WaveformSample>, DecodeError>
pub fn run(self) -> Result<Vec<WaveformSample>, DecodeError>
Runs the waveform analysis and returns one WaveformSample per interval.
The timestamp of each sample is the start of its interval. Audio
is decoded as packed f32 samples; the decoder performs any necessary
format conversion automatically.
§Errors
DecodeError::AnalysisFailed— interval isDuration::ZERO.DecodeError::FileNotFound— input path does not exist.- Any other
DecodeErrorpropagated fromAudioDecoder.