blob: 141dec13c86cd1efc8dd7b948ca082fea01ac319 [file] [log] [blame]
Sylvain Munautcca11552010-10-24 18:32:44 +02001/* EFR (GSM 06.60) 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 Munaut8552b9d2010-11-11 13:57:41 +010022#include "config.h"
23
24
25#ifdef HAVE_OPENCORE_AMRNB
26
27#include <stdlib.h>
28
Sylvain Munautdb837252012-12-08 19:14:11 +010029#include <opencore-amrnb/interf_dec.h>
30#include <opencore-amrnb/interf_enc.h>
Sylvain Munaut8552b9d2010-11-11 13:57:41 +010031
32
33struct codec_efr_state {
34 void *encoder;
35 void *decoder;
36};
37
38
39static void *
40codec_efr_init(void)
41{
42 struct codec_efr_state *st;
43
44 st = calloc(1, sizeof(*st));
45 if (!st)
46 return NULL;
47
48 st->encoder = Encoder_Interface_init(0);
49 st->decoder = Decoder_Interface_init();
50
51 return (void *)st;
52}
53
54static void
55codec_efr_exit(void *state)
56{
57 struct codec_efr_state *st = state;
58
59 Decoder_Interface_exit(st->decoder);
60 Encoder_Interface_exit(st->encoder);
61
62 return;
63}
64
65static int
66codec_efr_encode(void *state, uint8_t *cod, const uint8_t *pcm)
67{
68 struct codec_efr_state *st = state;
69 int rv;
70
71 rv = Encoder_Interface_Encode(
72 st->encoder,
73 MR122,
74 (const short*) pcm,
75 (unsigned char*) cod,
76 1
77 );
78
Sylvain Munautf624d182010-11-12 20:53:53 +010079 return rv != 32;
Sylvain Munaut8552b9d2010-11-11 13:57:41 +010080}
81
82static int
83codec_efr_decode(void *state, uint8_t *pcm, const uint8_t *cod)
84{
85 struct codec_efr_state *st = state;
86
87 Decoder_Interface_Decode(
88 st->decoder,
89 (const unsigned char*) cod,
90 (short *) pcm,
91 0
92 );
93
94 return 0;
95}
96
97#endif /* HAVE_OPENCORE_AMRNB */
98
99
Sylvain Munautcca11552010-10-24 18:32:44 +0200100const struct codec_desc codec_efr_desc = {
101 .type = CODEC_EFR,
102 .name = "efr",
103 .description = "GSM 06.60 Enhanced Full Rate codec",
104 .canon_frame_len = 31,
Sylvain Munaut8552b9d2010-11-11 13:57:41 +0100105#ifdef HAVE_OPENCORE_AMRNB
106 .codec_enc_format_type = FMT_AMR_EFR,
107 .codec_dec_format_type = FMT_AMR_EFR,
108 .codec_init = codec_efr_init,
109 .codec_exit = codec_efr_exit,
110 .codec_encode = codec_efr_encode,
111 .codec_decode = codec_efr_decode,
112#endif
Sylvain Munautcca11552010-10-24 18:32:44 +0200113};