From 71dc8d6407a83e1923e84cb10aaa2bdc98cc0c2f Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 26 Jul 2016 05:06:26 -0700 Subject: [PATCH] obs-filters: Add comments to noise suppression filter These comments have been added to clean up the code and make it more clear of what the code is doing. The code felt a bit messy, and this should help prevent the original author of the noise suppression filter from being lost in case he decides to modify/improve the filter. --- plugins/obs-filters/noise-suppress-filter.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/obs-filters/noise-suppress-filter.c b/plugins/obs-filters/noise-suppress-filter.c index 0084001c5..99cdb3aba 100644 --- a/plugins/obs-filters/noise-suppress-filter.c +++ b/plugins/obs-filters/noise-suppress-filter.c @@ -206,28 +206,40 @@ static struct obs_audio_data *noise_suppress_filter_audio(void *data, if (!ng->states[0]) return audio; + /* ----------------------------------------------- + * if timestamp has dramatically changed, consider it a new stream of + * audio data. clear all circular buffers to prevent old audio data + * from being processed as part of the new data. */ if (ng->last_timestamp) { int64_t diff = llabs((int64_t)ng->last_timestamp - (int64_t)audio->timestamp); - /* if timestamp has dramatically changed, reset audio data */ if (diff > 1000000000LL) reset_data(ng); } + ng->last_timestamp = audio->timestamp; + + /* ----------------------------------------------- + * push audio packet info (timestamp/frame count) to info circlebuf */ info.frames = audio->frames; info.timestamp = audio->timestamp; circlebuf_push_back(&ng->info_buffer, &info, sizeof(info)); - ng->last_timestamp = audio->timestamp; - + /* ----------------------------------------------- + * push back current audio data to input circlebuf */ for (size_t i = 0; i < ng->channels; i++) circlebuf_push_back(&ng->input_buffers[i], audio->data[i], audio->frames * sizeof(float)); + /* ----------------------------------------------- + * pop/process each 10ms segments, push back to output circlebuf */ while (ng->input_buffers[0].size >= segment_size) process(ng); + /* ----------------------------------------------- + * peek front of info circlebuf, check to see if we have enough to + * pop the expected packet size, if not, return null */ memset(&info, 0, sizeof(info)); circlebuf_peek_front(&ng->info_buffer, &info, sizeof(info)); out_size = info.frames * sizeof(float); @@ -235,6 +247,9 @@ static struct obs_audio_data *noise_suppress_filter_audio(void *data, if (ng->output_buffers[0].size < out_size) return NULL; + /* ----------------------------------------------- + * if there's enough audio data buffered in the output circlebuf, + * pop and return a packet */ circlebuf_pop_front(&ng->info_buffer, NULL, sizeof(info)); da_resize(ng->output_data, out_size * ng->channels);