opus_codec/
constants.rs

1//! Crate-wide constants and small helpers
2
3use crate::types::SampleRate;
4
5/// Maximum samples per channel in a single Opus frame at 48 kHz.
6///
7/// 120 ms at 48 kHz = 0.120 * 48000 = 5760 samples.
8pub const MAX_FRAME_SAMPLES_48KHZ: usize = 5760;
9
10/// Maximum packet duration in milliseconds.
11pub const MAX_PACKET_DURATION_MS: usize = 120;
12
13/// Compute the maximum samples per channel for a frame at the given `sample_rate`.
14#[must_use]
15pub const fn max_frame_samples_for(sample_rate: SampleRate) -> usize {
16    // Scale linearly from the 48 kHz base.
17    // sample_rate.as_i32() is always positive given valid SampleRate enum values
18    (MAX_FRAME_SAMPLES_48KHZ * (sample_rate as usize)) / 48_000
19}