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