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
40{
44};
45
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];
60 uint8_t sf0_perr_14;
61 uint8_t sf0_perr_58;
62};
63
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
81{
82 int16_t u_prev;
83 float uw_prev[121];
84 float psi1;
85 float phi[56];
86 float SE;
87};
88
91{
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);
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__ */
void ambe_idct(float *out, float *in, int N, int M)
Inverse Discrete Cosine Transform (iDCT)
Definition: math.c:99
const float ambe_sf0_perr58_tbl[32][4]
Prediction Error [5:8] for subframe 0.
Definition: tables.c:1099
ambe_frame_type
AMBE possible frame types.
Definition: private.h:40
void ambe_subframe_expand(struct ambe_subframe *sf)
Expands the decoded subframe params to prepare for synthesis.
Definition: frame.c:357
void ambe_synth_init(struct ambe_synth *synth)
Initialized Synthesizer state.
Definition: synth.c:297
const float ambe_prba57_tbl[128][3]
PRBA[5:7].
Definition: tables.c:555
const float ambe_sf0_perr14_tbl[64][4]
Prediction Error [1:4] for subframe 0.
Definition: tables.c:1031
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
void ambe_synth_enhance(struct ambe_synth *synth, struct ambe_subframe *sf)
Apply the spectral magnitude enhancement on the subframe.
Definition: synth.c:308
const float ambe_hoc3_tbl[64][4]
HOC for last frequency block.
Definition: tables.c:955
float cosf_fast(float angle)
Fast Cosinus approximation using a simple table.
Definition: math.c:51
const uint16_t ambe_v_uv_tbl[64]
V/UV decisions (subframe 0 = low byte. MSBs = low freq)
Definition: tables.c:343
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
void ambe_fdct(float *out, float *in, int N, int M)
Forward Discrete Cosine Transform (fDCT)
Definition: math.c:75
const float ambe_gain_tbl[256][2]
Gain (subframe 0, subframe 1)
Definition: tables.c:83
const float ambe_hoc2_tbl[64][4]
HOC for 3rd frequency block.
Definition: tables.c:887
void ambe_decode_fini(struct ambe_decoder *dec)
Release all resources associated with a decoder.
Definition: ambe.c:55
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
int ambe_decode_dtx(struct ambe_decoder *dec, int16_t *audio, int N)
Generates audio for DTX period.
Definition: ambe.c:155
const float ambe_hoc1_tbl[64][4]
HOC for 2nd frequency block.
Definition: tables.c:819
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
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
void ambe_decode_init(struct ambe_decoder *dec)
Initializes decoder state.
Definition: ambe.c:40
const float ambe_prba34_tbl[64][2]
PRBA[3:4].
Definition: tables.c:487
const float ambe_sf0_interp_tbl[4]
Interpolation ratios for subframe 0 magnitude prediction.
Definition: tables.c:1023
const float ambe_hoc0_tbl[128][4]
HOC for 1st frequency block.
Definition: tables.c:687
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
float sinf_fast(float angle)
Fast Sinus approximation using a simple table.
Definition: math.c:62
const float ambe_prba12_tbl[128][2]
PRBA[1:2].
Definition: tables.c:355
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
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
Speech frame.
Definition: private.h:41
@ AMBE_TONE
Tone frame
Definition: private.h:43
@ AMBE_SILENCE
Silence indication frame.
Definition: private.h:42
AMBE decoder state.
Definition: private.h:91
struct ambe_subframe sf_prev
Previous subframe.
Definition: private.h:95
float tone_phase_f1
Phase frequency 1 for tone frames.
Definition: private.h:92
float tone_phase_f2
Phase frequency 2 for tone frames.
Definition: private.h:93
struct ambe_synth synth
Synthesizer state.
Definition: private.h:97
AMBE encoded frame raw parameters.
Definition: private.h:48
uint8_t sf1_prba57
sf1 PRBA[5,6,7] VQ
Definition: private.h:56
uint8_t sf1_prba34
sf1 PRBA[3,4] VQ
Definition: private.h:55
uint8_t pitch
Pitch.
Definition: private.h:49
uint8_t v_uv
V/UV decision VQ.
Definition: private.h:52
uint8_t pitch_interp
Pitch interpolation selection.
Definition: private.h:50
uint8_t sf1_hoc[4]
sf1 HOCs VQ
Definition: private.h:57
uint8_t sf0_mag_interp
sf0 mag interpolation selection
Definition: private.h:59
uint8_t sf0_perr_14
sf0 mag prediction error VQ [1,4]
Definition: private.h:60
uint8_t sf1_prba12
sf1 PRBA[1,2] VQ
Definition: private.h:54
uint8_t gain
Gain VQ.
Definition: private.h:51
uint8_t sf0_perr_58
sf0 mag prediction error VQ [5,8]
Definition: private.h:61
AMBE subframe parameters.
Definition: private.h:66
float f0log
log2(f0)
Definition: private.h:68
int Vl[56]
Per-harmonic voicing state.
Definition: private.h:73
float w0
fundamental frequency (rad/samp)
Definition: private.h:69
int L
Number of harmonics.
Definition: private.h:70
float Ml[56]
spectral magnitudes
Definition: private.h:76
float Mlog[56]
log spectral magnitudes
Definition: private.h:75
float f0
fundamental normalized frequency
Definition: private.h:67
int v_uv[8]
Voicing state.
Definition: private.h:72
float gain
Gain.
Definition: private.h:74
int Lb[4]
Harmonics per block.
Definition: private.h:71
AMBE synthesizer state.
Definition: private.h:81
int16_t u_prev
Last 'u' of previous subframe.
Definition: private.h:82
float phi[56]
Current phase for each harmonic.
Definition: private.h:85
float psi1
Current PSI angle for fundamental.
Definition: private.h:84
float uw_prev[121]
Unvoiced data from previous subframe.
Definition: private.h:83
float SE
Current energy parameter.
Definition: private.h:86