1 /* ------------------------------------------------------------------
2 * Copyright (C) 2009 Martin Storsjo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
24 #include <interf_dec.h>
27 /* From WmfDecBytesPerFrame in dec_input_format_tab.cpp */
28 const int sizes[] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 6, 5, 5, 0, 0, 0, 0 };
31 int main(int argc, char *argv[]) {
33 fprintf(stderr, "%s in.amr\n", argv[0]);
37 FILE* in = fopen(argv[1], "rb");
43 int n = fread(header, 1, 6, in);
44 if (n != 6 || memcmp(header, "#!AMR\n", 6)) {
45 fprintf(stderr, "Bad header\n");
49 WavWriter wav("out.wav", 8000, 16, 1);
51 void* amr = Decoder_Interface_init();
54 /* Read the mode byte */
55 n = fread(buffer, 1, 1, in);
58 /* Find the packet size */
59 int size = sizes[(buffer[0] >> 3) & 0x0f];
62 n = fread(buffer + 1, 1, size, in);
66 /* Decode the packet */
67 int16_t outbuffer[160];
68 Decoder_Interface_Decode(amr, buffer, outbuffer, 0);
70 /* Convert to little endian and write to wav */
71 uint8_t littleendian[320];
72 uint8_t* ptr = littleendian;
73 for (int i = 0; i < 160; i++) {
74 *ptr++ = (outbuffer[i] >> 0) & 0xff;
75 *ptr++ = (outbuffer[i] >> 8) & 0xff;
77 wav.writeData(littleendian, 320);
80 Decoder_Interface_exit(amr);