Name: libaudio-effect
Summary: audio effect library
-Version: 0.0.9
+Version: 0.0.10
Release: 0
Group: System/Libraries
License: Apache-2.0
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;
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;
}
.destroy = aec_webrtc_destroy,
},
.constraint = {
- .frames_msec = 10,
+ .frames_msec = FIXED_FRAME_SIZE_MSEC,
.min_rate = 8000,
.max_rate = 48000,
.min_channels = 1,
#include <rnnoise.h>
+#define FIXED_FRAME_SIZE 480
+
struct userdata {
DenoiseState *st;
int rate;
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;
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;
}
.destroy = ns_rnnoise_destroy,
},
.constraint = {
- .frames = 480,
+ .frames = FIXED_FRAME_SIZE,
.min_rate = 48000,
.max_rate = 48000,
.min_channels = 1,
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;
}
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;
}
#include "audio_effect.h"
-#define FRAME_SIZE (480)
+#define FRAME_SIZE 1024
+#define FIXED_FRAME_SIZE 480
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++);
printf("(failed!)\n");
} else {
printf("(success!)\n");
- fwrite(out, sizeof(short), FRAME_SIZE, fout);
+ fwrite(out, sizeof(short), framesize, fout);
}
}
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");
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)