Sylvain Munaut | 723df06 | 2010-10-29 11:47:06 +0200 | [diff] [blame] | 1 | /* Classic .amr file format */ |
| 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 <stdint.h> |
| 21 | |
| 22 | #include <osmocom/codec/codec.h> |
| 23 | |
| 24 | #include <gapk/codecs.h> |
| 25 | #include <gapk/formats.h> |
| 26 | #include <gapk/utils.h> |
| 27 | |
| 28 | |
| 29 | static int |
| 30 | amr_efr_from_canon(uint8_t *dst, const uint8_t *src) |
| 31 | { |
| 32 | int i; |
| 33 | |
| 34 | dst[ 0] = 0x3c; |
| 35 | dst[31] = 0x00; /* last nibble won't written, pre-clear it */ |
| 36 | |
| 37 | for (i=0; i<244; i++) { |
| 38 | int si = gsm690_12_2_bitorder[i]; |
| 39 | int di = i; |
| 40 | msb_put_bit(&dst[1], di, msb_get_bit(src, si)); |
| 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static int |
| 47 | amr_efr_to_canon(uint8_t *dst, const uint8_t *src) |
| 48 | { |
| 49 | int i; |
| 50 | |
| 51 | if (src[0] != 0x3c) |
| 52 | return -1; |
| 53 | |
| 54 | dst[30] = 0x00; /* last nibble won't written, pre-clear it */ |
| 55 | |
| 56 | for (i=0; i<244; i++) { |
| 57 | int si = i; |
| 58 | int di = gsm690_12_2_bitorder[i]; |
| 59 | msb_put_bit(dst, di, msb_get_bit(&src[1], si)); |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | const struct format_desc fmt_amr_efr = { |
| 66 | .type = FMT_AMR_EFR, |
| 67 | .codec_type = CODEC_EFR, |
| 68 | .name = "amr-efr", |
| 69 | .description = "Classic .amr file containing EFR (=AMR 12.2k) data", |
| 70 | |
| 71 | .frame_len = 32, |
| 72 | .conv_from_canon = amr_efr_from_canon, |
| 73 | .conv_to_canon = amr_efr_to_canon, |
| 74 | |
| 75 | .header_len = 6, |
| 76 | .header = (const uint8_t *) "#!AMR\x0a", |
| 77 | }; |