merge with master
[platform/core/api/audio-io.git] / test / audio_io_test.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. 
15 */
16  
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <audio_io.h>   
21
22 int audio_io_test()
23 {
24         int ret, size;
25         audio_in_h input;
26         if ((ret = audio_in_create(44100, AUDIO_CHANNEL_STEREO ,AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) {
27                 ret = audio_in_ignore_session(input);
28                 if (ret != 0) {
29                         printf ("ERROR, set session mix\n");
30                         audio_in_destroy(input);
31                         return 0;
32                 }
33
34                 audio_in_prepare(input);
35                 if ((ret = audio_in_get_buffer_size(input, &size)) == AUDIO_IO_ERROR_NONE) {
36                         size = 500000;
37                         char *buffer = alloca(size);
38                         if ((ret = audio_in_read(input, (void*)buffer, size)) > AUDIO_IO_ERROR_NONE) {
39                                 FILE* fp = fopen ("/root/test.raw", "wb+");
40                                 fwrite (buffer, size, sizeof(char), fp);
41                                 fclose (fp);
42                                 printf ("PASS, size=%d, ret=%d\n", size, ret);
43                         }
44                         else {
45                                 printf ("FAIL, size=%d, ret=%d\n", size, ret);
46                         }
47                 }
48                 audio_in_destroy(input);
49         }
50
51         return 1;
52 }
53
54 int main(int argc, char ** argv)
55 {
56         audio_io_test();
57         return 0;
58 }
59