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"
25 /* From pvamrwbdecoder_api.h, by dividing by 8 and rounding up */
26 const int sizes[] = { 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, -1, -1, -1, -1, -1, 0 };
28 int main(int argc, char *argv[]) {
34 fprintf(stderr, "%s in.amr out.wav\n", argv[0]);
38 in = fopen(argv[1], "rb");
43 n = fread(header, 1, 9, in);
44 if (n != 9 || memcmp(header, "#!AMR-WB\n", 9)) {
45 fprintf(stderr, "Bad header\n");
49 wav = wav_write_open(argv[2], 16000, 16, 1);
51 fprintf(stderr, "Unable to open %s\n", argv[2]);
56 uint8_t buffer[500], littleendian[640], *ptr;
58 int16_t outbuffer[320];
59 /* Read the mode byte */
60 n = fread(buffer, 1, 1, in);
63 /* Find the packet size */
64 size = sizes[(buffer[0] >> 3) & 0x0f];
67 n = fread(buffer + 1, 1, size, in);
71 /* Decode the packet */
72 D_IF_decode(amr, buffer, outbuffer, 0);
74 /* Convert to little endian and write to wav */
76 for (i = 0; i < 320; i++) {
77 *ptr++ = (outbuffer[i] >> 0) & 0xff;
78 *ptr++ = (outbuffer[i] >> 8) & 0xff;
80 wav_write_data(wav, littleendian, 640);