blob: 3b1bb7c54a191dbf0add1025d2d187506da12f6a [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>
21
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010022#include "config.h"
23
24
25#ifdef HAVE_LIBGSM
26
27/* Find header */
28#ifdef HAVE_GSM_H
29# include <gsm.h>
30#elif HAVE_GSM_GSM_H
31# include <gsm/gsm.h>
32#else
33# error "Can't find gsm.h header anywhere ..."
34#endif
35
36#include <string.h>
37
38
39static void *
40codec_fr_init(void)
41{
42 return (void *)gsm_create();
43}
44
45static void
46codec_fr_exit(void *state)
47{
48 gsm_destroy( (gsm)state );
49}
50
51static int
52codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm)
53{
54 gsm gh = (gsm)state;
55 uint8_t pcm_b[2*160]; /* local copy as libgsm src isn't const ! */
56 memcpy(pcm_b, pcm, 2*160);
57 gsm_encode(gh, (gsm_signal*)pcm, (gsm_byte*)cod);
58 return 0;
59}
60
61static int
62codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod)
63{
64 gsm gh = (gsm)state;
65 uint8_t cod_b[33]; /* local copy as libgsm src isn't const ! */
66 memcpy(cod_b, cod, 33);
67 return gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm);
68}
69
70#endif /* HAVE_LIBGSM */
71
72
Sylvain Munautcca11552010-10-24 18:32:44 +020073const struct codec_desc codec_fr_desc = {
74 .type = CODEC_FR,
75 .name = "fr",
76 .description = "GSM 06.10 Full Rate codec (classic gsm codec)",
77 .canon_frame_len = 33,
Sylvain Munautdc5b38b2010-11-11 13:51:31 +010078#ifdef HAVE_LIBGSM
79 .codec_enc_format_type = FMT_GSM,
80 .codec_dec_format_type = FMT_GSM,
81 .codec_init = codec_fr_init,
82 .codec_exit = codec_fr_exit,
83 .codec_encode = codec_fr_encode,
84 .codec_decode = codec_fr_decode,
85#endif
Sylvain Munautcca11552010-10-24 18:32:44 +020086};