mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05: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 do_disconnect:1;
|
||||||
unsigned int unloading:1;
|
unsigned int unloading:1;
|
||||||
|
|
||||||
uint32_t rate;
|
long unsigned rate;
|
||||||
|
|
||||||
struct graph graph;
|
struct graph graph;
|
||||||
};
|
};
|
||||||
|
|
@ -1276,7 +1276,7 @@ static int setup_graph(struct graph *graph, struct spa_json *inputs, struct spa_
|
||||||
sd = dd = NULL;
|
sd = dd = NULL;
|
||||||
|
|
||||||
for (i = 0; i < n_hndl; i++) {
|
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");
|
pw_log_error("cannot create plugin instance");
|
||||||
res = -ENOMEM;
|
res = -ENOMEM;
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -1308,6 +1308,14 @@ static int setup_graph(struct graph *graph, struct spa_json *inputs, struct spa_
|
||||||
graph->n_control++;
|
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. */
|
/* now collect all input and output ports for all the handles. */
|
||||||
for (i = 0; i < n_hndl; i++) {
|
for (i = 0; i < n_hndl; i++) {
|
||||||
if (inputs == NULL) {
|
if (inputs == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ struct builtin {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *builtin_instantiate(const struct fc_descriptor * Descriptor,
|
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;
|
struct builtin *impl;
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ static void *builtin_instantiate(const struct fc_descriptor * Descriptor,
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
impl->rate = SampleRate;
|
impl->rate = *SampleRate;
|
||||||
|
|
||||||
return impl;
|
return impl;
|
||||||
}
|
}
|
||||||
|
|
@ -469,7 +469,7 @@ struct convolver_impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
static float *read_samples(const char *filename, float gain, int delay, int offset,
|
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;
|
float *samples;
|
||||||
#ifdef HAVE_SNDFILE
|
#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;
|
samples[i] = samples[info.channels * i + channel] * gain;
|
||||||
|
|
||||||
*n_samples = n;
|
*n_samples = n;
|
||||||
|
*rate = info.samplerate;
|
||||||
return samples;
|
return samples;
|
||||||
#else
|
#else
|
||||||
pw_log_error("compiled without sndfile support, can't load samples: "
|
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,
|
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;
|
struct convolver_impl *impl;
|
||||||
float *samples;
|
float *samples;
|
||||||
|
|
@ -642,7 +643,7 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
||||||
length, &n_samples);
|
length, &n_samples);
|
||||||
} else {
|
} else {
|
||||||
samples = read_samples(filename, gain, delay, offset,
|
samples = read_samples(filename, gain, delay, offset,
|
||||||
length, channel, &n_samples);
|
length, channel, SampleRate, &n_samples);
|
||||||
}
|
}
|
||||||
if (samples == NULL)
|
if (samples == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -658,7 +659,7 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
impl->rate = SampleRate;
|
impl->rate = *SampleRate;
|
||||||
|
|
||||||
impl->conv = convolver_new(blocksize, tailsize, samples, n_samples);
|
impl->conv = convolver_new(blocksize, tailsize, samples, n_samples);
|
||||||
free(samples);
|
free(samples);
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,10 @@ struct descriptor {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *ladspa_instantiate(const struct fc_descriptor *desc,
|
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;
|
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)
|
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;
|
struct fc_port *ports;
|
||||||
|
|
||||||
void *(*instantiate) (const struct fc_descriptor *desc,
|
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);
|
void (*cleanup) (void *instance);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue