#include <pulsecore/resampler.h>
#include <pulsecore/core-util.h>
+#include <assert.h>
#include "processor.h"
#ifdef __DEBUG__
#define debug_close_file(x)
#endif
+struct method_info {
+ audio_effect_method_e audio_effect_method;
+ const char *method_str;
+ bool need_reference;
+};
+
+static struct method_info method_table[] = {
+ [PROCESSOR_METHOD_AEC_SPEEX] =
+ { AUDIO_EFFECT_METHOD_AEC_SPEEX, "aec-speex", true },
+ [PROCESSOR_METHOD_AEC_WEBRTC] =
+ { AUDIO_EFFECT_METHOD_AEC_WEBRTC, "aec-webrtc", true },
+ [PROCESSOR_METHOD_REFERENCE_COPY] =
+ { AUDIO_EFFECT_METHOD_REFCOPY, "reference_copy", true },
+ [PROCESSOR_METHOD_NS_RNNOISE] =
+ { AUDIO_EFFECT_METHOD_NS_RNNOISE, "ns-rnnoise", false },
+ [PROCESSOR_METHOD_NS_PSE] =
+ { AUDIO_EFFECT_METHOD_NS_PSE, "ns-pse", false },
+ [PROCESSOR_METHOD_NS_SRID] =
+ { AUDIO_EFFECT_METHOD_NS_SRID, "ns-srid", false },
+};
+
+static_assert(sizeof(method_table) / sizeof(struct method_info) == PROCESSOR_METHOD_MAX);
+
static size_t pa_processor_usec_to_frame(pa_usec_t usec, pa_sample_spec *spec) {
pa_assert(spec);
}
static int pa_processor_convert_method(pa_processor_method_t method, audio_effect_method_e *audio_effect_method) {
- int ret = 0;
-
- switch (method) {
- case PROCESSOR_METHOD_SPEEX:
- *audio_effect_method = AUDIO_EFFECT_METHOD_AEC_SPEEX;
- break;
- case PROCESSOR_METHOD_WEBRTC:
- *audio_effect_method = AUDIO_EFFECT_METHOD_AEC_WEBRTC;
- break;
- case PROCESSOR_METHOD_REFERENCE_COPY:
- *audio_effect_method = AUDIO_EFFECT_METHOD_AEC_REFCOPY;
- break;
- case PROCESSOR_METHOD_RNNOISE:
- *audio_effect_method = AUDIO_EFFECT_METHOD_NS_RNNOISE;
- break;
- case PROCESSOR_METHOD_NONE_PSE:
- *audio_effect_method = AUDIO_EFFECT_METHOD_NS_PSE;
- break;
- default:
- ret = -1;
- break;
+ if (method >= PROCESSOR_METHOD_MAX) {
+ pa_log_error("invalid processor method(%d)", method);
+ return -1;
}
- return ret;
+ *audio_effect_method = method_table[method].audio_effect_method;
+
+ return 0;
}
static int pa_processor_convert_format(pa_sample_format_t f, audio_effect_format_e *format) {
ochunk.length = chunk->length;
ochunk.memblock = pa_memblock_new(processor->core->mempool, ochunk.length);
- recording = (uint8_t *)pa_memblock_acquire_chunk(chunk);
- output = (uint8_t *)pa_memblock_acquire_chunk(&ochunk);
+ recording = (int8_t *)pa_memblock_acquire_chunk(chunk);
+ output = (int8_t *)pa_memblock_acquire_chunk(&ochunk);
debug_timestamp_begin(processor);
}
const char *pa_processor_method_str(pa_processor_method_t method) {
- static const char *method_table[] = {
- [PROCESSOR_METHOD_SPEEX] = "speex",
- [PROCESSOR_METHOD_WEBRTC] = "webrtc",
- [PROCESSOR_METHOD_REFERENCE_COPY] = "reference_copy",
- [PROCESSOR_METHOD_RNNOISE] = "rnnoise",
- [PROCESSOR_METHOD_NONE_PSE] = "none-pse" };
-
if (method >= PROCESSOR_METHOD_MAX)
return NULL;
- return method_table[method];
+ return method_table[method].method_str;
}
int pa_processor_method_enum(const char *method, pa_processor_method_t *m) {
+ int i;
+
pa_assert(method);
pa_assert(m);
- if (pa_streq(method, "speex"))
- *m = PROCESSOR_METHOD_SPEEX;
- else if (pa_streq(method, "webrtc"))
- *m = PROCESSOR_METHOD_WEBRTC;
- else if (pa_streq(method, "reference_copy"))
- *m = PROCESSOR_METHOD_REFERENCE_COPY;
- else if (pa_streq(method, "rnnoise"))
- *m = PROCESSOR_METHOD_RNNOISE;
- else if (pa_streq(method, "pse"))
- *m = PROCESSOR_METHOD_NONE_PSE;
- else
- return -1;
+ for (i = 0; i < PROCESSOR_METHOD_MAX; i++) {
+ if (pa_streq(method, method_table[i].method_str)) {
+ *m = i;
+ return 0;
+ }
+ }
- return 0;
+ return -1;
}
bool pa_processor_method_need_reference_structure(pa_processor_method_t m) {
- if (m == PROCESSOR_METHOD_SPEEX)
- return true;
- else if (m == PROCESSOR_METHOD_WEBRTC)
- return true;
- else if (m == PROCESSOR_METHOD_REFERENCE_COPY)
- return true;
-
- return false;
+ if (m >= PROCESSOR_METHOD_MAX)
+ return false;
+
+ return method_table[m].need_reference;
}
void pa_processor_attach_reference(pa_processor *processor, pa_processor_reference *reference) {