blob: 182eb73394126e4fc87b12579853b4785efde20d [file] [log] [blame]
Sylvain Munautcca11552010-10-24 18:32:44 +02001/* FR (GSM 06.10) codec */
2
3/*
4 * This file is part of gapk (GSM Audio Pocket Knife).
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include <gapk/codecs.h>
Harald Welte7a046242014-05-08 19:18:01 +020021#include <gapk/benchmark.h>
Sylvain Munautcca11552010-10-24 18:32:44 +020022
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010023#include "config.h"
24
25
26#ifdef HAVE_LIBGSM
27
28/* Find header */
29#ifdef HAVE_GSM_H
30# include <gsm.h>
31#elif HAVE_GSM_GSM_H
32# include <gsm/gsm.h>
33#else
34# error "Can't find gsm.h header anywhere ..."
35#endif
36
37#include <string.h>
38
39
40static void *
41codec_fr_init(void)
42{
43 return (void *)gsm_create();
44}
45
46static void
47codec_fr_exit(void *state)
48{
49 gsm_destroy( (gsm)state );
50}
51
52static int
53codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm)
54{
55 gsm gh = (gsm)state;
56 uint8_t pcm_b[2*160]; /* local copy as libgsm src isn't const ! */
57 memcpy(pcm_b, pcm, 2*160);
Harald Welte7a046242014-05-08 19:18:01 +020058 BENCHMARK_START;
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010059 gsm_encode(gh, (gsm_signal*)pcm, (gsm_byte*)cod);
Harald Welte7a046242014-05-08 19:18:01 +020060 BENCHMARK_STOP(CODEC_FR, 1);
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010061 return 0;
62}
63
64static int
65codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod)
66{
67 gsm gh = (gsm)state;
68 uint8_t cod_b[33]; /* local copy as libgsm src isn't const ! */
Harald Welte7a046242014-05-08 19:18:01 +020069 int rc;
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010070 memcpy(cod_b, cod, 33);
Harald Welte7a046242014-05-08 19:18:01 +020071 BENCHMARK_START;
72 rc = gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm);
73 BENCHMARK_STOP(CODEC_FR, 1);
74 return rc;
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010075}
76
77#endif /* HAVE_LIBGSM */
78
79
Sylvain Munautcca11552010-10-24 18:32:44 +020080const struct codec_desc codec_fr_desc = {
81 .type = CODEC_FR,
82 .name = "fr",
83 .description = "GSM 06.10 Full Rate codec (classic gsm codec)",
Harald Welte62688b62017-05-28 10:20:26 +020084 .canon_frame_len = FR_CANON_LEN,
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010085#ifdef HAVE_LIBGSM
86 .codec_enc_format_type = FMT_GSM,
87 .codec_dec_format_type = FMT_GSM,
88 .codec_init = codec_fr_init,
89 .codec_exit = codec_fr_exit,
90 .codec_encode = codec_fr_encode,
91 .codec_decode = codec_fr_decode,
92#endif
Sylvain Munautcca11552010-10-24 18:32:44 +020093};