blob: 04ca062195057b2ea18e16ae90f89b817bf401fc [file] [log] [blame]
Sylvain Munaut5e380d02010-10-29 11:41:16 +02001/* Classic .gsm files for FR */
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#include <gapk/formats.h>
22
23
24#define GSM_MAGIC 0xd
25
26static int
27gsm_from_canon(uint8_t *dst, const uint8_t *src)
28{
29 int i;
30
31 dst[0] = (GSM_MAGIC << 4) | (src[0] >> 4);
32 for (i=1; i<33; i++)
33 dst[i] = (src[i-1] << 4) | (src[i] >> 4);
34
35 return 0;
36}
37
38static int
39gsm_to_canon(uint8_t *dst, const uint8_t *src)
40{
41 int i;
42
43 for (i=0; i<32; i++)
44 dst[i] = (src[i] << 4) | (src[i+1] >> 4);
45 dst[32] = src[32] << 4;
46
47 return 0;
48}
49
50const struct format_desc fmt_gsm = {
51 .type = FMT_GSM,
52 .codec_type = CODEC_FR,
53 .name = "gsm",
54 .description = "Classic .gsm file format",
55
56 .frame_len = 33,
57 .conv_from_canon = gsm_from_canon,
58 .conv_to_canon = gsm_to_canon,
59};