Sylvain Munaut | cca1155 | 2010-10-24 18:32:44 +0200 | [diff] [blame] | 1 | /* EFR (GSM 06.60) 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 | 8552b9d | 2010-11-11 13:57:41 +0100 | [diff] [blame] | 22 | #include "config.h" |
| 23 | |
| 24 | |
| 25 | #ifdef HAVE_OPENCORE_AMRNB |
| 26 | |
| 27 | #include <stdlib.h> |
| 28 | |
Sylvain Munaut | db83725 | 2012-12-08 19:14:11 +0100 | [diff] [blame] | 29 | #include <opencore-amrnb/interf_dec.h> |
| 30 | #include <opencore-amrnb/interf_enc.h> |
Sylvain Munaut | 8552b9d | 2010-11-11 13:57:41 +0100 | [diff] [blame] | 31 | |
| 32 | |
| 33 | struct codec_efr_state { |
| 34 | void *encoder; |
| 35 | void *decoder; |
| 36 | }; |
| 37 | |
| 38 | |
| 39 | static void * |
| 40 | codec_efr_init(void) |
| 41 | { |
| 42 | struct codec_efr_state *st; |
| 43 | |
| 44 | st = calloc(1, sizeof(*st)); |
| 45 | if (!st) |
| 46 | return NULL; |
| 47 | |
| 48 | st->encoder = Encoder_Interface_init(0); |
| 49 | st->decoder = Decoder_Interface_init(); |
| 50 | |
| 51 | return (void *)st; |
| 52 | } |
| 53 | |
| 54 | static void |
| 55 | codec_efr_exit(void *state) |
| 56 | { |
| 57 | struct codec_efr_state *st = state; |
| 58 | |
| 59 | Decoder_Interface_exit(st->decoder); |
| 60 | Encoder_Interface_exit(st->encoder); |
| 61 | |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | static int |
| 66 | codec_efr_encode(void *state, uint8_t *cod, const uint8_t *pcm) |
| 67 | { |
| 68 | struct codec_efr_state *st = state; |
| 69 | int rv; |
| 70 | |
| 71 | rv = Encoder_Interface_Encode( |
| 72 | st->encoder, |
| 73 | MR122, |
| 74 | (const short*) pcm, |
| 75 | (unsigned char*) cod, |
| 76 | 1 |
| 77 | ); |
| 78 | |
Sylvain Munaut | f624d18 | 2010-11-12 20:53:53 +0100 | [diff] [blame] | 79 | return rv != 32; |
Sylvain Munaut | 8552b9d | 2010-11-11 13:57:41 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static int |
| 83 | codec_efr_decode(void *state, uint8_t *pcm, const uint8_t *cod) |
| 84 | { |
| 85 | struct codec_efr_state *st = state; |
| 86 | |
| 87 | Decoder_Interface_Decode( |
| 88 | st->decoder, |
| 89 | (const unsigned char*) cod, |
| 90 | (short *) pcm, |
| 91 | 0 |
| 92 | ); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | #endif /* HAVE_OPENCORE_AMRNB */ |
| 98 | |
| 99 | |
Sylvain Munaut | cca1155 | 2010-10-24 18:32:44 +0200 | [diff] [blame] | 100 | const struct codec_desc codec_efr_desc = { |
| 101 | .type = CODEC_EFR, |
| 102 | .name = "efr", |
| 103 | .description = "GSM 06.60 Enhanced Full Rate codec", |
| 104 | .canon_frame_len = 31, |
Sylvain Munaut | 8552b9d | 2010-11-11 13:57:41 +0100 | [diff] [blame] | 105 | #ifdef HAVE_OPENCORE_AMRNB |
| 106 | .codec_enc_format_type = FMT_AMR_EFR, |
| 107 | .codec_dec_format_type = FMT_AMR_EFR, |
| 108 | .codec_init = codec_efr_init, |
| 109 | .codec_exit = codec_efr_exit, |
| 110 | .codec_encode = codec_efr_encode, |
| 111 | .codec_decode = codec_efr_decode, |
| 112 | #endif |
Sylvain Munaut | cca1155 | 2010-10-24 18:32:44 +0200 | [diff] [blame] | 113 | }; |