mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
filter-chain: make it possible to suggest a samplerate
Make it possible to let a plugin suggest a samplerate for the filter. Make the convolver suggest the samplerate of the IR file anf use that if nothing else is specified in the config. Fixes #1659
This commit is contained in:
parent
275dfed92a
commit
d6469e5437
4 changed files with 20 additions and 11 deletions
|
|
@ -247,7 +247,7 @@ struct impl {
|
|||
unsigned int do_disconnect:1;
|
||||
unsigned int unloading:1;
|
||||
|
||||
uint32_t rate;
|
||||
long unsigned rate;
|
||||
|
||||
struct graph graph;
|
||||
};
|
||||
|
|
@ -1276,7 +1276,7 @@ static int setup_graph(struct graph *graph, struct spa_json *inputs, struct spa_
|
|||
sd = dd = NULL;
|
||||
|
||||
for (i = 0; i < n_hndl; i++) {
|
||||
if ((node->hndl[i] = d->instantiate(d, impl->rate, i, node->config)) == NULL) {
|
||||
if ((node->hndl[i] = d->instantiate(d, &impl->rate, i, node->config)) == NULL) {
|
||||
pw_log_error("cannot create plugin instance");
|
||||
res = -ENOMEM;
|
||||
goto error;
|
||||
|
|
@ -1308,6 +1308,14 @@ static int setup_graph(struct graph *graph, struct spa_json *inputs, struct spa_
|
|||
graph->n_control++;
|
||||
}
|
||||
}
|
||||
pw_log_info("suggested rate:%lu capture:%d playback:%d", impl->rate,
|
||||
impl->capture_info.rate, impl->playback_info.rate);
|
||||
|
||||
if (impl->capture_info.rate == 0)
|
||||
impl->capture_info.rate = impl->rate;
|
||||
if (impl->playback_info.rate == 0)
|
||||
impl->playback_info.rate = impl->rate;
|
||||
|
||||
/* now collect all input and output ports for all the handles. */
|
||||
for (i = 0; i < n_hndl; i++) {
|
||||
if (inputs == NULL) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ struct builtin {
|
|||
};
|
||||
|
||||
static void *builtin_instantiate(const struct fc_descriptor * Descriptor,
|
||||
unsigned long SampleRate, int index, const char *config)
|
||||
unsigned long *SampleRate, int index, const char *config)
|
||||
{
|
||||
struct builtin *impl;
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ static void *builtin_instantiate(const struct fc_descriptor * Descriptor,
|
|||
if (impl == NULL)
|
||||
return NULL;
|
||||
|
||||
impl->rate = SampleRate;
|
||||
impl->rate = *SampleRate;
|
||||
|
||||
return impl;
|
||||
}
|
||||
|
|
@ -469,7 +469,7 @@ struct convolver_impl {
|
|||
};
|
||||
|
||||
static float *read_samples(const char *filename, float gain, int delay, int offset,
|
||||
int length, int channel, int *n_samples)
|
||||
int length, int channel, long unsigned *rate, int *n_samples)
|
||||
{
|
||||
float *samples;
|
||||
#ifdef HAVE_SNDFILE
|
||||
|
|
@ -510,6 +510,7 @@ static float *read_samples(const char *filename, float gain, int delay, int offs
|
|||
samples[i] = samples[info.channels * i + channel] * gain;
|
||||
|
||||
*n_samples = n;
|
||||
*rate = info.samplerate;
|
||||
return samples;
|
||||
#else
|
||||
pw_log_error("compiled without sndfile support, can't load samples: "
|
||||
|
|
@ -570,7 +571,7 @@ static float *create_dirac(const char *filename, float gain, int delay, int offs
|
|||
}
|
||||
|
||||
static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
||||
unsigned long SampleRate, int index, const char *config)
|
||||
unsigned long *SampleRate, int index, const char *config)
|
||||
{
|
||||
struct convolver_impl *impl;
|
||||
float *samples;
|
||||
|
|
@ -642,7 +643,7 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
|||
length, &n_samples);
|
||||
} else {
|
||||
samples = read_samples(filename, gain, delay, offset,
|
||||
length, channel, &n_samples);
|
||||
length, channel, SampleRate, &n_samples);
|
||||
}
|
||||
if (samples == NULL)
|
||||
return NULL;
|
||||
|
|
@ -658,7 +659,7 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
|||
if (impl == NULL)
|
||||
return NULL;
|
||||
|
||||
impl->rate = SampleRate;
|
||||
impl->rate = *SampleRate;
|
||||
|
||||
impl->conv = convolver_new(blocksize, tailsize, samples, n_samples);
|
||||
free(samples);
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ struct descriptor {
|
|||
};
|
||||
|
||||
static void *ladspa_instantiate(const struct fc_descriptor *desc,
|
||||
unsigned long SampleRate, int index, const char *config)
|
||||
unsigned long *SampleRate, int index, const char *config)
|
||||
{
|
||||
struct descriptor *d = (struct descriptor *)desc;
|
||||
return d->d->instantiate(d->d, SampleRate);
|
||||
return d->d->instantiate(d->d, *SampleRate);
|
||||
}
|
||||
|
||||
static const LADSPA_Descriptor *find_desc(LADSPA_Descriptor_Function desc_func, const char *name)
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ struct fc_descriptor {
|
|||
struct fc_port *ports;
|
||||
|
||||
void *(*instantiate) (const struct fc_descriptor *desc,
|
||||
unsigned long SampleRate, int index, const char *config);
|
||||
unsigned long *SampleRate, int index, const char *config);
|
||||
|
||||
void (*cleanup) (void *instance);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue