aboutsummaryrefslogtreecommitdiffstats
path: root/src/codec_fr.c
blob: 3b1bb7c54a191dbf0add1025d2d187506da12f6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* FR (GSM 06.10) codec */

/*
 * This file is part of gapk (GSM Audio Pocket Knife).
 *
 * gapk is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gapk is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gapk.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <gapk/codecs.h>

#include "config.h"


#ifdef HAVE_LIBGSM

/* Find header */
#ifdef HAVE_GSM_H
# include <gsm.h>
#elif HAVE_GSM_GSM_H
# include <gsm/gsm.h>
#else
# error "Can't find gsm.h header anywhere ..."
#endif

#include <string.h>


static void *
codec_fr_init(void)
{
	return (void *)gsm_create();
}

static void
codec_fr_exit(void *state)
{
	gsm_destroy( (gsm)state );
}

static int
codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm)
{
	gsm gh = (gsm)state;
	uint8_t pcm_b[2*160];	/* local copy as libgsm src isn't const ! */
	memcpy(pcm_b, pcm, 2*160);
	gsm_encode(gh, (gsm_signal*)pcm, (gsm_byte*)cod);
	return 0;
}

static int
codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod)
{
	gsm gh = (gsm)state;
	uint8_t cod_b[33];	/* local copy as libgsm src isn't const ! */
	memcpy(cod_b, cod, 33);
	return gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm);
}

#endif /* HAVE_LIBGSM */


const struct codec_desc codec_fr_desc = {
	.type = CODEC_FR,
	.name = "fr",
	.description = "GSM 06.10 Full Rate codec (classic gsm codec)",
	.canon_frame_len = 33,
#ifdef HAVE_LIBGSM
	.codec_enc_format_type = FMT_GSM,
	.codec_dec_format_type = FMT_GSM,
	.codec_init = codec_fr_init,
	.codec_exit = codec_fr_exit,
	.codec_encode = codec_fr_encode,
	.codec_decode = codec_fr_decode,
#endif
};