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 * -------------------------------------------------------------------
27 /* From pvamrwbdecoder_api.h, by dividing by 8 and rounding up */
28 const int sizes[] = { 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, -1, -1, -1, -1, -1, -1 };
30 int main(int argc, char *argv[]) {
32 fprintf(stderr, "%s in.amr\n", argv[0]);
36 FILE* in = fopen(argv[1], "rb");
42 int n = fread(header, 1, 9, in);
43 if (n != 9 || memcmp(header, "#!AMR-WB\n", 9)) {
44 fprintf(stderr, "Bad header\n");
48 WavWriter wav("out.wav", 16000, 16, 1);
49 void* amr = D_IF_init();
52 /* Read the mode byte */
53 n = fread(buffer, 1, 1, in);
56 /* Find the packet size */
57 int size = sizes[(buffer[0] >> 3) & 0x0f];
60 n = fread(buffer + 1, 1, size, in);
64 /* Decode the packet */
65 int16_t outbuffer[320];
66 D_IF_decode(amr, buffer, outbuffer, 0);
68 /* Convert to little endian and write to wav */
69 uint8_t littleendian[640];
70 uint8_t* ptr = littleendian;
71 for (int i = 0; i < 320; i++) {
72 *ptr++ = (outbuffer[i] >> 0) & 0xff;
73 *ptr++ = (outbuffer[i] >> 8) & 0xff;
75 wav.writeData(littleendian, 640);