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 * -------------------------------------------------------------------
22 #include "wavwriter.h"
23 #include <interf_dec.h>
25 /* From WmfDecBytesPerFrame in dec_input_format_tab.cpp */
26 const int sizes[] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 6, 5, 5, 0, 0, 0, 0 };
29 int main(int argc, char *argv[]) {
35 fprintf(stderr, "%s in.amr out.wav\n", argv[0]);
39 in = fopen(argv[1], "rb");
44 n = fread(header, 1, 6, in);
45 if (n != 6 || memcmp(header, "#!AMR\n", 6)) {
46 fprintf(stderr, "Bad header\n");
50 wav = wav_write_open(argv[2], 8000, 16, 1);
52 fprintf(stderr, "Unable to open %s\n", argv[2]);
56 amr = Decoder_Interface_init();
58 uint8_t buffer[500], littleendian[320], *ptr;
60 int16_t outbuffer[160];
61 /* Read the mode byte */
62 n = fread(buffer, 1, 1, in);
65 /* Find the packet size */
66 size = sizes[(buffer[0] >> 3) & 0x0f];
67 n = fread(buffer + 1, 1, size, in);
71 /* Decode the packet */
72 Decoder_Interface_Decode(amr, buffer, outbuffer, 0);
74 /* Convert to little endian and write to wav */
76 for (i = 0; i < 160; i++) {
77 *ptr++ = (outbuffer[i] >> 0) & 0xff;
78 *ptr++ = (outbuffer[i] >> 8) & 0xff;
80 wav_write_data(wav, littleendian, 320);
83 Decoder_Interface_exit(amr);