Add AGC speex function 11/295911/2 accepted/tizen/unified/20230719.170115
authorJaechul Lee <jcsing.lee@samsung.com>
Mon, 17 Jul 2023 06:28:41 +0000 (15:28 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Tue, 18 Jul 2023 04:08:20 +0000 (13:08 +0900)
[Version] 0.0.8
[Issue Type] update

Change-Id: I6d1b236666f00cbd1cc0ea1ff3903d4902c1f069
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
README.md
include/audio_effect.h
packaging/libaudio-effect.spec
src/audio_effect_interface.c
src/plugin_agc_speex.c
test/agc_speex_test.c [new file with mode: 0644]
test/meson.build
test/ns_srid_test.c

index a716e21d005bf7477dc890db40f642a714864950..0764a9568f57800312e2942d5d6b065be55f0526 100644 (file)
--- a/README.md
+++ b/README.md
@@ -2,8 +2,9 @@
 Additional audio pre-process methods.
 
 ## How to build
- * local : meson build --reconfigure [-Dtestsuite=enabled]  && ninja -C build clean && ninja -C build/
-   e.g) meson build --reconfigure -Db_sanitize=address -Db_coverage=true -Dtestsuite=enabled -Damplify=enabled -Dspeex-agc=enabled -Dns-rnnoise=enabled -Dns-srid=enabled -Drefcopy=enabled -Daec-speex=enabled -Daec-webrtc=enabled && ninja -C build clean && ninja -C build/
+ * local : meson build [-Dtestsuite=enabled]  && ninja -C build clean && ninja -C build/
+   e.g) meson build -Dtestsuite=enabled -Damplify=enabled -Dagc-speex=enabled -Dns-rnnoise=enabled -Dns-srid=enabled -Drefcopy=enabled -Daec-speex=enabled -Daec-webrtc=enabled && ninja -C build clean && ninja -C build/
+   e.g) meson build -Db_sanitize=address -Db_coverage=true -Dtestsuite=enabled -Damplify=enabled && ninja -C build clean && ninja -C build/
  * GBS : gbs build -A aarch64 --include-all
 
 ## How to test
index c6205cbd238b21c8976043c644f803d32642b420..599160cffeb9d4ec6a75962c9a3efd962b51264e 100644 (file)
 
 typedef struct audio_effect_interface audio_effect_interface_s;
 typedef enum {
-       AUDIO_EFFECT_METHOD_REFCOPY, /* synthesis reference source into recording source */
-
-       /* Acoustic Echo Cancellation */
-       AUDIO_EFFECT_METHOD_AEC_SPEEX, /* aec from speexdsp */
-       AUDIO_EFFECT_METHOD_AEC_WEBRTC, /* aec from webrtc-audio-processing */
-
-       /* Noise Suppression */
-       AUDIO_EFFECT_METHOD_NS_PSE, /* SAIC NS solution */
-       AUDIO_EFFECT_METHOD_NS_RNNOISE, /* RNNoise */
-       AUDIO_EFFECT_METHOD_NS_SRID, /* SRID solution */
+       AUDIO_EFFECT_METHOD_REFCOPY,    /* Synthesis the reference source into the recording source */
+       AUDIO_EFFECT_METHOD_AEC_SPEEX,  /* Acoustic Echo Cancellation with speex */
+       AUDIO_EFFECT_METHOD_AEC_WEBRTC, /* Acoustic Echo Cancellation with webrtc */
+       AUDIO_EFFECT_METHOD_NS_PSE,     /* Noise Suppression with PSE(SAIC) */
+       AUDIO_EFFECT_METHOD_NS_RNNOISE, /* Noise suppression with RNNoise */
+       AUDIO_EFFECT_METHOD_NS_SRID,    /* Noise suppression from SRID */
+       AUDIO_EFFECT_METHOD_AGC_SPEEX,  /* Automatic Gain Control with speex */
 
        /* Template */
        AUDIO_EFFECT_METHOD_AMPLIFY,
-
-       /* Experiment */
-       AUDIO_EFFECT_METHOD_AGC_SPEEX,
        AUDIO_EFFECT_METHOD_MAX,
 } audio_effect_method_e;
 
index 2f0bf7f2a52cf5c3a5c8098447a83db7c8369992..3a50cf64ef7e65c159560ac282c00ee3b988cdf4 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libaudio-effect
 Summary:    audio effect library
-Version:    0.0.7
+Version:    0.0.8
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
@@ -35,6 +35,7 @@ MMSound development package for audio effect
        -Dns-rnnoise=enabled \
        -Daec-webrtc=enabled \
 %endif
+       -Dagc-speex=enabled \
        -Drefcopy=enabled \
        -Daec-speex=enabled \
        -Dns-srid=enabled
index 988078c0efca24b286d4bf2c2e4bc1db17b30a5e..e9b7df1ab2a2233346f32dd931ca5d18df9335a8 100644 (file)
@@ -37,10 +37,12 @@ static const char *effect_path_list[] = {
        [AUDIO_EFFECT_METHOD_NS_PSE] = DL_PLUGIN_PATH "libaudio-effect-ns-pse.so",
        [AUDIO_EFFECT_METHOD_NS_RNNOISE] = DL_PLUGIN_PATH "libaudio-effect-ns-rnnoise.so",
        [AUDIO_EFFECT_METHOD_NS_SRID] = DL_PLUGIN_PATH "libaudio-effect-ns-srid.so",
-       [AUDIO_EFFECT_METHOD_AMPLIFY] = DL_PLUGIN_PATH "libaudio-effect-amplify.so",
        [AUDIO_EFFECT_METHOD_AGC_SPEEX] = DL_PLUGIN_PATH "libaudio-effect-agc-speex.so",
+       [AUDIO_EFFECT_METHOD_AMPLIFY] = DL_PLUGIN_PATH "libaudio-effect-amplify.so",
 };
 
+static_assert(sizeof(effect_path_list) / sizeof(char *) == AUDIO_EFFECT_METHOD_MAX);
+
 static struct plugin_list {
        void *handle;
        int refcnt;
index 566c3f70089945229e3fc80247cf4e4f35b08e54..d6484302aaa347ea4ff42ffe5e5d552609618e06 100644 (file)
@@ -39,11 +39,6 @@ void *speex_agc_create(int rate, int channels, audio_effect_format_e format, siz
 
        int denoise_enabled = 1;
        int agc_enabled = 1;
-       float target_level = 0; // The target audio level in dBFS
-       //float target_level = -20; // The target audio level in dBFS
-       float max_gain = 0; // The maximum audio gain in dB
-       //float max_gain = 30; // The maximum audio gain in dB
-       int agc_level = 8000;
 
        SpeexPreprocessState *st;
 
@@ -51,9 +46,6 @@ void *speex_agc_create(int rate, int channels, audio_effect_format_e format, siz
 
        speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DENOISE, &denoise_enabled);
        speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &agc_enabled);
-       speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_TARGET, &target_level);
-       speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_MAX_GAIN, &max_gain);
-       speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &agc_level);
 
        u->frames = frames;
        u->st = st;
@@ -95,7 +87,7 @@ void speex_agc_destroy(void *priv)
 }
 
 static audio_effect_plugin_info_s speex_agc = {
-       .name = "speex-agc",
+       .name = "agc-speex",
        .interface = {
                .method = AUDIO_EFFECT_METHOD_AGC_SPEEX,
                .create = speex_agc_create,
diff --git a/test/agc_speex_test.c b/test/agc_speex_test.c
new file mode 100644 (file)
index 0000000..b46ea91
--- /dev/null
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "audio_effect.h"
+
+#define FRAME_SIZE (160)
+
+int main(void)
+{
+       audio_effect_s *ae;
+       FILE *fin;
+       FILE *fout;
+       short in[FRAME_SIZE];
+       short out[FRAME_SIZE];
+       size_t framesize = FRAME_SIZE;
+
+       int i=0;
+
+       printf("--- agc speex start ---\n");
+
+       fin = fopen("obama.raw", "r");
+       if (!fin) {
+               printf("failed to find airport_48k.raw\n");
+               exit(-1);
+       }
+
+       fout = fopen("agc_speex_out.raw", "wb");
+       if (!fout) {
+               printf("failed to open raw\n");
+               exit(-1);
+       }
+
+       ae = audio_effect_create(AUDIO_EFFECT_METHOD_AGC_SPEEX, 16000, 1, AUDIO_EFFECT_FORMAT_S16, framesize);
+       assert(ae);
+
+       framesize = audio_effect_get_process_framesize(ae);
+       printf("frame size %zu\n", framesize);
+
+       while (!feof(fin)) {
+               if (fread(in, sizeof(short), FRAME_SIZE, fin) < 0)
+                       break;
+
+               printf("#%d frame. ", i++);
+
+               if (audio_effect_process(ae, in, out) < 0) {
+                       printf("(failed!)\n");
+               } else {
+                       printf("(success!)\n");
+                       fwrite(out, sizeof(short), FRAME_SIZE, fout);
+               }
+       }
+
+       audio_effect_destroy(ae);
+
+       fclose(fin);
+       fclose(fout);
+
+       printf("--- agc speex end ---\n");
+
+       return 0;
+}
index c88cbf5be3c278b9a2ebf0c4be7608d6c0453b5c..7c7e918ed697a3f73b00d6e786e8402d7e2f0d0f 100644 (file)
@@ -26,6 +26,10 @@ if get_option('aec-webrtc').enabled()
   test_list += [[ 'aec_webrtc_test', 'aec_webrtc_test.c' ]]
 endif
 
+if get_option('agc-speex').enabled()
+  test_list += [[ 'agc_speex_test', 'agc_speex_test.c' ]]
+endif
+
 testsuite_env = environment()
 testsuite_env.set('LD_LIBRARY_PATH', './')
 
index 0e63e87dfa45fb29b720dca939ac9e02ad79b5fd..28638022eef8fc4ce30f25927f7d6dc3a20e2f9a 100644 (file)
@@ -31,13 +31,13 @@ int main(void)
 
                fin = fopen(source_file[i], "r");
                if (!fin) {
-                       printf("failed to find airport_48k.raw\n");
+                       printf("failed to find the source file. file(%s)\n", source_file[i]);
                        exit(-1);
                }
 
                fout = fopen(output_file[i], "wb");
                if (!fout) {
-                       printf("failed to open raw\n");
+                       printf("failed to open output file. file(%s)\n", output_file[i]);
                        exit(-1);
                }