Sylvain Munaut | 6c96cc2 | 2010-10-29 11:46:05 +0200 | [diff] [blame^] | 1 | /* Racal 6103E TCH recordings 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 | racal_hr_from_canon(uint8_t *dst, const uint8_t *src) |
| 31 | { |
| 32 | int i, voiced; |
| 33 | const uint16_t *bit_mapping; |
| 34 | |
| 35 | voiced = (msb_get_bit(src, 34) << 1) | msb_get_bit(src, 35); |
| 36 | |
| 37 | bit_mapping = voiced ? |
| 38 | &gsm620_voiced_bitorder[0] : |
| 39 | &gsm620_unvoiced_bitorder[0] ; |
| 40 | |
| 41 | for (i=0; i<112; i++) { |
| 42 | int si = bit_mapping[i]; |
| 43 | int di = i; |
| 44 | lsb_put_bit(dst, di, msb_get_bit(src, si)); |
| 45 | } |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int |
| 51 | racal_hr_to_canon(uint8_t *dst, const uint8_t *src) |
| 52 | { |
| 53 | int i, voiced; |
| 54 | const uint16_t *bit_mapping; |
| 55 | |
| 56 | voiced = (lsb_get_bit(src, 94) << 1) | lsb_get_bit(src, 93); |
| 57 | |
| 58 | bit_mapping = voiced ? |
| 59 | &gsm620_voiced_bitorder[0] : |
| 60 | &gsm620_unvoiced_bitorder[0] ; |
| 61 | |
| 62 | for (i=0; i<112; i++) { |
| 63 | int si = i; |
| 64 | int di = bit_mapping[i]; |
| 65 | msb_put_bit(dst, di, lsb_get_bit(src, si)); |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | const struct format_desc fmt_racal_hr = { |
| 72 | .type = FMT_RACAL_HR, |
| 73 | .codec_type = CODEC_HR, |
| 74 | .name = "racal-hr", |
| 75 | .description = "Racal HR TCH/H recording", |
| 76 | |
| 77 | .frame_len = 14, |
| 78 | .conv_from_canon = racal_hr_from_canon, |
| 79 | .conv_to_canon = racal_hr_to_canon, |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | static int |
| 84 | racal_fr_from_canon(uint8_t *dst, const uint8_t *src) |
| 85 | { |
| 86 | int i; |
| 87 | |
| 88 | dst[32] = 0x00; /* last nibble won't written, pre-clear it */ |
| 89 | |
| 90 | for (i=0; i<260; i++) { |
| 91 | int si = gsm610_bitorder[i]; |
| 92 | int di = i; |
| 93 | lsb_put_bit(dst, di, msb_get_bit(src, si)); |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static int |
| 100 | racal_fr_to_canon(uint8_t *dst, const uint8_t *src) |
| 101 | { |
| 102 | int i; |
| 103 | |
| 104 | dst[32] = 0x00; /* last nibble won't written, pre-clear it */ |
| 105 | |
| 106 | for (i=0; i<260; i++) { |
| 107 | int si = i; |
| 108 | int di = gsm610_bitorder[i]; |
| 109 | msb_put_bit(dst, di, lsb_get_bit(src, si)); |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | const struct format_desc fmt_racal_fr = { |
| 116 | .type = FMT_RACAL_FR, |
| 117 | .codec_type = CODEC_FR, |
| 118 | .name = "racal-fr", |
| 119 | .description = "Racal FR TCH/F recording", |
| 120 | |
| 121 | .frame_len = 33, |
| 122 | .conv_from_canon = racal_fr_from_canon, |
| 123 | .conv_to_canon = racal_fr_to_canon, |
| 124 | }; |
| 125 | |
| 126 | |
| 127 | static int |
| 128 | racal_efr_from_canon(uint8_t *dst, const uint8_t *src) |
| 129 | { |
| 130 | int i; |
| 131 | |
| 132 | dst[30] = 0x00; /* last nibble won't written, pre-clear it */ |
| 133 | |
| 134 | for (i=0; i<244; i++) |
| 135 | lsb_put_bit(dst, i, msb_get_bit(src, i)); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static int |
| 141 | racal_efr_to_canon(uint8_t *dst, const uint8_t *src) |
| 142 | { |
| 143 | int i; |
| 144 | |
| 145 | dst[30] = 0x00; /* last nibble won't written, pre-clear it */ |
| 146 | |
| 147 | for (i=0; i<244; i++) |
| 148 | msb_put_bit(dst, i, lsb_get_bit(src, i)); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | const struct format_desc fmt_racal_efr = { |
| 154 | .type = FMT_RACAL_EFR, |
| 155 | .codec_type = CODEC_EFR, |
| 156 | .name = "racal-efr", |
| 157 | .description = "Racal EFR TCH/F recording", |
| 158 | |
| 159 | .frame_len = 31, |
| 160 | .conv_from_canon = racal_efr_from_canon, |
| 161 | .conv_to_canon = racal_efr_to_canon, |
| 162 | }; |