Git init
[external/opencore-amr.git] / test / amrnb-enc.c
1 /* ------------------------------------------------------------------
2  * Copyright (C) 2009 Martin Storsjo
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <math.h>
22 #include <interf_enc.h>
23
24 int main(int argc, char *argv[]) {
25         int i, j;
26         void* amr;
27         FILE* out;
28         int sample_pos = 0;
29
30         amr = Encoder_Interface_init(0);
31         out = fopen("out.amr", "wb");
32
33         fwrite("#!AMR\n", 1, 6, out);
34         for (i = 0; i < 1000; i++) {
35                 short buf[160];
36                 uint8_t outbuf[500];
37                 int n;
38                 for (j = 0; j < 160; j++) {
39                         buf[j] = 32767*sin(440*2*3.141592654*sample_pos/8000);
40                         sample_pos++;
41                 }
42                 n = Encoder_Interface_Encode(amr, MR475, buf, outbuf, 0);
43                 fwrite(outbuf, 1, n, out);
44         }
45         fclose(out);
46         Encoder_Interface_exit(amr);
47
48         return 0;
49 }
50