Sylvain Munaut | cca1155 | 2010-10-24 18:32:44 +0200 | [diff] [blame] | 1 | /* FR (GSM 06.10) codec */ |
| 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> |
Harald Welte | 7a04624 | 2014-05-08 19:18:01 +0200 | [diff] [blame] | 21 | #include <gapk/benchmark.h> |
Sylvain Munaut | cca1155 | 2010-10-24 18:32:44 +0200 | [diff] [blame] | 22 | |
Sylvain Munaut | dc5b38b | 2010-11-11 13:51:31 +0100 | [diff] [blame] | 23 | #include "config.h" |
| 24 | |
| 25 | |
| 26 | #ifdef HAVE_LIBGSM |
| 27 | |
| 28 | /* Find header */ |
| 29 | #ifdef HAVE_GSM_H |
| 30 | # include <gsm.h> |
| 31 | #elif HAVE_GSM_GSM_H |
| 32 | # include <gsm/gsm.h> |
| 33 | #else |
| 34 | # error "Can't find gsm.h header anywhere ..." |
| 35 | #endif |
| 36 | |
| 37 | #include <string.h> |
| 38 | |
| 39 | |
| 40 | static void * |
| 41 | codec_fr_init(void) |
| 42 | { |
| 43 | return (void *)gsm_create(); |
| 44 | } |
| 45 | |
| 46 | static void |
| 47 | codec_fr_exit(void *state) |
| 48 | { |
| 49 | gsm_destroy( (gsm)state ); |
| 50 | } |
| 51 | |
| 52 | static int |
| 53 | codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm) |
| 54 | { |
| 55 | gsm gh = (gsm)state; |
| 56 | uint8_t pcm_b[2*160]; /* local copy as libgsm src isn't const ! */ |
| 57 | memcpy(pcm_b, pcm, 2*160); |
Harald Welte | 7a04624 | 2014-05-08 19:18:01 +0200 | [diff] [blame] | 58 | BENCHMARK_START; |
Sylvain Munaut | dc5b38b | 2010-11-11 13:51:31 +0100 | [diff] [blame] | 59 | gsm_encode(gh, (gsm_signal*)pcm, (gsm_byte*)cod); |
Harald Welte | 7a04624 | 2014-05-08 19:18:01 +0200 | [diff] [blame] | 60 | BENCHMARK_STOP(CODEC_FR, 1); |
Sylvain Munaut | dc5b38b | 2010-11-11 13:51:31 +0100 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int |
| 65 | codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod) |
| 66 | { |
| 67 | gsm gh = (gsm)state; |
| 68 | uint8_t cod_b[33]; /* local copy as libgsm src isn't const ! */ |
Harald Welte | 7a04624 | 2014-05-08 19:18:01 +0200 | [diff] [blame] | 69 | int rc; |
Sylvain Munaut | dc5b38b | 2010-11-11 13:51:31 +0100 | [diff] [blame] | 70 | memcpy(cod_b, cod, 33); |
Harald Welte | 7a04624 | 2014-05-08 19:18:01 +0200 | [diff] [blame] | 71 | BENCHMARK_START; |
| 72 | rc = gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm); |
| 73 | BENCHMARK_STOP(CODEC_FR, 1); |
| 74 | return rc; |
Sylvain Munaut | dc5b38b | 2010-11-11 13:51:31 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | #endif /* HAVE_LIBGSM */ |
| 78 | |
| 79 | |
Sylvain Munaut | cca1155 | 2010-10-24 18:32:44 +0200 | [diff] [blame] | 80 | const struct codec_desc codec_fr_desc = { |
| 81 | .type = CODEC_FR, |
| 82 | .name = "fr", |
| 83 | .description = "GSM 06.10 Full Rate codec (classic gsm codec)", |
Harald Welte | 62688b6 | 2017-05-28 10:20:26 +0200 | [diff] [blame^] | 84 | .canon_frame_len = FR_CANON_LEN, |
Sylvain Munaut | dc5b38b | 2010-11-11 13:51:31 +0100 | [diff] [blame] | 85 | #ifdef HAVE_LIBGSM |
| 86 | .codec_enc_format_type = FMT_GSM, |
| 87 | .codec_dec_format_type = FMT_GSM, |
| 88 | .codec_init = codec_fr_init, |
| 89 | .codec_exit = codec_fr_exit, |
| 90 | .codec_encode = codec_fr_encode, |
| 91 | .codec_decode = codec_fr_decode, |
| 92 | #endif |
Sylvain Munaut | cca1155 | 2010-10-24 18:32:44 +0200 | [diff] [blame] | 93 | }; |