Add some exception for plugins using fixed frame size 97/296397/2 accepted/tizen/unified/20230728.155801
authorJaechul Lee <jcsing.lee@samsung.com>
Thu, 27 Jul 2023 02:23:26 +0000 (11:23 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Thu, 27 Jul 2023 05:56:15 +0000 (14:56 +0900)
[Version] 0.0.10
[Issue Type] Update

Change-Id: I5f22a58762ee42926d9dfb3e70efe895faf9ebbd
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
packaging/libaudio-effect.spec
src/plugin_aec_webrtc.cpp
src/plugin_ns_rnnoise.c
src/plugin_ns_srid.c
test/ns_rnnoise_test.c
test/ns_srid_test.c

index 95bacf65c59a22ab18432e12ca14d3a4647bd1de..2beb14d31e68126f46f23a1a11b2fa5af585e661 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libaudio-effect
 Summary:    audio effect library
-Version:    0.0.9
+Version:    0.0.10
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 0bc35b32b0eae660355f48cefd8cca7d7002a41c..14a37f13b9d71fb7f55c44f34820c1171d296251 100644 (file)
@@ -28,7 +28,7 @@ extern "C" {
 audio_effect_plugin_info_s *__audio_effect_plugin_entry_point__(void);
 }
 
-#define DEFAULT_PROCESS_SIZE_MS 10
+#define FIXED_FRAME_SIZE_MSEC 10
 #define CHANNELS_MAX 2
 
 using namespace webrtc;
@@ -71,12 +71,12 @@ static void *aec_webrtc_create(int rate, int channels, audio_effect_format_e for
        if (!u)
                return NULL;
 
-       fixed_bytes = audio_effect_util_msec_to_bytes(DEFAULT_PROCESS_SIZE_MS, rate, channels, format);
+       fixed_bytes = audio_effect_util_msec_to_bytes(FIXED_FRAME_SIZE_MSEC, rate, channels, format);
        request_bytes = frames * audio_effect_util_get_frame_size(format, channels);
 
        if (fixed_bytes > request_bytes) {
                LOG_ERROR("frames should be bigger than %dms. frames(%zu) request_bytes(%zu)",
-                                               DEFAULT_PROCESS_SIZE_MS, frames, request_bytes);
+                                               FIXED_FRAME_SIZE_MSEC, frames, request_bytes);
                goto fail;
        }
 
@@ -244,7 +244,7 @@ static audio_effect_plugin_info_s aec_webrtc_desc = {
                .destroy = aec_webrtc_destroy,
        },
        .constraint = {
-               .frames_msec = 10,
+               .frames_msec = FIXED_FRAME_SIZE_MSEC,
                .min_rate = 8000,
                .max_rate = 48000,
                .min_channels = 1,
index dea0565d0c31c13462cfb5cba1f174c892e54b6a..2d8b47ba4f503899264a5bb2b8fbe5750390c28c 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <rnnoise.h>
 
+#define FIXED_FRAME_SIZE 480
+
 struct userdata {
        DenoiseState *st;
        int rate;
@@ -32,6 +34,8 @@ struct userdata {
        float *buffer;
 };
 
+static audio_effect_plugin_info_s ns_rnnoise_desc;
+
 static void *ns_rnnoise_create(int rate, int channels, audio_effect_format_e format, size_t frames)
 {
        struct userdata *u;
@@ -42,11 +46,18 @@ static void *ns_rnnoise_create(int rate, int channels, audio_effect_format_e for
        u->rate = rate;
        u->channels = channels;
        u->format = format;
-       u->frames = frames;
-       u->buffer = (float *)malloc(sizeof(float) * frames * channels);
+
+       if (frames != FIXED_FRAME_SIZE) {
+               LOG_WARN("Not support frames(%zu). It will be set to fixed frame_size(%u)",
+                               frames, FIXED_FRAME_SIZE);
+       }
+
+       u->frames = FIXED_FRAME_SIZE;
+
+       u->buffer = (float *)malloc(sizeof(float) * u->frames * channels);
 
        LOG_INFO("plugin rnnoise init. rate(%d), channels(%d), format(%d), frames(%zu)",
-                               rate, channels, format, frames);
+                               rate, channels, format, u->frames);
 
        return u;
 }
@@ -100,7 +111,7 @@ static audio_effect_plugin_info_s ns_rnnoise_desc = {
                .destroy = ns_rnnoise_destroy,
        },
        .constraint = {
-               .frames = 480,
+               .frames = FIXED_FRAME_SIZE,
                .min_rate = 48000,
                .max_rate = 48000,
                .min_channels = 1,
index 646c896096fc24efcb77d85e123e5f2d8358bce1..b298b5810147736e431c65878a7a651e40037b9b 100644 (file)
@@ -30,15 +30,15 @@ struct userdata {
        size_t frames;
 };
 
-static audio_effect_plugin_info_s ns_srid;
+static audio_effect_plugin_info_s ns_srid_desc;
 
-static void *ns_srid_create(int rate, int channels, audio_effect_format_e format, size_t frames)
+static void *ns_srid_create(int rate, int channels, audio_effect_format_e format, size_t req_frames)
 {
        struct userdata *u;
        noise_suppression_h handle;
-       unsigned int frame_size = frames;
+       unsigned int frame_size = (unsigned int)req_frames;
 
-       if (rate != 48000 && rate != 16000) {
+       if (rate != ns_srid_desc.constraint.min_rate && ns_srid_desc.constraint.max_rate != rate) {
                LOG_ERROR("Not support rate %d", rate);
                return NULL;
        }
@@ -48,25 +48,21 @@ static void *ns_srid_create(int rate, int channels, audio_effect_format_e format
                return NULL;
        }
 
-       if ((size_t)frame_size != frames) {
-               LOG_INFO("frames_size(%d) is not same with frame(%zu)", frame_size, frames);
-               ns_srid.constraint.frames = frame_size;
-       }
+       if ((size_t)frame_size != req_frames)
+               LOG_WARN("this solution supports only frames(%u), request framesize(%zu)", frame_size, req_frames);
 
        u = (struct userdata *)malloc(sizeof(struct userdata));
        u->handle = handle;
 
        /* framesize could be 960 in case of 48K (16K 320) */
-       frames = frame_size;
-
-       u->frames = frames;
-       u->buffer = (float *)malloc(sizeof(float) * frames);
-       ns_srid.constraint.frames = frames;
+       u->frames = (size_t)frame_size;
+       u->buffer = (float *)malloc(sizeof(float) * u->frames);
+       ns_srid_desc.constraint.frames = u->frames;
 
        noise_suppression_set_level(u->handle, NOISE_SUPPRESSION_LEVEL_MID);
 
-       LOG_INFO("plugin noise-suppression srid init. rate(%d), channels(%d), format(%d), frames(%zu), frame_size(%d)",
-                               rate, channels, format, frames, frame_size);
+       LOG_INFO("plugin noise-suppression srid init. rate(%d), channels(%d), format(%d), frames(%zu)",
+                               rate, channels, format, u->frames);
 
        return u;
 }
index fdb1419d8ca051c13eaa85b03b0c29260e4bccab..5f7a90afe9a8ecb92303fe340ffccaceae2c3cdf 100644 (file)
@@ -4,7 +4,8 @@
 
 #include "audio_effect.h"
 
-#define FRAME_SIZE (480)
+#define FRAME_SIZE 1024
+#define FIXED_FRAME_SIZE 480
 
 int main(void)
 {
@@ -35,10 +36,11 @@ int main(void)
        assert(ae);
 
        framesize = audio_effect_get_process_framesize(ae);
+       assert(framesize == FIXED_FRAME_SIZE);
        printf("frame size %zu\n", framesize);
 
        while (!feof(fin)) {
-               if (fread(in, sizeof(short), FRAME_SIZE, fin) < 0)
+               if (fread(in, sizeof(short), framesize, fin) < 0)
                        break;
 
                printf("#%d frame. ", i++);
@@ -47,7 +49,7 @@ int main(void)
                        printf("(failed!)\n");
                } else {
                        printf("(success!)\n");
-                       fwrite(out, sizeof(short), FRAME_SIZE, fout);
+                       fwrite(out, sizeof(short), framesize, fout);
                }
        }
 
index 28638022eef8fc4ce30f25927f7d6dc3a20e2f9a..7284f28cfba124d9413bdb46d711ef2b654c123a 100644 (file)
@@ -21,7 +21,8 @@ int main(void)
        const char *output_file[] = { "srid_out_48k.raw", "srid_out_16k.raw" };
 
        int loop = sizeof(source_file) / sizeof(char *);
-       int rate[] = { 48000, 16000 };
+       const int rate[] = { 48000, 16000 };
+       const size_t fixed_frame_size[] = { 960, 320 };
 
        for (i = 0; i < loop; i++) {
                printf("--- srid start ---\n");
@@ -41,11 +42,13 @@ int main(void)
                        exit(-1);
                }
 
+               printf("Try to create with framesize(%zu)", framesize);
+
                ae = audio_effect_create(AUDIO_EFFECT_METHOD_NS_SRID, rate[i], 1, AUDIO_EFFECT_FORMAT_S16, framesize);
                assert(ae);
 
                framesize = audio_effect_get_process_framesize(ae);
-               printf("setting frame size %zu\n", framesize);
+               assert(framesize == fixed_frame_size[i]);
 
                while (!feof(fin)) {
                        if (fread(in, sizeof(short), framesize, fin) < 0)