osmo-gmr: src/codec/private.h Source File

osmo-gmr 0.2.104-2b98 Osmocom GMR-1

private.h
Go to the documentation of this file.
1/* GMR-1 AMBE vocoder private header */
2
3/* (C) 2011-2019 by Sylvain Munaut <tnt@246tNt.com>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __OSMO_GMR1_CODEC_PRIVATE_H__
21#define __OSMO_GMR1_CODEC_PRIVATE_H__
22
32#include <stdint.h>
33
34
35#define AMBE_RATE 8000
39 enum ambe_frame_type
40{
41 AMBE_SPEECH,
42 AMBE_SILENCE,
43 AMBE_TONE,
44};
45
47 struct ambe_raw_params
48{
49 uint8_t pitch;
50 uint8_t pitch_interp;
51 uint8_t gain;
52 uint8_t v_uv;
54 uint8_t sf1_prba12;
55 uint8_t sf1_prba34;
56 uint8_t sf1_prba57;
57 uint8_t sf1_hoc[4];
59 uint8_t sf0_mag_interp;
60 uint8_t sf0_perr_14;
61 uint8_t sf0_perr_58;
62};
63
65 struct ambe_subframe
66{
67 float f0;
68 float f0log;
69 float w0;
70 int L;
71 int Lb[4];
72 int v_uv[8];
73 int Vl[56];
74 float gain;
75 float Mlog[56];
76 float Ml[56];
77};
78
80 struct ambe_synth
81{
82 int16_t u_prev;
83 float uw_prev[121];
84 float psi1;
85 float phi[56];
86 float SE;
87};
88
90 struct ambe_decoder
91{
92 float tone_phase_f1;
93 float tone_phase_f2;
95 struct ambe_subframe sf_prev;
97 struct ambe_synth synth;
98};
99
100/* From ambe.c */
101void ambe_decode_init(struct ambe_decoder *dec);
102void ambe_decode_fini(struct ambe_decoder *dec);
103
104int ambe_decode_frame(struct ambe_decoder *dec,
105 int16_t *audio, int N,
106 const uint8_t *frame, int bad);
107int ambe_decode_dtx(struct ambe_decoder *dec,
108 int16_t *audio, int N);
109
110/* From frame.c */
111void ambe_frame_unpack_raw(struct ambe_raw_params *rp, const uint8_t *frame);
112void ambe_frame_decode_params(struct ambe_subframe *sf,
113 struct ambe_subframe *sf_prev,
114 struct ambe_raw_params *rp);
115void ambe_subframe_expand(struct ambe_subframe *sf);
116
117/* From math.c */
118#define M_PIf (3.141592653589793f)
120float cosf_fast(float angle);
121float sinf_fast(float angle);
122void ambe_fdct(float *out, float *in, int N, int M);
123void ambe_idct(float *out, float *in, int N, int M);
124void ambe_fdft_fc(float *out_i, float *out_q, float *in, int N, int M);
125void ambe_idft_cf(float *out, float *in_i, float *in_q, int N, int M);
126
127/* From synth.c */
128void ambe_synth_init(struct ambe_synth *synth);
129void ambe_synth_enhance(struct ambe_synth *synth, struct ambe_subframe *sf);
130void ambe_synth_audio(struct ambe_synth *synth, int16_t *audio,
131 struct ambe_subframe *sf,
132 struct ambe_subframe *sf_prev);
133
134/* From tables.c */
135extern const uint8_t ambe_hpg_tbl[48][4];
136extern const float ambe_gain_tbl[256][2];
137extern const uint16_t ambe_v_uv_tbl[64];
138extern const float ambe_prba12_tbl[128][2];
139extern const float ambe_prba34_tbl[64][2];
140extern const float ambe_prba57_tbl[128][3];
141extern const float ambe_hoc0_tbl[128][4];
142extern const float ambe_hoc1_tbl[64][4];
143extern const float ambe_hoc2_tbl[64][4];
144extern const float ambe_hoc3_tbl[64][4];
145extern const float ambe_sf0_interp_tbl[4];
146extern const float ambe_sf0_perr14_tbl[64][4];
147extern const float ambe_sf0_perr58_tbl[32][4];
148
149/* From tone.c */
150int ambe_decode_tone(struct ambe_decoder *dec,
151 int16_t *audio, int N, const uint8_t *frame);
152
153
156#endif /* __OSMO_GMR1_CODEC_PRIVATE_H__ */
ambe_idct
void ambe_idct(float *out, float *in, int N, int M)
Inverse Discrete Cosine Transform (iDCT)
Definition: math.c:99
ambe_sf0_perr58_tbl
const float ambe_sf0_perr58_tbl[32][4]
Prediction Error [5:8] for subframe 0.
Definition: tables.c:1099
ambe_frame_type
ambe_frame_type
AMBE possible frame types.
Definition: private.h:40
ambe_subframe_expand
void ambe_subframe_expand(struct ambe_subframe *sf)
Expands the decoded subframe params to prepare for synthesis.
Definition: frame.c:357
ambe_synth_init
void ambe_synth_init(struct ambe_synth *synth)
Initialized Synthesizer state.
Definition: synth.c:297
ambe_prba57_tbl
const float ambe_prba57_tbl[128][3]
PRBA[5:7].
Definition: tables.c:555
ambe_sf0_perr14_tbl
const float ambe_sf0_perr14_tbl[64][4]
Prediction Error [1:4] for subframe 0.
Definition: tables.c:1031
ambe_frame_decode_params
void ambe_frame_decode_params(struct ambe_subframe *sf, struct ambe_subframe *sf_prev, struct ambe_raw_params *rp)
Decodes the speech parameters for both subframes from raw params.
Definition: frame.c:309
ambe_synth_enhance
void ambe_synth_enhance(struct ambe_synth *synth, struct ambe_subframe *sf)
Apply the spectral magnitude enhancement on the subframe.
Definition: synth.c:308
ambe_hoc3_tbl
const float ambe_hoc3_tbl[64][4]
HOC for last frequency block.
Definition: tables.c:955
cosf_fast
float cosf_fast(float angle)
Fast Cosinus approximation using a simple table.
Definition: math.c:51
ambe_v_uv_tbl
const uint16_t ambe_v_uv_tbl[64]
V/UV decisions (subframe 0 = low byte. MSBs = low freq)
Definition: tables.c:343
ambe_synth_audio
void ambe_synth_audio(struct ambe_synth *synth, int16_t *audio, struct ambe_subframe *sf, struct ambe_subframe *sf_prev)
Generate audio for a given subframe.
Definition: synth.c:378
ambe_fdct
void ambe_fdct(float *out, float *in, int N, int M)
Forward Discrete Cosine Transform (fDCT)
Definition: math.c:75
ambe_gain_tbl
const float ambe_gain_tbl[256][2]
Gain (subframe 0, subframe 1)
Definition: tables.c:83
ambe_hoc2_tbl
const float ambe_hoc2_tbl[64][4]
HOC for 3rd frequency block.
Definition: tables.c:887
ambe_decode_fini
void ambe_decode_fini(struct ambe_decoder *dec)
Release all resources associated with a decoder.
Definition: ambe.c:55
ambe_frame_unpack_raw
void ambe_frame_unpack_raw(struct ambe_raw_params *rp, const uint8_t *frame)
Unpack a frame into its raw encoded parameters.
Definition: frame.c:61
ambe_decode_dtx
int ambe_decode_dtx(struct ambe_decoder *dec, int16_t *audio, int N)
Generates audio for DTX period.
Definition: ambe.c:155
ambe_hoc1_tbl
const float ambe_hoc1_tbl[64][4]
HOC for 2nd frequency block.
Definition: tables.c:819
ambe_decode_frame
int ambe_decode_frame(struct ambe_decoder *dec, int16_t *audio, int N, const uint8_t *frame, int bad)
Decodes an AMBE frame to audio.
Definition: ambe.c:129
ambe_fdft_fc
void ambe_fdft_fc(float *out_i, float *out_q, float *in, int N, int M)
Forward Discrete Fourrier Transform (float->complex)
Definition: math.c:127
ambe_decode_init
void ambe_decode_init(struct ambe_decoder *dec)
Initializes decoder state.
Definition: ambe.c:40
ambe_prba34_tbl
const float ambe_prba34_tbl[64][2]
PRBA[3:4].
Definition: tables.c:487
ambe_sf0_interp_tbl
const float ambe_sf0_interp_tbl[4]
Interpolation ratios for subframe 0 magnitude prediction.
Definition: tables.c:1023
ambe_hoc0_tbl
const float ambe_hoc0_tbl[128][4]
HOC for 1st frequency block.
Definition: tables.c:687
ambe_idft_cf
void ambe_idft_cf(float *out, float *in_i, float *in_q, int N, int M)
Inverse Discret Fourrier Transform (complex->float)
Definition: math.c:158
sinf_fast
float sinf_fast(float angle)
Fast Sinus approximation using a simple table.
Definition: math.c:62
ambe_prba12_tbl
const float ambe_prba12_tbl[128][2]
PRBA[1:2].
Definition: tables.c:355
ambe_decode_tone
int ambe_decode_tone(struct ambe_decoder *dec, int16_t *audio, int N, const uint8_t *frame)
Decodes an AMBE tone frame.
Definition: tone.c:126
ambe_hpg_tbl
const uint8_t ambe_hpg_tbl[48][4]
Number of harmonics per group for a given L (starts at L=9)
Definition: tables.c:31
AMBE_SPEECH
@ AMBE_SPEECH
Speech frame.
Definition: private.h:41
AMBE_TONE
@ AMBE_TONE
Tone frame
Definition: private.h:43
AMBE_SILENCE
@ AMBE_SILENCE
Silence indication frame.
Definition: private.h:42
ambe_decoder
AMBE decoder state.
Definition: private.h:91
ambe_decoder::sf_prev
struct ambe_subframe sf_prev
Previous subframe.
Definition: private.h:95
ambe_decoder::tone_phase_f1
float tone_phase_f1
Phase frequency 1 for tone frames.
Definition: private.h:92
ambe_decoder::tone_phase_f2
float tone_phase_f2
Phase frequency 2 for tone frames.
Definition: private.h:93
ambe_decoder::synth
struct ambe_synth synth
Synthesizer state.
Definition: private.h:97
ambe_raw_params
AMBE encoded frame raw parameters.
Definition: private.h:48
ambe_raw_params::sf1_prba57
uint8_t sf1_prba57
sf1 PRBA[5,6,7] VQ
Definition: private.h:56
ambe_raw_params::sf1_prba34
uint8_t sf1_prba34
sf1 PRBA[3,4] VQ
Definition: private.h:55
ambe_raw_params::pitch
uint8_t pitch
Pitch.
Definition: private.h:49
ambe_raw_params::v_uv
uint8_t v_uv
V/UV decision VQ.
Definition: private.h:52
ambe_raw_params::pitch_interp
uint8_t pitch_interp
Pitch interpolation selection.
Definition: private.h:50
ambe_raw_params::sf1_hoc
uint8_t sf1_hoc[4]
sf1 HOCs VQ
Definition: private.h:57
ambe_raw_params::sf0_mag_interp
uint8_t sf0_mag_interp
sf0 mag interpolation selection
Definition: private.h:59
ambe_raw_params::sf0_perr_14
uint8_t sf0_perr_14
sf0 mag prediction error VQ [1,4]
Definition: private.h:60
ambe_raw_params::sf1_prba12
uint8_t sf1_prba12
sf1 PRBA[1,2] VQ
Definition: private.h:54
ambe_raw_params::gain
uint8_t gain
Gain VQ.
Definition: private.h:51
ambe_raw_params::sf0_perr_58
uint8_t sf0_perr_58
sf0 mag prediction error VQ [5,8]
Definition: private.h:61
ambe_subframe
AMBE subframe parameters.
Definition: private.h:66
ambe_subframe::f0log
float f0log
log2(f0)
Definition: private.h:68
ambe_subframe::Vl
int Vl[56]
Per-harmonic voicing state.
Definition: private.h:73
ambe_subframe::w0
float w0
fundamental frequency (rad/samp)
Definition: private.h:69
ambe_subframe::L
int L
Number of harmonics.
Definition: private.h:70
ambe_subframe::Ml
float Ml[56]
spectral magnitudes
Definition: private.h:76
ambe_subframe::Mlog
float Mlog[56]
log spectral magnitudes
Definition: private.h:75
ambe_subframe::f0
float f0
fundamental normalized frequency
Definition: private.h:67
ambe_subframe::v_uv
int v_uv[8]
Voicing state.
Definition: private.h:72
ambe_subframe::gain
float gain
Gain.
Definition: private.h:74
ambe_subframe::Lb
int Lb[4]
Harmonics per block.
Definition: private.h:71
ambe_synth
AMBE synthesizer state.
Definition: private.h:81
ambe_synth::u_prev
int16_t u_prev
Last 'u' of previous subframe.
Definition: private.h:82
ambe_synth::phi
float phi[56]
Current phase for each harmonic.
Definition: private.h:85
ambe_synth::psi1
float psi1
Current PSI angle for fundamental.
Definition: private.h:84
ambe_synth::uw_prev
float uw_prev[121]
Unvoiced data from previous subframe.
Definition: private.h:83
ambe_synth::SE
float SE
Current energy parameter.
Definition: private.h:86