mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
filter-chain: convolver: resample IR
Ensure correct filtering when node rate does not match filter rate
This commit is contained in:
parent
b5c21c1fbc
commit
7950d3ff0d
2 changed files with 25 additions and 3 deletions
|
|
@ -100,7 +100,7 @@ filter_chain_sources = [
|
|||
'module-filter-chain/convolver.c'
|
||||
]
|
||||
filter_chain_dependencies = [
|
||||
mathlib, dl_lib, pipewire_dep, sndfile_dep
|
||||
mathlib, dl_lib, pipewire_dep, sndfile_dep, audioconvert_dep
|
||||
]
|
||||
|
||||
if lilv_lib.found()
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include <spa/utils/json.h>
|
||||
#include <spa/support/cpu.h>
|
||||
#include <spa/plugins/audioconvert/resample.h>
|
||||
|
||||
#include <pipewire/log.h>
|
||||
|
||||
|
|
@ -635,8 +636,29 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
|||
samples = read_samples(filename, gain, delay, offset,
|
||||
length, channel, &rate, &n_samples);
|
||||
if (rate != SampleRate) {
|
||||
pw_log_warn("Convolver samplerate %lu doesn't match filter rate %lu. "
|
||||
"Consider forcing a filter rate.", rate, SampleRate);
|
||||
pw_log_info("Convolver running rate %lu doesn't match filter file rate %lu, "
|
||||
"resampling filter (len: %d)", SampleRate, rate, n_samples);
|
||||
float *samples_original = samples;
|
||||
uint32_t in_len = n_samples;
|
||||
uint32_t out_len = in_len * SampleRate / rate;
|
||||
samples = calloc(out_len, sizeof(float));
|
||||
|
||||
struct resample r;
|
||||
spa_zero(r);
|
||||
r.channels = 1;
|
||||
r.i_rate = rate;
|
||||
r.o_rate = SampleRate;
|
||||
r.quality = RESAMPLE_DEFAULT_QUALITY;
|
||||
if (resample_native_init(&r) < 0) {
|
||||
pw_log_error("resampling failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
resample_process(&r, (void *)&samples_original, &in_len, (void *)&samples, &out_len);
|
||||
|
||||
free(samples_original);
|
||||
n_samples = out_len;
|
||||
rate = SampleRate;
|
||||
}
|
||||
}
|
||||
if (samples == NULL) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue