From: <sl...@ke...> - 2008-01-27 05:56:12
|
CVS Root: /cvs/gstreamer Module: gst-plugins-bad Changes by: slomo Date: Sun Jan 27 2008 05:56:18 UTC Log message: * ext/soundtouch/Makefile.am: * ext/soundtouch/gstbpmdetect.cc: * ext/soundtouch/gstbpmdetect.hh: * ext/soundtouch/plugin.c: (plugin_init): Add BPM detection plugin based on SoundTouch's libBPM. * ext/soundtouch/gstpitch.cc: Allow sample rates until MAX instead of only 48kHz and remove the buffer-frames field from that caps. Clear the remaining samples completely when necessary to get into a clean state again. Modified files: . : ChangeLog ext/soundtouch : Makefile.am gstpitch.cc Added files: ext/soundtouch : gstbpmdetect.cc gstbpmdetect.hh plugin.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ChangeLog.diff?r1=1.3063&r2=1.3064 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/soundtouch/Makefile.am.diff?r1=1.3&r2=1.4 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/soundtouch/gstbpmdetect.cc?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/soundtouch/gstbpmdetect.hh?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/soundtouch/gstpitch.cc.diff?r1=1.8&r2=1.9 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-bad/ext/soundtouch/plugin.c?rev=1.1&content-type=text/vnd.viewcvs-markup ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gst-plugins-bad/ChangeLog,v retrieving revision 1.3063 retrieving revision 1.3064 diff -u -d -r1.3063 -r1.3064 --- ChangeLog 26 Jan 2008 16:19:25 -0000 1.3063 +++ ChangeLog 27 Jan 2008 05:56:02 -0000 1.3064 @@ -1,3 +1,17 @@ +2008-01-27 Sebastian Dröge <sl...@ci...> + + * ext/soundtouch/Makefile.am: + * ext/soundtouch/gstbpmdetect.cc: + * ext/soundtouch/gstbpmdetect.hh: + * ext/soundtouch/plugin.c: (plugin_init): + Add BPM detection plugin based on SoundTouch's libBPM. + * ext/soundtouch/gstpitch.cc: + Allow sample rates until MAX instead of only 48kHz and remove the + buffer-frames field from that caps. + Clear the remaining samples completely when necessary to get into + a clean state again. 2008-01-26 Sebastian Dröge <sl...@ci...> * gst/filter/gstbpwsinc.c: (gst_bpwsinc_class_init): Index: Makefile.am RCS file: /cvs/gstreamer/gst-plugins-bad/ext/soundtouch/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 3 Sep 2006 21:12:36 -0000 1.3 +++ Makefile.am 27 Jan 2008 05:56:03 -0000 1.4 @@ -1,9 +1,13 @@ -plugin_LTLIBRARIES = libgstpitch.la +plugin_LTLIBRARIES = libgstsoundtouch.la -libgstpitch_la_SOURCES = gstpitch.cc +libgstsoundtouch_la_SOURCES = \ + plugin.c \ + gstpitch.cc \ + gstbpmdetect.cc -libgstpitch_la_CXXFLAGS = $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(SOUNDTOUCH_CFLAGS) -libgstpitch_la_LIBADD = $(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS) $(GST_LIBS) $(SOUNDTOUCH_LIBS) -libgstpitch_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) +libgstsoundtouch_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(SOUNDTOUCH_CFLAGS) +libgstsoundtouch_la_CXXFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(SOUNDTOUCH_CFLAGS) +libgstsoundtouch_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS) $(GST_LIBS) $(SOUNDTOUCH_LIBS) -lgstaudio-$(GST_MAJORMINOR) -lBPM $(LIBM) +libgstsoundtouch_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -noinst_HEADERS = gstpitch.hh +noinst_HEADERS = gstpitch.hh gstbpmdetect.hh --- NEW FILE: gstbpmdetect.cc --- /* GStreamer * Copyright (C) 2008 Sebastian Dröge <sl...@ci...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * 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. */ #define FLOAT_SAMPLES 1 #include <soundtouch/BPMDetect.h> /* FIXME: workaround for SoundTouch.h of version 1.3.1 defining those * variables while it shouldn't. */ #undef VERSION #undef PACKAGE_VERSION #undef PACKAGE_TARNAME #undef PACKAGE_STRING #undef PACKAGE_NAME #undef PACKAGE_BUGREPORT #undef PACKAGE #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <gst/audio/audio.h> #include <gst/audio/gstaudiofilter.h> #include <math.h> #include <string.h> #include "gstbpmdetect.hh" GST_DEBUG_CATEGORY_STATIC (gst_bpm_detect_debug); #define GST_CAT_DEFAULT gst_bpm_detect_debug #define GST_BPM_DETECT_GET_PRIVATE(o) (o->priv) struct _GstBPMDetectPrivate { gfloat bpm; BPMDetect *detect; }; #define ALLOWED_CAPS \ "audio/x-raw-float, " \ " width = (int) 32, " \ " endianness = (int) BYTE_ORDER, " \ " rate = (int) [ 8000, MAX ], " \ " channels = (int) [ 1, 2 ]" GST_BOILERPLATE (GstBPMDetect, gst_bpm_detect, GstAudioFilter, GST_TYPE_AUDIO_FILTER); static void gst_bpm_detect_finalize (GObject * object); static gboolean gst_bpm_detect_stop (GstBaseTransform * trans); static gboolean gst_bpm_detect_event (GstBaseTransform * trans, GstEvent * event); static GstFlowReturn gst_bpm_detect_transform_ip (GstBaseTransform * trans, GstBuffer * in); static gboolean gst_bpm_detect_setup (GstAudioFilter * filter, GstRingBufferSpec * format); static void gst_bpm_detect_base_init (gpointer g_class) GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GstCaps *caps; gst_element_class_set_details_simple (element_class, "BPM Detector", "Filter/Analyzer/Audio", "Detect the BPM of an audio stream", "Sebastian Dröge <sl...@ci...>"); caps = gst_caps_from_string (ALLOWED_CAPS); gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (g_class), caps); gst_caps_unref (caps); } gst_bpm_detect_class_init (GstBPMDetectClass * klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass); GstAudioFilterClass *filter_class = GST_AUDIO_FILTER_CLASS (klass); GST_DEBUG_CATEGORY_INIT (gst_bpm_detect_debug, "bpm_detect", 0, "audio bpm detection element"); gobject_class->finalize = gst_bpm_detect_finalize; trans_class->stop = GST_DEBUG_FUNCPTR (gst_bpm_detect_stop); trans_class->event = GST_DEBUG_FUNCPTR (gst_bpm_detect_event); trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_bpm_detect_transform_ip); trans_class->passthrough_on_same_caps = TRUE; filter_class->setup = GST_DEBUG_FUNCPTR (gst_bpm_detect_setup); g_type_class_add_private (gobject_class, sizeof (GstBPMDetectPrivate)); gst_bpm_detect_init (GstBPMDetect * bpm_detect, GstBPMDetectClass * g_class) bpm_detect->priv = G_TYPE_INSTANCE_GET_PRIVATE ((bpm_detect), GST_TYPE_BPM_DETECT, GstBPMDetectPrivate); bpm_detect->priv->detect = NULL; bpm_detect->bpm = 0.0; gst_bpm_detect_finalize (GObject * object) GstBPMDetect *bpm_detect = GST_BPM_DETECT (object); if (bpm_detect->priv->detect) { delete bpm_detect->priv->detect; bpm_detect->priv->detect = NULL; } G_OBJECT_CLASS (parent_class)->finalize (object); static gboolean gst_bpm_detect_stop (GstBaseTransform * trans) GstBPMDetect *bpm_detect = GST_BPM_DETECT (trans); return TRUE; gst_bpm_detect_event (GstBaseTransform * trans, GstEvent * event) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_FLUSH_STOP: case GST_EVENT_EOS: case GST_EVENT_NEWSEGMENT: if (bpm_detect->priv->detect) { delete bpm_detect->priv->detect; bpm_detect->priv->detect = NULL; } bpm_detect->bpm = 0.0; break; default: gst_bpm_detect_setup (GstAudioFilter * filter, GstRingBufferSpec * format) GstBPMDetect *bpm_detect = GST_BPM_DETECT (filter); static GstFlowReturn gst_bpm_detect_transform_ip (GstBaseTransform * trans, GstBuffer * in) GstAudioFilter *filter = GST_AUDIO_FILTER (trans); gint nsamples; gfloat *data; if (filter->format.channels == 0 || filter->format.rate == 0) { GST_ERROR_OBJECT (bpm_detect, "No channels or rate set yet"); return GST_FLOW_ERROR; nsamples = GST_BUFFER_SIZE (in) / (4 * filter->format.channels); if (!bpm_detect->priv->detect) bpm_detect->priv->detect = new BPMDetect (filter->format.channels, filter->format.rate); data = (gfloat *) g_memdup (GST_BUFFER_DATA (in), GST_BUFFER_SIZE (in)); bpm_detect->priv->detect->inputSamples (data, nsamples); g_free (data); bpm = bpm_detect->priv->detect->getBpm (); if (bpm != 0.0 && fabs (bpm_detect->bpm - bpm) >= 1.0) { GstTagList *tags = gst_tag_list_new (); gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE_ALL, GST_TAG_BEATS_PER_MINUTE, bpm, NULL); gst_element_found_tags (GST_ELEMENT (bpm_detect), tags); GST_INFO_OBJECT (bpm_detect, "Detected BPM: %lf\n", bpm); bpm_detect->bpm = bpm; return GST_FLOW_OK; --- NEW FILE: gstbpmdetect.hh --- * Copyright (C) 2008 Sebastian Dröge <sl...@ci...> #ifndef __GST_BPM_DETECT_H__ #define __GST_BPM_DETECT_H__ #include <gst/gst.h> #include <gst/base/gstbasetransform.h> G_BEGIN_DECLS #define GST_TYPE_BPM_DETECT (gst_bpm_detect_get_type()) #define GST_BPM_DETECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BPM_DETECT,GstBPMDetect)) #define GST_IS_BPM_DETECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BPM_DETECT)) #define GST_BPM_DETECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_BPM_DETECT,GstBPMDetectClass)) #define GST_IS_BPM_DETECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_BPM_DETECT)) typedef struct _GstBPMDetect GstBPMDetect; typedef struct _GstBPMDetectClass GstBPMDetectClass; typedef struct _GstBPMDetectPrivate GstBPMDetectPrivate; struct _GstBPMDetect { GstAudioFilter element; GstBPMDetectPrivate *priv; struct _GstBPMDetectClass { GstAudioFilterClass parent_class; GType gst_bpm_detect_get_type (void); G_END_DECLS #endif /* __GST_BPM_DETECT_H__ */ Index: gstpitch.cc RCS file: /cvs/gstreamer/gst-plugins-bad/ext/soundtouch/gstpitch.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- gstpitch.cc 26 Jan 2008 15:12:50 -0000 1.8 +++ gstpitch.cc 27 Jan 2008 05:56:04 -0000 1.9 @@ -62,11 +62,10 @@ #define SUPPORTED_CAPS \ GST_STATIC_CAPS( \ "audio/x-raw-float, " \ - "rate = (int) [ 8000, 48000 ], " \ + "rate = (int) [ 8000, MAX ], " \ "channels = (int) [ 1, 2 ], " \ "endianness = (int) BYTE_ORDER, " \ - "width = (int) 32, " \ - "buffer-frames = (int) [ 0, MAX ]" \ + "width = (int) 32" \ ) static GstStaticPadTemplate gst_pitch_sink_template = @@ -124,6 +123,9 @@ gobject_class = G_OBJECT_CLASS (klass); element_class = GST_ELEMENT_CLASS (klass); + GST_DEBUG_CATEGORY_INIT (pitch_debug, "pitch", 0, + "audio pitch control element"); gobject_class->set_property = gst_pitch_set_property; gobject_class->get_property = gst_pitch_get_property; gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pitch_dispose); @@ -725,9 +727,11 @@ switch (GST_EVENT_TYPE (event)) { case GST_EVENT_FLUSH_STOP: gst_pitch_flush_buffer (pitch, FALSE); + pitch->priv->st->clear (); break; case GST_EVENT_EOS: gst_pitch_flush_buffer (pitch, TRUE); case GST_EVENT_NEWSEGMENT: if (!gst_pitch_process_segment (pitch, &event)) { @@ -737,6 +741,7 @@ GST_PITCH_GET_PRIVATE (pitch)->pending_segment = event; event = NULL; } default: @@ -812,6 +817,7 @@ case GST_STATE_CHANGE_READY_TO_PAUSED: pitch->next_buffer_time = 0; pitch->next_buffer_offset = 0; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: @@ -839,20 +845,3 @@ return ret; } - -static gboolean -plugin_init (GstPlugin * plugin) -{ - gst_controller_init (NULL, NULL); - GST_DEBUG_CATEGORY_INIT (pitch_debug, "pitch", 0, - "audio pitch control element"); - return gst_element_register (plugin, "pitch", GST_RANK_NONE, GST_TYPE_PITCH); -} -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "soundtouch", - "Audio Pitch Controller", - plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) --- NEW FILE: plugin.c --- /* GStreamer soundtouch plugin * modify it under the terms of the GNU Lesser General Public * version 2.1 of the License, or (at your option) any later version. * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # include <config.h> #include <gst/controller/gstcontroller.h> #include "gstpitch.hh" plugin_init (GstPlugin * plugin) gst_controller_init (NULL, NULL); return gst_element_register (plugin, "pitch", GST_RANK_NONE, GST_TYPE_PITCH) && gst_element_register (plugin, "bpmdetect", GST_RANK_NONE, GST_TYPE_BPM_DETECT); GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "soundtouch", "Audio Pitch Controller & BPM Detection", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) |