Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions benches/ebur128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ fn get_results_c(ebu: &EbuR128C, mode: ModeC) {
if mode.contains(ModeC::S) {
black_box(ebu.loudness_shortterm().unwrap());
}
black_box(ebu.loudness_window(1).unwrap());
if mode.intersects(ModeC::M | ModeC::S | ModeC::I | ModeC::LRA) {
black_box(ebu.loudness_window(1).unwrap());
}

if mode.contains(ModeC::LRA) {
black_box(ebu.loudness_range().unwrap());
Expand Down Expand Up @@ -52,7 +54,9 @@ fn get_results(ebu: &EbuR128, mode: Mode) {
if mode.contains(Mode::S) {
black_box(ebu.loudness_shortterm().unwrap());
}
black_box(ebu.loudness_window(1).unwrap());
if mode.intersects(Mode::M | Mode::S | Mode::I | Mode::LRA) {
black_box(ebu.loudness_window(1).unwrap());
}

if mode.contains(Mode::LRA) {
black_box(ebu.loudness_range().unwrap());
Expand Down
17 changes: 9 additions & 8 deletions benches/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
black_box(2),
black_box(false),
black_box(false),
black_box(true),
);
drop(black_box(f));
})
Expand Down Expand Up @@ -79,7 +80,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}

{
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Interleaved", |b| {
b.iter(|| {
f.process(
Expand All @@ -91,7 +92,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
})
});

let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Planar", |b| {
b.iter(|| {
f.process(
Expand Down Expand Up @@ -143,7 +144,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}

{
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Interleaved", |b| {
b.iter(|| {
f.process(
Expand All @@ -155,7 +156,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
})
});

let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Planar", |b| {
b.iter(|| {
f.process(
Expand Down Expand Up @@ -207,7 +208,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}

{
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Interleaved", |b| {
b.iter(|| {
f.process(
Expand All @@ -219,7 +220,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
})
});

let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Planar", |b| {
b.iter(|| {
f.process(
Expand Down Expand Up @@ -271,7 +272,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}

{
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Interleaved", |b| {
b.iter(|| {
f.process(
Expand All @@ -283,7 +284,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
})
});

let mut f = filter::Filter::new(48_000, 2, *sample_peak, false);
let mut f = filter::Filter::new(48_000, 2, *sample_peak, false, true);
group.bench_function("Rust/Planar", |b| {
b.iter(|| {
f.process(
Expand Down
24 changes: 20 additions & 4 deletions src/ebur128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ bitflags! {
/// can call [`EbuR128::loudness_range`](struct.EbuR128.html#method.loudness_range)
const LRA = 0b00001000 | Mode::S.bits;
/// can call [`EbuR128::sample_peak`](struct.EbuR128.html#method.sample_peak)
const SAMPLE_PEAK = 0b00010000 | Mode::M.bits;
const SAMPLE_PEAK = 0b00010000;
/// can call [`EbuR128::true_peak`](struct.EbuR128.html#method.true_peak)
const TRUE_PEAK = 0b00110001;
const TRUE_PEAK = 0b00110000;
/// uses histogram algorithm to calculate loudness
const HISTOGRAM = 0b01000000;
}
Expand Down Expand Up @@ -300,15 +300,22 @@ impl EbuR128 {
let history = usize::MAX;
let samples_in_100ms = (rate as usize + 5) / 10;

let calculate_loudness = mode.intersects(Mode::M | Mode::S | Mode::I | Mode::LRA);
let window = if mode.contains(Mode::S) {
3000
} else if mode.contains(Mode::M) {
400
} else if mode.intersects(Mode::SAMPLE_PEAK | Mode::TRUE_PEAK) {
0
} else {
return Err(Error::InvalidMode);
};

let audio_data = Self::allocate_audio_data(channels, rate, window)?;
let audio_data = if window > 0 {
Self::allocate_audio_data(channels, rate, window)?
} else {
Vec::new().into_boxed_slice()
};
// start at the beginning of the buffer
let audio_data_index = 0;

Expand All @@ -324,6 +331,7 @@ impl EbuR128 {
channels,
mode.contains(Mode::SAMPLE_PEAK),
mode.contains(Mode::TRUE_PEAK),
calculate_loudness,
);

let channel_map = default_channel_map(channels);
Expand Down Expand Up @@ -448,7 +456,11 @@ impl EbuR128 {
return Ok(());
}

self.audio_data = Self::allocate_audio_data(channels, rate, self.window)?;
self.audio_data = if self.window > 0 {
Self::allocate_audio_data(channels, rate, self.window)?
} else {
Vec::new().into_boxed_slice()
};

if self.channels != channels {
self.channels = channels;
Expand All @@ -462,11 +474,15 @@ impl EbuR128 {
self.samples_in_100ms = (rate as usize + 5) / 10;
}

let calculate_loudness = self
.mode
.intersects(Mode::M | Mode::S | Mode::I | Mode::LRA);
self.filter = crate::filter::Filter::new(
rate,
channels,
self.mode.contains(Mode::SAMPLE_PEAK),
self.mode.contains(Mode::TRUE_PEAK),
calculate_loudness,
);

// the first block needs 400ms of audio data
Expand Down
Loading
Loading