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
20  * AMR library installed at SoX build time. The SoX build system
21  * recognizes the AMR implementations available from
22  * http://opencore-amr.sourceforge.net/
23  */
24 
25 #include "sox_i.h"
26 
27 /* Common definitions: */
28 
29 enum amrnb_mode { amrnb_mode_dummy };
30 
31 static const unsigned amrnb_block_size[] = {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
32 static char const amrnb_magic[] = "#!AMR\n";
33 #define amr_block_size amrnb_block_size
34 #define amr_magic amrnb_magic
35 #define amr_priv_t amrnb_priv_t
36 #define amr_opencore_funcs amrnb_opencore_funcs
37 #define amr_gp3_funcs amrnb_gp3_funcs
38 
39 #define AMR_CODED_MAX       32                  /* max coded size */
40 #define AMR_ENCODING        SOX_ENCODING_AMR_NB
41 #define AMR_FORMAT_FN       lsx_amr_nb_format_fn
42 #define AMR_FRAME           160                 /* 20ms @ 8kHz */
43 #define AMR_MODE_MAX        7
44 #define AMR_NAMES           "amr-nb", "anb"
45 #define AMR_RATE            8000
46 #define AMR_DESC            "3GPP Adaptive Multi Rate Narrow-Band (AMR-NB) lossy speech compressor"
47 
48 #ifdef DL_OPENCORE_AMRNB
49   #define AMR_FUNC  LSX_DLENTRY_DYNAMIC
50 #else
51   #define AMR_FUNC  LSX_DLENTRY_STATIC
52 #endif /* DL_AMRNB */
53 
54 /* OpenCore definitions: */
55 
56 #define AMR_OPENCORE 1
57 #define AMR_OPENCORE_ENABLE_ENCODE 1
58 
59 #define AMR_OPENCORE_FUNC_ENTRIES(f,x) \
60   AMR_FUNC(f,x, void*, Encoder_Interface_init,   (int dtx)) \
61   AMR_FUNC(f,x, int,   Encoder_Interface_Encode, (void* state, enum amrnb_mode mode, const short* in, unsigned char* out, int forceSpeech)) \
62   AMR_FUNC(f,x, void,  Encoder_Interface_exit,   (void* state)) \
63   AMR_FUNC(f,x, void*, Decoder_Interface_init,   (void)) \
64   AMR_FUNC(f,x, void,  Decoder_Interface_Decode, (void* state, const unsigned char* in, short* out, int bfi)) \
65   AMR_FUNC(f,x, void,  Decoder_Interface_exit,   (void* state)) \
66 
67 #define AmrEncoderInit() \
68   Encoder_Interface_init(1)
69 #define AmrEncoderEncode(state, mode, in, out, forceSpeech) \
70   Encoder_Interface_Encode(state, mode, in, out, forceSpeech)
71 #define AmrEncoderExit(state) \
72   Encoder_Interface_exit(state)
73 #define AmrDecoderInit() \
74   Decoder_Interface_init()
75 #define AmrDecoderDecode(state, in, out, bfi) \
76   Decoder_Interface_Decode(state, in, out, bfi)
77 #define AmrDecoderExit(state) \
78   Decoder_Interface_exit(state)
79 
80 #define AMR_OPENCORE_DESC "amr-nb OpenCore library"
81 static const char* const amr_opencore_library_names[] =
82 {
83 #ifdef DL_OPENCORE_AMRNB
84   "libopencore-amrnb",
85   "libopencore-amrnb-0",
86 #endif
87   NULL
88 };
89 
90 #include "amr.h"
91