Initialize Tizen 2.3
[external/opencore-amr.git] / test / amrnb-enc-sine.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         if (argc < 2) {
31                 fprintf(stderr, "%s out.amr\n", argv[0]);
32                 return 1;
33         }
34
35         amr = Encoder_Interface_init(0);
36         out = fopen(argv[1], "wb");
37         if (!out) {
38                 perror(argv[1]);
39                 return 1;
40         }
41
42         fwrite("#!AMR\n", 1, 6, out);
43         for (i = 0; i < 1000; i++) {
44                 short buf[160];
45                 uint8_t outbuf[500];
46                 int n;
47                 for (j = 0; j < 160; j++) {
48                         buf[j] = 32767*sin(440*2*3.141592654*sample_pos/8000);
49                         sample_pos++;
50                 }
51                 n = Encoder_Interface_Encode(amr, MR475, buf, outbuf, 0);
52                 fwrite(outbuf, 1, n, out);
53         }
54         fclose(out);
55         Encoder_Interface_exit(amr);
56
57         return 0;
58 }
59