aacparse: fix wrong offset of adts channel
[platform/upstream/gst-plugins-good.git] / gst / audiofx / audiocheblimit.c
index e1fcdfa..e278886 100644 (file)
@@ -14,8 +14,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /* 
  * be at most this value. A lower ripple value will allow a faster rolloff.
  *
  * As a special case, a Chebyshev type 1 filter with no ripple is a Butterworth filter.
- * </para>
+ *
  * <note><para>
  * Be warned that a too large number of poles can produce noise. The most poles are possible with
  * a cutoff frequency at a quarter of the sampling rate.
  * </para></note>
- * <para>
+ *
  * <refsect2>
  * <title>Example launch line</title>
  * |[
- * gst-launch audiotestsrc freq=1500 ! audioconvert ! audiocheblimit mode=low-pass cutoff=1000 poles=4 ! audioconvert ! alsasink
- * gst-launch filesrc location="melo1.ogg" ! oggdemux ! vorbisdec ! audioconvert ! audiocheblimit mode=high-pass cutoff=400 ripple=0.2 ! audioconvert ! alsasink
- * gst-launch audiotestsrc wave=white-noise ! audioconvert ! audiocheblimit mode=low-pass cutoff=800 type=2 ! audioconvert ! alsasink
+ * gst-launch-1.0 audiotestsrc freq=1500 ! audioconvert ! audiocheblimit mode=low-pass cutoff=1000 poles=4 ! audioconvert ! alsasink
+ * gst-launch-1.0 filesrc location="melo1.ogg" ! oggdemux ! vorbisdec ! audioconvert ! audiocheblimit mode=high-pass cutoff=400 ripple=0.2 ! audioconvert ! alsasink
+ * gst-launch-1.0 audiotestsrc wave=white-noise ! audioconvert ! audiocheblimit mode=low-pass cutoff=800 type=2 ! audioconvert ! alsasink
  * ]|
  * </refsect2>
  */
@@ -178,7 +178,7 @@ gst_audio_cheb_limit_class_init (GstAudioChebLimitClass * klass)
           2, 32, 4,
           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
 
-  gst_element_class_set_details_simple (gstelement_class,
+  gst_element_class_set_static_metadata (gstelement_class,
       "Low pass & high pass filter",
       "Filter/Effect/Audio",
       "Chebyshev low pass and high pass filter",
@@ -201,7 +201,7 @@ gst_audio_cheb_limit_init (GstAudioChebLimit * filter)
 
 static void
 generate_biquad_coefficients (GstAudioChebLimit * filter,
-    gint p, gdouble * b0, gdouble * b1, gdouble * b2,
+    gint p, gint rate, gdouble * b0, gdouble * b1, gdouble * b2,
     gdouble * a1, gdouble * a2)
 {
   gint np = filter->poles;
@@ -320,8 +320,7 @@ generate_biquad_coefficients (GstAudioChebLimit * filter,
    */
   {
     gdouble k, d;
-    gdouble omega =
-        2.0 * G_PI * (filter->cutoff / GST_AUDIO_FILTER_RATE (filter));
+    gdouble omega = 2.0 * G_PI * (filter->cutoff / rate);
 
     if (filter->mode == MODE_LOW_PASS)
       k = sin ((1.0 - omega) / 2.0) / sin ((1.0 + omega) / 2.0);
@@ -343,9 +342,19 @@ generate_biquad_coefficients (GstAudioChebLimit * filter,
 }
 
 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 *b = g_new0 (gdouble, 1);
 
@@ -358,7 +367,7 @@ generate_coefficients (GstAudioChebLimit * filter)
     return;
   }
 
-  if (filter->cutoff >= GST_AUDIO_FILTER_RATE (filter) / 2.0) {
+  if (filter->cutoff >= rate / 2.0) {
     gdouble *a = g_new0 (gdouble, 1);
     gdouble *b = g_new0 (gdouble, 1);
 
@@ -398,7 +407,7 @@ generate_coefficients (GstAudioChebLimit * filter)
       gdouble *ta = g_new0 (gdouble, np + 3);
       gdouble *tb = g_new0 (gdouble, np + 3);
 
-      generate_biquad_coefficients (filter, p, &b0, &b1, &b2, &a1, &a2);
+      generate_biquad_coefficients (filter, p, rate, &b0, &b1, &b2, &a1, &a2);
 
       memcpy (ta, a, sizeof (gdouble) * (np + 3));
       memcpy (tb, b, sizeof (gdouble) * (np + 3));
@@ -456,8 +465,7 @@ generate_coefficients (GstAudioChebLimit * filter)
 
 #ifndef GST_DISABLE_GST_DEBUG
     {
-      gdouble wc =
-          2.0 * G_PI * (filter->cutoff / GST_AUDIO_FILTER_RATE (filter));
+      gdouble wc = 2.0 * G_PI * (filter->cutoff / rate);
       gdouble zr = cos (wc), zi = sin (wc);
 
       GST_LOG_OBJECT (filter, "%.2f dB gain @ %d Hz",
@@ -468,7 +476,7 @@ generate_coefficients (GstAudioChebLimit * filter)
 
     GST_LOG_OBJECT (filter, "%.2f dB gain @ %d Hz",
         20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b,
-                np + 1, -1.0, 0.0)), GST_AUDIO_FILTER_RATE (filter) / 2);
+                np + 1, -1.0, 0.0)), rate);
   }
 }
 
@@ -492,31 +500,31 @@ gst_audio_cheb_limit_set_property (GObject * object, guint prop_id,
     case PROP_MODE:
       g_mutex_lock (&filter->lock);
       filter->mode = g_value_get_enum (value);
-      generate_coefficients (filter);
+      generate_coefficients (filter, NULL);
       g_mutex_unlock (&filter->lock);
       break;
     case PROP_TYPE:
       g_mutex_lock (&filter->lock);
       filter->type = g_value_get_int (value);
-      generate_coefficients (filter);
+      generate_coefficients (filter, NULL);
       g_mutex_unlock (&filter->lock);
       break;
     case PROP_CUTOFF:
       g_mutex_lock (&filter->lock);
       filter->cutoff = g_value_get_float (value);
-      generate_coefficients (filter);
+      generate_coefficients (filter, NULL);
       g_mutex_unlock (&filter->lock);
       break;
     case PROP_RIPPLE:
       g_mutex_lock (&filter->lock);
       filter->ripple = g_value_get_float (value);
-      generate_coefficients (filter);
+      generate_coefficients (filter, NULL);
       g_mutex_unlock (&filter->lock);
       break;
     case PROP_POLES:
       g_mutex_lock (&filter->lock);
       filter->poles = GST_ROUND_UP_2 (g_value_get_int (value));
-      generate_coefficients (filter);
+      generate_coefficients (filter, NULL);
       g_mutex_unlock (&filter->lock);
       break;
     default:
@@ -560,7 +568,7 @@ gst_audio_cheb_limit_setup (GstAudioFilter * base, const GstAudioInfo * info)
 {
   GstAudioChebLimit *filter = GST_AUDIO_CHEB_LIMIT (base);
 
-  generate_coefficients (filter);
+  generate_coefficients (filter, info);
 
   return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info);
 }