1 /* File format: AMR-NB (c) 2007 robs@users.sourceforge.net 2 * 3 * This library is free software; you can redistribute it and/or modify it 4 * under the terms of the GNU Lesser General Public License as published by 5 * the Free Software Foundation; either version 2.1 of the License, or (at 6 * your option) any later version. 7 * 8 * This library is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 11 * General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this library; if not, write to the Free Software Foundation, 15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 */ 17 18 /* 19 * In order to use the AMR format with SoX, you need to have an AMR 20 * library installed at SoX build time. Currently, the SoX build system 21 * recognizes two AMR implementations, in the following order: 22 * http://opencore-amr.sourceforge.net/ 23 * http://ftp.penguin.cz/pub/users/utx/amr/ 24 */ 25 26 #include "sox_i.h" 27 28 #ifdef HAVE_AMRNB 29 30 /* Common definitions: */ 31 32 enum amrnb_mode { amrnb_mode_dummy }; 33 34 static const unsigned amrnb_block_size[] = {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1}; 35 static char const amrnb_magic[] = "#!AMR\n"; 36 #define amr_block_size amrnb_block_size 37 #define amr_magic amrnb_magic 38 #define amr_priv_t amrnb_priv_t 39 #define amr_opencore_funcs amrnb_opencore_funcs 40 #define amr_gp3_funcs amrnb_gp3_funcs 41 42 #define AMR_CODED_MAX 32 /* max coded size */ 43 #define AMR_ENCODING SOX_ENCODING_AMR_NB 44 #define AMR_FORMAT_FN lsx_amr_nb_format_fn 45 #define AMR_FRAME 160 /* 20ms @ 8kHz */ 46 #define AMR_MODE_MAX 7 47 #define AMR_NAMES "amr-nb", "anb" 48 #define AMR_RATE 8000 49 #define AMR_DESC "3GPP Adaptive Multi Rate Narrow-Band (AMR-NB) lossy speech compressor" 50 51 #if !defined(HAVE_LIBLTDL) 52 #undef DL_AMRNB 53 #endif 54 55 #ifdef DL_AMRNB 56 #define AMR_FUNC LSX_DLENTRY_DYNAMIC 57 #else 58 #define AMR_FUNC LSX_DLENTRY_STATIC 59 #endif /* DL_AMRNB */ 60 61 /* OpenCore definitions: */ 62 63 #if defined(HAVE_OPENCORE_AMRNB_INTERF_DEC_H) || defined(DL_AMRNB) 64 #define AMR_OPENCORE 1 65 #define AMR_OPENCORE_ENABLE_ENCODE 1 66 #endif 67 68 #define AMR_OPENCORE_FUNC_ENTRIES(f,x) \ 69 AMR_FUNC(f,x, void*, Encoder_Interface_init, (int dtx)) \ 70 AMR_FUNC(f,x, int, Encoder_Interface_Encode, (void* state, enum amrnb_mode mode, const short* in, unsigned char* out, int forceSpeech)) \ 71 AMR_FUNC(f,x, void, Encoder_Interface_exit, (void* state)) \ 72 AMR_FUNC(f,x, void*, Decoder_Interface_init, (void)) \ 73 AMR_FUNC(f,x, void, Decoder_Interface_Decode, (void* state, const unsigned char* in, short* out, int bfi)) \ 74 AMR_FUNC(f,x, void, Decoder_Interface_exit, (void* state)) \ 75 76 #define AmrOpencoreEncoderInit() \ 77 Encoder_Interface_init(1) 78 #define AmrOpencoreEncoderEncode(state, mode, in, out, forceSpeech) \ 79 Encoder_Interface_Encode(state, mode, in, out, forceSpeech) 80 #define AmrOpencoreEncoderExit(state) \ 81 Encoder_Interface_exit(state) 82 #define AmrOpencoreDecoderInit() \ 83 Decoder_Interface_init() 84 #define AmrOpencoreDecoderDecode(state, in, out, bfi) \ 85 Decoder_Interface_Decode(state, in, out, bfi) 86 #define AmrOpencoreDecoderExit(state) \ 87 Decoder_Interface_exit(state) 88 89 #define AMR_OPENCORE_DESC "amr-nb OpenCore library" 90 static const char* const amr_opencore_library_names[] = 91 { 92 #ifdef DL_AMRWB 93 "libopencore-amrnb", 94 "libopencore-amrnb-0", 95 #endif 96 NULL 97 }; 98 99 /* 3GPP (reference implementation) definitions: */ 100 101 #if !defined(HAVE_OPENCORE_AMRNB_INTERF_DEC_H) || defined(DL_AMRNB) 102 #define AMR_GP3 1 103 #endif 104 105 #define AMR_GP3_FUNC_ENTRIES(f,x) \ 106 AMR_FUNC(f,x, void*, VADxEncoder_Interface_init, (int dtx, char vad2_code)) \ 107 AMR_FUNC(f,x, int, GP3VADxEncoder_Interface_Encode, (void* state, enum amrnb_mode mode, short* in, unsigned char* out, int forceSpeech, char vad2_code)) \ 108 AMR_FUNC(f,x, void, Encoder_Interface_exit, (void* state)) \ 109 AMR_FUNC(f,x, void*, Decoder_Interface_init, (void)) \ 110 AMR_FUNC(f,x, void, GP3Decoder_Interface_Decode, (void* state, unsigned char* in, short* out, int bfi)) \ 111 AMR_FUNC(f,x, void, Decoder_Interface_exit, (void* state)) \ 112 113 #define AmrGp3EncoderInit() \ 114 VADxEncoder_Interface_init(1, 0) 115 #define AmrGp3EncoderEncode(state, mode, in, out, forceSpeech) \ 116 GP3VADxEncoder_Interface_Encode(state, mode, in, out, forceSpeech, 0) 117 #define AmrGp3EncoderExit(state) \ 118 Encoder_Interface_exit(state) 119 #define AmrGp3DecoderInit() \ 120 Decoder_Interface_init() 121 #define AmrGp3DecoderDecode(state, in, out, bfi) \ 122 GP3Decoder_Interface_Decode(state, in, out, bfi) 123 #define AmrGp3DecoderExit(state) \ 124 Decoder_Interface_exit(state) 125 126 #define AMR_GP3_DESC "amr-nb 3GPP reference library" 127 static const char* const amr_gp3_library_names[] = 128 { 129 #ifdef DL_AMRWB 130 "libamrnb-3", 131 "libamrnb", 132 "amrnb", 133 "cygamrnb-3", 134 #endif 135 NULL 136 }; 137 138 #include "amr.h" 139 140 #endif /* HAVE_AMRNB */ 141 142