Add echo cancel testsuite 32/272832/3 submit/tizen/20220405.045611
authorJaechul Lee <jcsing.lee@samsung.com>
Fri, 25 Mar 2022 03:20:01 +0000 (12:20 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Thu, 31 Mar 2022 06:00:28 +0000 (15:00 +0900)
[Version] 0.5.46
[Issue Type] Add

Change-Id: I1a5b0048b46e4f187ca9d4e31f11cae5c858025c
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
packaging/capi-media-audio-io.spec
test/audio_io_test.c

index 557021a..6ef26d7 100644 (file)
@@ -1,6 +1,6 @@
 Name:           capi-media-audio-io
 Summary:        An Audio Input & Audio Output library in Tizen Native API
-Version:        0.5.45
+Version:        0.5.46
 Release:        0
 Group:          Multimedia/API
 License:        Apache-2.0
index e766df7..efb54c4 100644 (file)
@@ -21,6 +21,7 @@
 #include <math.h>
 #include <pthread.h>
 #include <sound_manager.h>
+#include <sound_manager_internal.h>
 #include <audio_io.h>
 #include <time.h>
 
@@ -244,6 +245,107 @@ EXIT:
        printf("\nEOS!!!! Play done\n");
 }
 
+static sound_device_h *find_device_by_id(int id)
+{
+       sound_device_list_h device_list;
+       sound_device_h device;
+       int _id;
+
+       if (sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &device_list) != 0)
+               return NULL;
+
+       while (!sound_manager_get_next_device(device_list, &device)) {
+               if (sound_manager_get_device_id(device, &_id) != 0) {
+                       device = NULL;
+                       goto out;
+               }
+
+               if (_id == id)
+                       break;
+       }
+
+out:
+       sound_manager_free_device_list(device_list);
+
+       return device;
+}
+
+static int _record_echocancel(char *filename, int rate, int channels, int ref_deviceid)
+{
+       int ret, size;
+       sound_stream_info_h stream_info;
+       sound_device_h ref_dev = NULL;
+       audio_in_h input = NULL;
+       FILE *fp = NULL;
+       char *buffer = NULL;
+
+       ret = audio_in_create(rate, ch_table[channels], AUDIO_SAMPLE_TYPE_S16_LE, &input);
+       if (ret != AUDIO_IO_ERROR_NONE) {
+               printf("audio in create error = 0x%x\n", ret);
+               return -1;
+       }
+
+       ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &stream_info);
+       if (ret) {
+               printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
+               goto out;
+       }
+
+       if (!(ref_dev = find_device_by_id(ref_deviceid))) {
+               printf("fail to get ref device id\b");
+               goto out;
+       }
+
+       ret = sound_manager_set_echo_cancel_reference_device(stream_info, ref_dev);
+       if (ret) {
+               printf("fail to sound_manager_set_echo_cancel_reference_device(), ret(0x%x)\n", ret);
+               goto out;
+       }
+
+       ret = audio_in_set_sound_stream_info(input, stream_info);
+       if (ret) {
+               printf("fail to audio_in_set_sound_stream_info(), ret(0x%x)\n", ret);
+               goto out;
+       }
+
+       ret = audio_in_prepare(input);
+       if (ret != AUDIO_IO_ERROR_NONE) {
+               printf("ERROR, prepare\n");
+               goto out;
+       }
+
+       ret = audio_in_get_buffer_size(input, &size);
+       if (ret != AUDIO_IO_ERROR_NONE) {
+               printf("ERROR, get_buffer_size\n");
+               goto out;
+       }
+
+       fp = fopen(filename, "wb+");
+       if (fp == NULL) {
+               printf("ERROR, file open failed\n");
+               goto out;
+       }
+
+       buffer = alloca(size);
+
+       while (1) {
+               ret = audio_in_read(input, (void *)buffer, size);
+               if (ret <= 0) {
+                       printf("FAIL, size=%d, ret=0x%x\n", size, ret);
+                       goto out;
+               }
+
+               fwrite(buffer, size, sizeof(char), fp);
+       }
+
+out:
+       fclose(fp);
+       audio_in_unprepare(input);
+       audio_in_destroy(input);
+
+       return 0;
+}
+
 static int _record_and_play(int length, int num, int ch)
 {
        int ret, size, i;
@@ -1036,6 +1138,8 @@ int main(int argc, char **argv)
                        _play_file_sample_sync(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
                else if (strcmp(argv[1], "playasync") == 0)
                        _play_file_sample_async(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
+               else if (strcmp(argv[1], "echocancel") == 0)
+                       _record_echocancel(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
        } else {
                printf("- Usages :\n");
                printf("- # audio_io_test loopback\n");
@@ -1044,6 +1148,7 @@ int main(int argc, char **argv)
                printf("- # audio_io_test async [write(1) | read(2)]\n");
                printf("- # audio_io_test play [filename] [sample rate] [channels] [type(0:U8,1:S16LE,2:S24LE,3:S24_32LE)]\n");
                printf("- # audio_io_test playasync [filename] [sample rate] [channels] [type(0:U8,1:S16LE,2:S24LE,3:S24_32LE)]\n");
+               printf("- # audio_io_test echocancel [filename] [sample rate] [channels] [ref_dev]\n");
        }
        return 0;
 }