2
* ===================================================================
6
* 3GPP AMR Floating-point Speech Codec
7
* ===================================================================
16
* AMR Floating-Point Codec
19
* Speech encoder main program
27
#include "interf_enc.h"
31
#define AMR_MAGIC_NUMBER "#!AMR\n"
35
static const short modeConv[]={
36
475, 515, 59, 67, 74, 795, 102, 122};
38
static void Usage(char* argv[])
42
"[-dtx] mode speech_file bitstream_file \n\n"
44
"[-dtx] -modefile=mode_file speech_file bitstream_file \n\n\n"
45
"mode = MR475, MR515, MR59, MR67, MR74, MR795, MR102, MR122 \n\n\n",
50
"===================================================================\n"
52
" REL-5 V5.4.0 2004-03 \n"
53
" REL-6 V6.1.0 2004-03 \n"
54
" 3GPP AMR Floating-point Speech Encoder \n"
55
"===================================================================\n"
63
* Speech encoder main program
65
* Usage: encoder speech_file bitstream_file mode dtx mode_file
67
* Format for speech_file:
68
* Speech is read from a binary file of 16 bits data.
70
* Format for ETSI bitstream file:
71
* 1 word (2-byte) for the TX frame type
72
* 244 words (2-byte) containing 244 bits.
73
* Bit 0 = 0x0000 and Bit 1 = 0x0001
74
* 1 word (2-byte) for the mode indication
75
* 4 words for future use, currently written as zero
77
* Format for 3GPP bitstream file:
78
* Holds mode information and bits packed to octets.
79
* Size is from 1 byte to 31 bytes.
81
* ETSI bitstream file format is defined using ETSI as preprocessor
84
* mode : MR475, MR515, MR59, MR67, MR74, MR795, MR102, MR122
85
* mode_file : reads mode information from a file
89
int main (int argc, char * argv[]){
92
FILE * file_speech = NULL;
93
FILE * file_encoded = NULL;
94
FILE * file_mode = NULL;
96
/* input speech vector */
100
int byte_counter, frames = 0, bytes = 0;
102
/* pointer to encoder state structure */
106
enum Mode req_mode = MR122;
109
/* temporary variables */
113
/* bitstream filetype */
115
unsigned char serial_data[32];
117
short serial_data[250] = {0};
120
/* Process command line options */
122
if ((argc == 5) || (argc == 4)){
123
file_encoded = fopen(argv[argc - 1], "wb");
124
if (file_encoded == NULL){
128
file_speech = fopen(argv[argc - 2], "rb");
129
if (file_speech == NULL){
130
fclose(file_encoded);
134
if (strncmp(argv[argc - 3], "-modefile=", 10) == 0){
135
file_mode = fopen(&argv[argc - 3][10], "rt");
136
if (file_mode == NULL){
139
fclose(file_encoded);
144
mode_tmp = strtol(&argv[argc - 3][2], NULL, 0);
145
for (req_mode = 0; req_mode < 8; req_mode++){
146
if (mode_tmp == modeConv[req_mode])
152
fclose(file_encoded);
153
if (file_mode != NULL)
159
if ((strcmp(argv[1], "-dtx") != 0)){
162
fclose(file_encoded);
163
if (file_mode != NULL){
179
enstate = Encoder_Interface_init(dtx);
183
fprintf( stderr, "%s\n", "Code compiled with VAD option: VAD1");
185
fprintf( stderr, "%s\n", "Code compiled with VAD option: VAD2");
190
/* write magic number to indicate single channel AMR file storage format */
191
bytes = fwrite(AMR_MAGIC_NUMBER, sizeof(char), strlen(AMR_MAGIC_NUMBER), file_encoded);
196
while (fread( speech, sizeof (Word16), 160, file_speech ) > 0)
199
if (file_mode != NULL){
201
if (fscanf(file_mode, "%9s\n", mode_string) != EOF) {
202
mode_tmp = strtol(&mode_string[2], NULL, 0);
203
for (req_mode = 0; req_mode < 8; req_mode++){
204
if (mode_tmp == modeConv[req_mode]){
217
byte_counter = Encoder_Interface_Encode(enstate, req_mode, speech, serial_data, 0);
219
bytes += byte_counter;
220
fwrite(serial_data, sizeof (UWord8), byte_counter, file_encoded );
221
fflush(file_encoded);
223
Encoder_Interface_exit(enstate);
227
fprintf ( stderr, "\n%s%i%s%i%s\n", "Frame structure AMR IF2: ", frames, " frames, ", bytes, " bytes.");
229
fprintf ( stderr, "\n%s%i%s%i%s\n", "Frame structure AMR MIME file storage format: ", frames, " frames, ", bytes, " bytes.");
232
fprintf ( stderr, "\n%s%i%s\n", "Frame structure AMR ETSI: ", frames, " frames. ");
236
fclose(file_encoded);
237
if (file_mode != NULL)