1 /* HR (GSM 06.20) codec wrapper */
4 * This file is part of gapk (GSM Audio Pocket Knife).
6 * gapk is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU 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.
11 * gapk 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 General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with gapk. If not, see <http://www.gnu.org/licenses/>.
25 #include <gsmhr/gsmhr.h>
27 #include "refsrc/typedefs.h"
28 #include "refsrc/homing.h"
29 #include "refsrc/sp_dec.h"
30 #include "refsrc/sp_enc.h"
33 #define EXPORT __attribute__((visibility("default")))
45 state = calloc(1, sizeof(struct gsmhr));
49 state->dec_reset_flg = 1;
55 gsmhr_exit(struct gsmhr *state)
61 gsmhr_encode(struct gsmhr *state, int16_t *hr_params, const int16_t *pcm)
64 Shortword pcm_b[F_LEN];
66 memcpy(pcm_b, pcm, F_LEN*sizeof(int16_t));
68 enc_reset_flg = encoderHomingFrameTest(pcm_b);
70 speechEncoder(pcm_b, hr_params);
79 gsmhr_decode(struct gsmhr *state, int16_t *pcm, const int16_t *hr_params)
81 #define WHOLE_FRAME 18
82 #define TO_FIRST_SUBFRAME 9
85 Shortword hr_params_b[22];
87 memcpy(hr_params_b, hr_params, 22*sizeof(int16_t));
89 if (state->dec_reset_flg)
90 dec_reset_flg = decoderHomingFrameTest(hr_params_b, TO_FIRST_SUBFRAME);
94 if (dec_reset_flg && state->dec_reset_flg) {
96 for (i=0; i<F_LEN; i++)
99 speechDecoder(hr_params_b, pcm);
102 if (!state->dec_reset_flg)
103 dec_reset_flg = decoderHomingFrameTest(hr_params_b, WHOLE_FRAME);
108 state->dec_reset_flg = dec_reset_flg;