summaryrefslogtreecommitdiffstats
path: root/src/codec_hr.c
blob: d0e09ceed13734670803096b9f01418c92f7bb6c (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
/* HR (GSM 06.20) 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 <gapk/benchmark.h>

#include "config.h"


#ifdef HAVE_LIBGSMHR

#include <gsmhr/gsmhr.h>

static void *
codec_hr_init(void)
{
	return (void *)gsmhr_init();
}

static void
codec_hr_exit(void *_state)
{
	struct gsmhr *state = _state;
	gsmhr_exit(state);
}

static int
codec_hr_encode(void *_state, uint8_t *cod, const uint8_t *pcm)
{
	struct gsmhr *state = _state;
	int rc;
	BENCHMARK_START;
	rc = gsmhr_encode(state, (int16_t *)cod, (const int16_t *)pcm);
	BENCHMARK_STOP(CODEC_HR, 1);
	return rc;
}

static int
codec_hr_decode(void *_state, uint8_t *pcm, const uint8_t *cod)
{
	struct gsmhr *state = _state;
	int rc;
	BENCHMARK_START;
	rc = gsmhr_decode(state, (int16_t *)pcm, (const int16_t *)cod);
	BENCHMARK_STOP(CODEC_HR, 0);
	return rc;
}

#endif /* HAVE_LIBGSMHR */


const struct codec_desc codec_hr_desc = {
	.type = CODEC_HR,
	.name = "hr",
	.description = "GSM 06.20 Half Rate codec",
	.canon_frame_len = 14,
#ifdef HAVE_LIBGSMHR
	.codec_enc_format_type = FMT_HR_REF_ENC,
	.codec_dec_format_type = FMT_HR_REF_DEC,
	.codec_init = codec_hr_init,
	.codec_exit = codec_hr_exit,
	.codec_encode = codec_hr_encode,
	.codec_decode = codec_hr_decode,
#endif
};