The 2400 bit/s MBE codec
A voice codec on the MBE core (mbe.md): 48 parameter bits a 20 ms frame in a 72-bit frame with FEC (3600
bit/s on air). The frames are compatible with D-STAR's voice frames. Switch: CONFIG_MBE2400, off by default; no
mode uses the codec yet (build-config.md). Code: core/mbe/mbe2400.h.
D-STAR is a registered trademark of Icom Incorporated. RadioFoundry is not affiliated with or endorsed by Icom.
| Part | State |
|---|---|
| Frame: bit map, Golay FEC, whitening, interleave | written, host tested |
| Dequantizer and decoder | written, host tested; untested on air |
| Quantizer and encoder | written, host tested; untested on air |
1. Parameters
| Field | Bits | What |
|---|---|---|
| b0 | 7 | pitch code, 0 to 125; 126 and 127 mark frames played as silence (2.4) |
| b1 | 4 | voicing of four 1 kHz bands |
| b2 | 6 | gain step |
| b3 | 9 | first codebook vector (G2..G4) |
| b4 | 7 | second codebook vector (G5..G8) |
| b5..b8 | 4 each | the higher-order terms of blocks 1 to 4; b8's lowest bit is not sent (always 0) |
2. The dequantizer (mbe2400_unpack)
2.1 Pitch and voicing
f0 = 2^(-4.311767578125 - 0.021336 (b0 - 1)) of the sample rate: 409 Hz at b0 0, 1.47 % lower a step. The harmonic
count L (9 to 56) comes from a table by b0 (mbe2400_L); every harmonic is under 4 kHz.
Harmonic l is in band floor(l f0 / 1 kHz). Bit 3 - k of b1 voices band k: the highest bit the lowest band.
2.2 Gain and envelope
| Step | What |
|---|---|
| Gain | gamma = Dg[b2] + gamma' / 2, gamma' the last frame's (log2) |
| Codebooks | G2..G4 = PRBA24[b3], G5..G8 = PRBA58[b4] |
| Transform | R_i = sum over m = 2..8 of 2 G_m cos(pi (m - 1)(i - 1/2) / 8), i = 1..8 |
| Blocks | L harmonics in four blocks of J1..J4 by L (mbe2400_J). Block i: C1 = (R_{2i-1} + R_{2i}) / 2, C2 = (R_{2i-1} - R_{2i}) / (2 sqrt 2), C3..C6 from HOC_i[b(4 + i)], as many as the block has harmonics; C_k is 0 above C6 |
| Shape | T_j = C1 + 2 sum over k = 2..J of C_k cos(pi (k - 1)(j - 1/2) / J), for each harmonic j of the block |
| Amplitudes | log2 M_l = T_l - mean(T) + P_l + gamma - log2(L) / 2 |
P is the prediction (mbe_predict, mbe.md 4): 0.65 times the last frame's log2 amplitudes resampled to L
harmonics, mean removed, the value at harmonic 0 that of harmonic 1. A frame that resets the prediction leaves L' 30,
all amplitudes 0 and gamma' 0.
The codebooks are in mbe2400_tab.c, as integers that give every value exactly (G2..G4 in 1/16, the others in 1/128).
2.3 What the synthesis gets
| Parameter | Value |
|---|---|
| Amplitudes | log2 M_l plus the output gain, a factor of 4.2 (7, 4.4 dB down) to PCM units |
| Unvoiced bands | as a spectral density (MBE_UV_DENSITY, mbe.md 1.1) |
| Voiced phases | regenerated from the amplitudes (MBE_PHASE_REGEN, mbe.md 1.2) |
2.4 Frames played as silence
b0 126 or 127: the frame is not decoded. The decoder plays silence and resets the prediction. Tone frames are not written.
3. The frame (mbe2400_frame.c)
3.1 The three words
| Word | Bits | Coding |
|---|---|---|
| W0 | b0 bits 6..1, b2 bits 5..2, b3 bits 8..7 (12) | extended Golay (24,12): data bits 23..12, the overall parity bit 0 (core/fec/golay.h) |
| W1 | b3 bits 6..2, b4 bits 6..2, b5 bits 3..2 (12) | extended Golay (24,12), then whitened (3.3) |
| W2 | 24 bits (3.2) | none |
3.2 The third word
From bit 23 down: b5 bits 1..0, b6 bits 3..0, b7 bits 3..0, b8 bits 3..1, b1 bits 3..0, b2 bits 1..0, b3 bits 1..0, b4 bits 1..0, b0 bit 0.
3.3 Whitening
W1 is XORed with a sequence seeded from W0's 12 data bits d: x0 = 16 d, then 24 steps of x = (173 x + 13849) mod 65536; step s puts bit 15 of x on W1's bit 24 - s. A receiver removes the sequence with W0's corrected data.
3.4 Interleave
The frame is 72 bits, bit a in bit a mod 8 of byte a / 8 (least significant first). Air bit a = 24 blk + 2 p + h (blk 0..2, p 0..11, h 0..1) carries bit 8 - 4 blk + r[p] + 12 h of word w[p]:
| p | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| w[p] | 0 | 2 | 1 | 0 | 1 | 0 | 2 | 1 | 2 | 1 | 0 | 2 |
| r[p] | 2 | 3 | 3 | 3 | 1 | 1 | 2 | 2 | 0 | 0 | 0 | 1 |
The air positions of each word's bits 23 to 0:
| Word | Air bits |
|---|---|
| W0 | 7 1 11 21 31 25 35 45 55 49 59 69 6 0 10 20 30 24 34 44 54 48 58 68 |
| W1 | 5 15 9 19 29 39 33 43 53 63 57 67 4 14 8 18 28 38 32 42 52 62 56 66 |
| W2 | 3 13 23 17 27 37 47 41 51 61 71 65 2 12 22 16 26 36 46 40 50 60 70 64 |
3.5 Errors and bad frames
Hard decisions only. Each Golay word corrects up to three bit errors; four are detected (MBE2400_ERRS: the bits
corrected in W0 and W1, 4 for a failed word). A failed W1 is read as its 23-bit Golay word without the parity bit.
A frame is bad when W0 failed (its data, the pitch and gain bits and W1's whitening are unknown), or when W0 needed
three corrections and W1 failed. The decoder does not use a bad frame and repeats the last good one, up to three
times, each 1 dB quieter, then plays silence and resets the prediction (mbe_synth_conceal, mbe.md 2.1).
3.6 The silence frame
mbe2400_silence, 9E 8D 32 88 26 1A 3F 61 E8: b0..b8 = 124 0 4 165 41 10 7 7 10, no errors. The frame D-STAR
sends for a lost packet, decoded as near silence (a 65 Hz pitch, every band unvoiced, a low gain). The encoder
sends this frame for input of zeros.
4. The encoder (mbe2400_enc_frame)
| Step | What |
|---|---|
| Analysis | the MBE core's estimator (mbe.md 3) |
| Pitch | mbe_est_pitch on this codec's grid. A frame with no pitch is coded at b0 90 (108 Hz), every band unvoiced |
| Voicing and amplitudes | mbe_est_params_hz, four bands of 1 kHz, unvoiced levels as a density; the output gain taken off |
| Quantizer | mbe2400_pack (4.1) |
| Frame | mbe2400_frame_pack (3) |
4.1 The quantizer
The inverse of the dequantizer, step by step, on what the receiver reconstructs:
| Field | Choice |
|---|---|
| b1 | a band is voiced when more of its harmonics are voiced than not |
| Target | the amplitudes, none more than 96 dB under the loudest (a lower one is raised to that floor) |
| b2 | the gain step nearest the target's mean; chosen again after the shape (below) |
| R | the residual (target less the prediction, mean removed) per block by its DCT; C1 and C2 of each block give R_{2i-1} and R_{2i} |
| b3, b4 | G2..G8 from R by the inverse 8-point transform; the nearest PRBA24 vector to G2..G4, the nearest PRBA58 vector to G5..G8 (squared distance) |
| b5..b8 | per block, the nearest HOC vector to C3..C6 over the terms the block has; block 4 only among even codes |
The gain step sets the mean of the log amplitudes. The shape codebooks cannot follow a spectrum of a few strong harmonics over deep gaps (a tone, a whistle, a hum): the gaps are filled and the peaks cut, and with the mean right the frame plays up to 8 dB low, at a level that moves from frame to frame. So the quantizer runs its fields through the dequantizer once on a copy of the state, and moves b2 by the difference between the target's energy (the sum of the squared amplitudes) and the reconstructed frame's. The gain shifts every log amplitude alike, so one trial is enough. Speech moves by about 1 dB.
The quantizer then runs its fields through the dequantizer, so the two ends' prediction states stay equal.
5. Memory
| Part | Bytes |
|---|---|
Decoder state (mbe2400_state_t) |
124 |
| Synthesis core | mbe.md |
| Encoder: the estimator's state | 516 |
The encoder and the decoder can share the core's scratch.
6. Tests (tests/host/mbe2400Test.c)
| Test | What |
|---|---|
| Silence frame | 3.6's bytes give its fields with no corrections, and pack back bit for bit |
| Bit map | 20,000 random frames back; each bit of W2 alone at its air position; every air bit used once |
| FEC | 1 to 3 errors in a word corrected and counted; 4 detected; a frame with a failed W0 bad |
| Whitening | the sequence of 3.3 seen on air with W1's data 0; one bit of d inverts every step |
| Pitch | every code's f0 to 0.02 %; L rising, harmonics under 4 kHz |
| Voicing | every b1 against 2.1's bands at many pitches |
| Silence frames | b0 126 and 127 play silence and reset the state |
| Quantizer | the parameters the quantizer leaves equal the dequantizer's from its fields, bit for bit; the states stay equal; smooth envelopes back within 4 dB rms |
| Core options | a density an octave down plays 3 dB quieter; regenerated phases do not depend on the noise seed, match mbe.md 1.2's formula on a sloped envelope (sign and size) and follow a resonator's own phases |
| Concealment | repeats fade 1 dB each, then silence; a good frame resumes. Lost frames before any good one are silent; the prediction is held through the repeats and reset after them; after a frame played as silence the repeats are silent; which frames are bad by what the FEC found (3.5) |
| Random frames | 12,000 frames of random bytes, lost frames, loudest gains, silence frames and b0 126 or 127 in any order: the count of bad frames follows the FEC, the state stays in range, silence plays as silence afterwards |
| Wild parameters | 4,000 frames no dequantizer makes (any L, w0, amplitudes, flags, concealment policy) into the synthesis |
| Digital silence | zeros give the silence frame; the decoder plays near silence |
| Encoder input | full-scale noise, a square wave, DC, clicks, a 30 Hz hum, near silence: every frame valid, the receiver's prediction equal to the encoder's |
| Steady signals | two harmonics over deep gaps, one tone and 20 harmonics come back within 1 dB of the input's level, frame levels within 1 dB (2.5 dB for the 20 harmonics) |
| Encoder pitch | harmonic signals at six pitch codes across the range coded within a step, all bands voiced |
| Speech | tests/data/voice through the encoder and the decoder: band distance (16 bands of 250 Hz, level removed per frame) under 6 dB clean, 6.5 dB at 2 % bit errors and 7.5 dB at 5 % (frames lost), level within 1.5 dB; the two ends' prediction equal after a clean run. The full-rate codec's decodes there score about 5.4 to 5.8 dB |
tests/host/mbeExactTest.c holds CRCs of the codec's frames and samples for 12 s of made-up speech, random frames and
lost frames, the same with 64-bit products and with products from 16-bit halves (mbe.md 5). A change
meant to change the codec's output writes the new CRCs down with the reason.