File: amr-nb.c

package info (click to toggle)
sox 14.4.2%2Bgit20190427-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,104 kB
  • sloc: ansic: 43,278; sh: 11,693; makefile: 339
file content (141 lines) | stat: -rw-r--r-- 5,076 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* File format: AMR-NB   (c) 2007 robs@users.sourceforge.net
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
/*
 * In order to use the AMR format with SoX, you need to have an AMR
 * library installed at SoX build time. Currently, the SoX build system
 * recognizes two AMR implementations, in the following order:
 *   http://opencore-amr.sourceforge.net/
 *   http://ftp.penguin.cz/pub/users/utx/amr/
 */

#include "sox_i.h"

#ifdef HAVE_AMRNB

/* Common definitions: */

enum amrnb_mode { amrnb_mode_dummy };

static const unsigned amrnb_block_size[] = {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
static char const amrnb_magic[] = "#!AMR\n";
#define amr_block_size amrnb_block_size
#define amr_magic amrnb_magic
#define amr_priv_t amrnb_priv_t
#define amr_opencore_funcs amrnb_opencore_funcs
#define amr_gp3_funcs amrnb_gp3_funcs

#define AMR_CODED_MAX       32                  /* max coded size */
#define AMR_ENCODING        SOX_ENCODING_AMR_NB
#define AMR_FORMAT_FN       lsx_amr_nb_format_fn
#define AMR_FRAME           160                 /* 20ms @ 8kHz */
#define AMR_MODE_MAX        7
#define AMR_NAMES           "amr-nb", "anb"
#define AMR_RATE            8000
#define AMR_DESC            "3GPP Adaptive Multi Rate Narrow-Band (AMR-NB) lossy speech compressor"

#if !defined(HAVE_LIBLTDL)
  #undef DL_AMRNB
#endif

#ifdef DL_AMRNB
  #define AMR_FUNC  LSX_DLENTRY_DYNAMIC
#else
  #define AMR_FUNC  LSX_DLENTRY_STATIC
#endif /* DL_AMRNB */

/* OpenCore definitions: */

#if defined(HAVE_OPENCORE_AMRNB_INTERF_DEC_H) || defined(DL_AMRNB)
  #define AMR_OPENCORE 1
  #define AMR_OPENCORE_ENABLE_ENCODE 1
#endif

#define AMR_OPENCORE_FUNC_ENTRIES(f,x) \
  AMR_FUNC(f,x, void*, Encoder_Interface_init,   (int dtx)) \
  AMR_FUNC(f,x, int,   Encoder_Interface_Encode, (void* state, enum amrnb_mode mode, const short* in, unsigned char* out, int forceSpeech)) \
  AMR_FUNC(f,x, void,  Encoder_Interface_exit,   (void* state)) \
  AMR_FUNC(f,x, void*, Decoder_Interface_init,   (void)) \
  AMR_FUNC(f,x, void,  Decoder_Interface_Decode, (void* state, const unsigned char* in, short* out, int bfi)) \
  AMR_FUNC(f,x, void,  Decoder_Interface_exit,   (void* state)) \

#define AmrOpencoreEncoderInit() \
  Encoder_Interface_init(1)
#define AmrOpencoreEncoderEncode(state, mode, in, out, forceSpeech) \
  Encoder_Interface_Encode(state, mode, in, out, forceSpeech)
#define AmrOpencoreEncoderExit(state) \
  Encoder_Interface_exit(state)
#define AmrOpencoreDecoderInit() \
  Decoder_Interface_init()
#define AmrOpencoreDecoderDecode(state, in, out, bfi) \
  Decoder_Interface_Decode(state, in, out, bfi)
#define AmrOpencoreDecoderExit(state) \
  Decoder_Interface_exit(state)

#define AMR_OPENCORE_DESC "amr-nb OpenCore library"
static const char* const amr_opencore_library_names[] =
{
#ifdef DL_AMRWB
  "libopencore-amrnb",
  "libopencore-amrnb-0",
#endif
  NULL
};

/* 3GPP (reference implementation) definitions: */

#if !defined(HAVE_OPENCORE_AMRNB_INTERF_DEC_H) || defined(DL_AMRNB)
  #define AMR_GP3 1
#endif

#define AMR_GP3_FUNC_ENTRIES(f,x) \
  AMR_FUNC(f,x, void*, VADxEncoder_Interface_init,      (int dtx, char vad2_code)) \
  AMR_FUNC(f,x, int,   GP3VADxEncoder_Interface_Encode, (void* state, enum amrnb_mode mode, short* in, unsigned char* out, int forceSpeech, char vad2_code)) \
  AMR_FUNC(f,x, void,  Encoder_Interface_exit,          (void* state)) \
  AMR_FUNC(f,x, void*, Decoder_Interface_init,          (void)) \
  AMR_FUNC(f,x, void,  GP3Decoder_Interface_Decode,     (void* state, unsigned char* in, short* out, int bfi)) \
  AMR_FUNC(f,x, void,  Decoder_Interface_exit,          (void* state)) \

#define AmrGp3EncoderInit() \
  VADxEncoder_Interface_init(1, 0)
#define AmrGp3EncoderEncode(state, mode, in, out, forceSpeech) \
  GP3VADxEncoder_Interface_Encode(state, mode, in, out, forceSpeech, 0)
#define AmrGp3EncoderExit(state) \
  Encoder_Interface_exit(state)
#define AmrGp3DecoderInit() \
  Decoder_Interface_init()
#define AmrGp3DecoderDecode(state, in, out, bfi) \
  GP3Decoder_Interface_Decode(state, in, out, bfi)
#define AmrGp3DecoderExit(state) \
  Decoder_Interface_exit(state)

#define AMR_GP3_DESC "amr-nb 3GPP reference library"
static const char* const amr_gp3_library_names[] =
{
#ifdef DL_AMRWB
  "libamrnb-3",
  "libamrnb",
  "amrnb",
  "cygamrnb-3",
#endif
  NULL
};

#include "amr.h"

#endif /* HAVE_AMRNB */