audiofx: adjust to changed semantics of audiofilter _setup method

... in that it will now call subclass with info on proposed audio format
without having set that info already in base class.  As such,
subclass can not rely on audio format info being available there.
This commit is contained in:
Mark Nauwelaerts 2012-03-23 18:42:48 +01:00
parent 06f1c1817e
commit 9041a588f9
8 changed files with 93 additions and 47 deletions

View file

@ -389,9 +389,15 @@ generate_biquad_coefficients (GstAudioChebBand * filter,
} }
static void static void
generate_coefficients (GstAudioChebBand * filter) generate_coefficients (GstAudioChebBand * filter, const GstAudioInfo * info)
{ {
gint rate = GST_AUDIO_FILTER_RATE (filter); gint rate;
if (info) {
rate = GST_AUDIO_INFO_RATE (info);
} else {
rate = GST_AUDIO_FILTER_RATE (filter);
}
if (rate == 0) { if (rate == 0) {
gdouble *a = g_new0 (gdouble, 1); gdouble *a = g_new0 (gdouble, 1);
@ -572,37 +578,37 @@ gst_audio_cheb_band_set_property (GObject * object, guint prop_id,
case PROP_MODE: case PROP_MODE:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->mode = g_value_get_enum (value); filter->mode = g_value_get_enum (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_TYPE: case PROP_TYPE:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->type = g_value_get_int (value); filter->type = g_value_get_int (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_LOWER_FREQUENCY: case PROP_LOWER_FREQUENCY:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->lower_frequency = g_value_get_float (value); filter->lower_frequency = g_value_get_float (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_UPPER_FREQUENCY: case PROP_UPPER_FREQUENCY:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->upper_frequency = g_value_get_float (value); filter->upper_frequency = g_value_get_float (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_RIPPLE: case PROP_RIPPLE:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->ripple = g_value_get_float (value); filter->ripple = g_value_get_float (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_POLES: case PROP_POLES:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->poles = GST_ROUND_UP_4 (g_value_get_int (value)); filter->poles = GST_ROUND_UP_4 (g_value_get_int (value));
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
default: default:
@ -649,7 +655,7 @@ gst_audio_cheb_band_setup (GstAudioFilter * base, const GstAudioInfo * info)
{ {
GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (base); GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (base);
generate_coefficients (filter); generate_coefficients (filter, info);
return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info); return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info);
} }

View file

@ -343,9 +343,19 @@ generate_biquad_coefficients (GstAudioChebLimit * filter,
} }
static void static void
generate_coefficients (GstAudioChebLimit * filter) generate_coefficients (GstAudioChebLimit * filter, const GstAudioInfo * info)
{ {
if (GST_AUDIO_FILTER_RATE (filter) == 0) { gint rate;
if (info) {
rate = GST_AUDIO_INFO_RATE (info);
} else {
rate = GST_AUDIO_FILTER_RATE (filter);
}
GST_LOG_OBJECT (filter, "cutoff %f", filter->cutoff);
if (rate == 0) {
gdouble *a = g_new0 (gdouble, 1); gdouble *a = g_new0 (gdouble, 1);
gdouble *b = g_new0 (gdouble, 1); gdouble *b = g_new0 (gdouble, 1);
@ -358,7 +368,7 @@ generate_coefficients (GstAudioChebLimit * filter)
return; return;
} }
if (filter->cutoff >= GST_AUDIO_FILTER_RATE (filter) / 2.0) { if (filter->cutoff >= rate / 2.0) {
gdouble *a = g_new0 (gdouble, 1); gdouble *a = g_new0 (gdouble, 1);
gdouble *b = g_new0 (gdouble, 1); gdouble *b = g_new0 (gdouble, 1);
@ -492,31 +502,31 @@ gst_audio_cheb_limit_set_property (GObject * object, guint prop_id,
case PROP_MODE: case PROP_MODE:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->mode = g_value_get_enum (value); filter->mode = g_value_get_enum (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_TYPE: case PROP_TYPE:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->type = g_value_get_int (value); filter->type = g_value_get_int (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_CUTOFF: case PROP_CUTOFF:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->cutoff = g_value_get_float (value); filter->cutoff = g_value_get_float (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_RIPPLE: case PROP_RIPPLE:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->ripple = g_value_get_float (value); filter->ripple = g_value_get_float (value);
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
case PROP_POLES: case PROP_POLES:
g_mutex_lock (&filter->lock); g_mutex_lock (&filter->lock);
filter->poles = GST_ROUND_UP_2 (g_value_get_int (value)); filter->poles = GST_ROUND_UP_2 (g_value_get_int (value));
generate_coefficients (filter); generate_coefficients (filter, NULL);
g_mutex_unlock (&filter->lock); g_mutex_unlock (&filter->lock);
break; break;
default: default:
@ -560,7 +570,7 @@ gst_audio_cheb_limit_setup (GstAudioFilter * base, const GstAudioInfo * info)
{ {
GstAudioChebLimit *filter = GST_AUDIO_CHEB_LIMIT (base); GstAudioChebLimit *filter = GST_AUDIO_CHEB_LIMIT (base);
generate_coefficients (filter); generate_coefficients (filter, info);
return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info); return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info);
} }

View file

@ -163,7 +163,7 @@ gst_audio_fir_filter_update_kernel (GstAudioFIRFilter * self, GValueArray * va)
} }
gst_audio_fx_base_fir_filter_set_kernel (GST_AUDIO_FX_BASE_FIR_FILTER (self), gst_audio_fx_base_fir_filter_set_kernel (GST_AUDIO_FX_BASE_FIR_FILTER (self),
kernel, self->kernel->n_values, self->latency); kernel, self->kernel->n_values, self->latency, NULL);
} }
static void static void

View file

@ -880,6 +880,8 @@ gst_audio_fx_base_fir_filter_transform (GstBaseTransform * base,
gint64 tmp = diff; gint64 tmp = diff;
diff = generated_samples - diff; diff = generated_samples - diff;
generated_samples = tmp; generated_samples = tmp;
} else {
diff = 0;
} }
gst_buffer_resize (outbuf, diff * bps * channels, gst_buffer_resize (outbuf, diff * bps * channels,
@ -1027,9 +1029,12 @@ gst_audio_fx_base_fir_filter_sink_event (GstBaseTransform * base,
void void
gst_audio_fx_base_fir_filter_set_kernel (GstAudioFXBaseFIRFilter * self, gst_audio_fx_base_fir_filter_set_kernel (GstAudioFXBaseFIRFilter * self,
gdouble * kernel, guint kernel_length, guint64 latency) gdouble * kernel, guint kernel_length, guint64 latency,
const GstAudioInfo * info)
{ {
gboolean latency_changed; gboolean latency_changed;
GstAudioFormat format;
gint channels;
g_return_if_fail (kernel != NULL); g_return_if_fail (kernel != NULL);
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);
@ -1064,9 +1069,16 @@ gst_audio_fx_base_fir_filter_set_kernel (GstAudioFXBaseFIRFilter * self,
self->kernel = kernel; self->kernel = kernel;
self->kernel_length = kernel_length; self->kernel_length = kernel_length;
if (info) {
format = GST_AUDIO_INFO_FORMAT (info);
channels = GST_AUDIO_INFO_CHANNELS (info);
} else {
format = GST_AUDIO_FILTER_FORMAT (self);
channels = GST_AUDIO_FILTER_CHANNELS (self);
}
gst_audio_fx_base_fir_filter_calculate_frequency_response (self); gst_audio_fx_base_fir_filter_calculate_frequency_response (self);
gst_audio_fx_base_fir_filter_select_process_function (self, gst_audio_fx_base_fir_filter_select_process_function (self, format, channels);
GST_AUDIO_FILTER_FORMAT (self), GST_AUDIO_FILTER_CHANNELS (self));
if (latency_changed) { if (latency_changed) {
self->latency = latency; self->latency = latency;

View file

@ -93,7 +93,8 @@ struct _GstAudioFXBaseFIRFilterClass {
}; };
GType gst_audio_fx_base_fir_filter_get_type (void); GType gst_audio_fx_base_fir_filter_get_type (void);
void gst_audio_fx_base_fir_filter_set_kernel (GstAudioFXBaseFIRFilter *filter, gdouble *kernel, guint kernel_length, guint64 latency); void gst_audio_fx_base_fir_filter_set_kernel (GstAudioFXBaseFIRFilter *filter, gdouble *kernel,
guint kernel_length, guint64 latency, const GstAudioInfo * info);
void gst_audio_fx_base_fir_filter_push_residue (GstAudioFXBaseFIRFilter *filter); void gst_audio_fx_base_fir_filter_push_residue (GstAudioFXBaseFIRFilter *filter);
G_END_DECLS G_END_DECLS

View file

@ -161,12 +161,17 @@ gst_audio_karaoke_init (GstAudioKaraoke * filter)
} }
static void static void
update_filter (GstAudioKaraoke * filter) update_filter (GstAudioKaraoke * filter, const GstAudioInfo * info)
{ {
gfloat A, B, C; gfloat A, B, C;
gint rate; gint rate;
rate = GST_AUDIO_FILTER_RATE (filter); if (info) {
rate = GST_AUDIO_INFO_RATE (info);
} else {
rate = GST_AUDIO_FILTER_RATE (filter);
}
if (rate == 0) if (rate == 0)
return; return;
@ -198,11 +203,11 @@ gst_audio_karaoke_set_property (GObject * object, guint prop_id,
break; break;
case PROP_FILTER_BAND: case PROP_FILTER_BAND:
filter->filter_band = g_value_get_float (value); filter->filter_band = g_value_get_float (value);
update_filter (filter); update_filter (filter, NULL);
break; break;
case PROP_FILTER_WIDTH: case PROP_FILTER_WIDTH:
filter->filter_width = g_value_get_float (value); filter->filter_width = g_value_get_float (value);
update_filter (filter); update_filter (filter, NULL);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -258,7 +263,7 @@ gst_audio_karaoke_setup (GstAudioFilter * base, const GstAudioInfo * info)
ret = FALSE; ret = FALSE;
break; break;
} }
update_filter (filter); update_filter (filter, info);
return ret; return ret;
} }

View file

@ -220,7 +220,8 @@ gst_audio_wsincband_init (GstAudioWSincBand * self)
} }
static void static void
gst_audio_wsincband_build_kernel (GstAudioWSincBand * self) gst_audio_wsincband_build_kernel (GstAudioWSincBand * self,
const GstAudioInfo * info)
{ {
gint i = 0; gint i = 0;
gdouble sum = 0.0; gdouble sum = 0.0;
@ -232,8 +233,13 @@ gst_audio_wsincband_build_kernel (GstAudioWSincBand * self)
len = self->kernel_length; len = self->kernel_length;
rate = GST_AUDIO_FILTER_RATE (self); if (info) {
channels = GST_AUDIO_FILTER_CHANNELS (self); rate = GST_AUDIO_INFO_RATE (info);
channels = GST_AUDIO_INFO_CHANNELS (info);
} else {
rate = GST_AUDIO_FILTER_RATE (self);
channels = GST_AUDIO_FILTER_CHANNELS (self);
}
if (rate == 0) { if (rate == 0) {
GST_DEBUG ("rate not set yet"); GST_DEBUG ("rate not set yet");
@ -365,7 +371,7 @@ gst_audio_wsincband_build_kernel (GstAudioWSincBand * self)
} }
gst_audio_fx_base_fir_filter_set_kernel (GST_AUDIO_FX_BASE_FIR_FILTER (self), gst_audio_fx_base_fir_filter_set_kernel (GST_AUDIO_FX_BASE_FIR_FILTER (self),
kernel, self->kernel_length, (len - 1) / 2); kernel, self->kernel_length, (len - 1) / 2, info);
} }
/* GstAudioFilter vmethod implementations */ /* GstAudioFilter vmethod implementations */
@ -376,7 +382,7 @@ gst_audio_wsincband_setup (GstAudioFilter * base, const GstAudioInfo * info)
{ {
GstAudioWSincBand *self = GST_AUDIO_WSINC_BAND (base); GstAudioWSincBand *self = GST_AUDIO_WSINC_BAND (base);
gst_audio_wsincband_build_kernel (self); gst_audio_wsincband_build_kernel (self, info);
return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info); return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info);
} }
@ -412,7 +418,7 @@ gst_audio_wsincband_set_property (GObject * object, guint prop_id,
gst_audio_fx_base_fir_filter_push_residue (GST_AUDIO_FX_BASE_FIR_FILTER gst_audio_fx_base_fir_filter_push_residue (GST_AUDIO_FX_BASE_FIR_FILTER
(self)); (self));
self->kernel_length = val; self->kernel_length = val;
gst_audio_wsincband_build_kernel (self); gst_audio_wsincband_build_kernel (self, NULL);
} }
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
@ -420,25 +426,25 @@ gst_audio_wsincband_set_property (GObject * object, guint prop_id,
case PROP_LOWER_FREQUENCY: case PROP_LOWER_FREQUENCY:
g_mutex_lock (&self->lock); g_mutex_lock (&self->lock);
self->lower_frequency = g_value_get_float (value); self->lower_frequency = g_value_get_float (value);
gst_audio_wsincband_build_kernel (self); gst_audio_wsincband_build_kernel (self, NULL);
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
case PROP_UPPER_FREQUENCY: case PROP_UPPER_FREQUENCY:
g_mutex_lock (&self->lock); g_mutex_lock (&self->lock);
self->upper_frequency = g_value_get_float (value); self->upper_frequency = g_value_get_float (value);
gst_audio_wsincband_build_kernel (self); gst_audio_wsincband_build_kernel (self, NULL);
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
case PROP_MODE: case PROP_MODE:
g_mutex_lock (&self->lock); g_mutex_lock (&self->lock);
self->mode = g_value_get_enum (value); self->mode = g_value_get_enum (value);
gst_audio_wsincband_build_kernel (self); gst_audio_wsincband_build_kernel (self, NULL);
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
case PROP_WINDOW: case PROP_WINDOW:
g_mutex_lock (&self->lock); g_mutex_lock (&self->lock);
self->window = g_value_get_enum (value); self->window = g_value_get_enum (value);
gst_audio_wsincband_build_kernel (self); gst_audio_wsincband_build_kernel (self, NULL);
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
default: default:

View file

@ -215,7 +215,8 @@ gst_audio_wsinclimit_init (GstAudioWSincLimit * self)
} }
static void static void
gst_audio_wsinclimit_build_kernel (GstAudioWSincLimit * self) gst_audio_wsinclimit_build_kernel (GstAudioWSincLimit * self,
const GstAudioInfo * info)
{ {
gint i = 0; gint i = 0;
gdouble sum = 0.0; gdouble sum = 0.0;
@ -226,8 +227,13 @@ gst_audio_wsinclimit_build_kernel (GstAudioWSincLimit * self)
len = self->kernel_length; len = self->kernel_length;
rate = GST_AUDIO_FILTER_RATE (self); if (info) {
channels = GST_AUDIO_FILTER_CHANNELS (self); rate = GST_AUDIO_INFO_RATE (info);
channels = GST_AUDIO_INFO_CHANNELS (info);
} else {
rate = GST_AUDIO_FILTER_RATE (self);
channels = GST_AUDIO_FILTER_CHANNELS (self);
}
if (rate == 0) { if (rate == 0) {
GST_DEBUG ("rate not set yet"); GST_DEBUG ("rate not set yet");
@ -300,7 +306,7 @@ gst_audio_wsinclimit_build_kernel (GstAudioWSincLimit * self)
} }
gst_audio_fx_base_fir_filter_set_kernel (GST_AUDIO_FX_BASE_FIR_FILTER (self), gst_audio_fx_base_fir_filter_set_kernel (GST_AUDIO_FX_BASE_FIR_FILTER (self),
kernel, self->kernel_length, (len - 1) / 2); kernel, self->kernel_length, (len - 1) / 2, info);
} }
/* GstAudioFilter vmethod implementations */ /* GstAudioFilter vmethod implementations */
@ -311,7 +317,7 @@ gst_audio_wsinclimit_setup (GstAudioFilter * base, const GstAudioInfo * info)
{ {
GstAudioWSincLimit *self = GST_AUDIO_WSINC_LIMIT (base); GstAudioWSincLimit *self = GST_AUDIO_WSINC_LIMIT (base);
gst_audio_wsinclimit_build_kernel (self); gst_audio_wsinclimit_build_kernel (self, info);
return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info); return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info);
} }
@ -347,7 +353,7 @@ gst_audio_wsinclimit_set_property (GObject * object, guint prop_id,
gst_audio_fx_base_fir_filter_push_residue (GST_AUDIO_FX_BASE_FIR_FILTER gst_audio_fx_base_fir_filter_push_residue (GST_AUDIO_FX_BASE_FIR_FILTER
(self)); (self));
self->kernel_length = val; self->kernel_length = val;
gst_audio_wsinclimit_build_kernel (self); gst_audio_wsinclimit_build_kernel (self, NULL);
} }
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
@ -355,19 +361,19 @@ gst_audio_wsinclimit_set_property (GObject * object, guint prop_id,
case PROP_FREQUENCY: case PROP_FREQUENCY:
g_mutex_lock (&self->lock); g_mutex_lock (&self->lock);
self->cutoff = g_value_get_float (value); self->cutoff = g_value_get_float (value);
gst_audio_wsinclimit_build_kernel (self); gst_audio_wsinclimit_build_kernel (self, NULL);
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
case PROP_MODE: case PROP_MODE:
g_mutex_lock (&self->lock); g_mutex_lock (&self->lock);
self->mode = g_value_get_enum (value); self->mode = g_value_get_enum (value);
gst_audio_wsinclimit_build_kernel (self); gst_audio_wsinclimit_build_kernel (self, NULL);
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
case PROP_WINDOW: case PROP_WINDOW:
g_mutex_lock (&self->lock); g_mutex_lock (&self->lock);
self->window = g_value_get_enum (value); self->window = g_value_get_enum (value);
gst_audio_wsinclimit_build_kernel (self); gst_audio_wsinclimit_build_kernel (self, NULL);
g_mutex_unlock (&self->lock); g_mutex_unlock (&self->lock);
break; break;
default: default: