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