1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! AMR narrowband, 3GPP TS 26.090 (prose) and TS 26.073 (the normative
//! fixed-point reference).
//!
//! 8 kHz, 160 samples per 20 ms frame, four 40-sample subframes, LP order 10,
//! eight rates from 4.75 to 12.2 kbit/s.
//!
//! # Relationship to the wideband implementation
//!
//! The two codecs are close relatives and it is tempting to share more than is
//! safe. They differ in ways that are invisible at a glance and produce audio
//! that sounds right while being wrong:
//!
//! - Narrowband uses **LSP/LSF**, wideband **ISP/ISF**. These are different
//! representations, not the same one at a different order.
//! - Narrowband has a **decoder post-filter**; wideband has none.
//! - Each narrowband rate has its **own algebraic codebook**, where wideband
//! has one family parameterised by width.
//! - `packed_size` in the two references uses different conventions: the
//! narrowband table includes the `ToC` byte, the wideband one does not.
//!
//! Anything genuinely shared lives in [`crate::fixed_point`] or in the
//! variant-agnostic modules one level up ([`super::payload`],
//! [`super::storage`], [`super::mode`]).
/// Frame size in samples, 20 ms at 8 kHz.
pub const L_FRAME: usize = 160;
/// Subframe size in samples; four to a frame.
pub const L_SUBFR: usize = 40;
/// Minimum pitch lag for every rate except 12.2 kbit/s.
pub const PIT_MIN: i16 = 20;
/// Minimum pitch lag at 12.2 kbit/s, which resolves the lag more finely and so
/// can afford to reach a shorter period.
pub const PIT_MIN_MR122: i16 = 18;
/// Maximum pitch lag, all rates.
pub const PIT_MAX: i16 = 143;
/// Length of the adaptive codebook's interpolation filter, one side plus one.
pub const L_INTERPOL: usize = 11;
/// Maximum pitch-sharpening factor, 0.7947 in Q14.
pub const SHARPMAX: i16 = 13017;
/// Tilt-compensation factor for the post-filter, 0.8 in Q15.
pub const MU: i16 = 26214;
/// Gain-smoothing factor for the post-filter's AGC, 0.9 in Q15.
pub const AGC_FAC: i16 = 29491;