summaryrefslogtreecommitdiff
path: root/ext/soundtouch/gstbpmdetect.cc
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2012-07-10 17:47:20 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2012-07-10 17:47:20 +0200
commit2eefdda3e4334fc413a864b095484cd8ff7a62f8 (patch)
tree263352c07ca6f034c3939f969095b1e0f33b109e /ext/soundtouch/gstbpmdetect.cc
parent29092cc3b8d339c1f38c4fda95cca23c60bf1586 (diff)
downloadgstreamer-plugins-bad-2eefdda3e4334fc413a864b095484cd8ff7a62f8.tar.gz
soundtouch: port to 0.11
Diffstat (limited to 'ext/soundtouch/gstbpmdetect.cc')
-rw-r--r--ext/soundtouch/gstbpmdetect.cc71
1 files changed, 35 insertions, 36 deletions
diff --git a/ext/soundtouch/gstbpmdetect.cc b/ext/soundtouch/gstbpmdetect.cc
index 9908dcad5..edb2db08f 100644
--- a/ext/soundtouch/gstbpmdetect.cc
+++ b/ext/soundtouch/gstbpmdetect.cc
@@ -56,14 +56,13 @@ struct _GstBPMDetectPrivate
};
#define ALLOWED_CAPS \
- "audio/x-raw-float, " \
- " width = (int) 32, " \
- " endianness = (int) BYTE_ORDER, " \
+ "audio/x-raw, " \
+ " format = (string) " GST_AUDIO_NE (F32) ", " \
" rate = (int) [ 8000, MAX ], " \
" channels = (int) [ 1, 2 ]"
-GST_BOILERPLATE (GstBPMDetect, gst_bpm_detect, GstAudioFilter,
- GST_TYPE_AUDIO_FILTER);
+#define gst_bpm_detect_parent_class parent_class
+G_DEFINE_TYPE (GstBPMDetect, gst_bpm_detect, GST_TYPE_AUDIO_FILTER);
static void gst_bpm_detect_finalize (GObject * object);
static gboolean gst_bpm_detect_stop (GstBaseTransform * trans);
@@ -72,28 +71,14 @@ static gboolean gst_bpm_detect_event (GstBaseTransform * trans,
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 <slomo@circular-chaos.org>");
-
- 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);
-}
+ const GstAudioInfo * info);
static void
gst_bpm_detect_class_init (GstBPMDetectClass * klass)
{
+ GstCaps *caps;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass);
GstAudioFilterClass *filter_class = GST_AUDIO_FILTER_CLASS (klass);
@@ -102,8 +87,17 @@ gst_bpm_detect_class_init (GstBPMDetectClass * klass)
gobject_class->finalize = gst_bpm_detect_finalize;
+ gst_element_class_set_details_simple (element_class, "BPM Detector",
+ "Filter/Analyzer/Audio", "Detect the BPM of an audio stream",
+ "Sebastian Dröge <slomo@circular-chaos.org>");
+
+ caps = gst_caps_from_string (ALLOWED_CAPS);
+ gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (klass),
+ caps);
+ gst_caps_unref (caps);
+
trans_class->stop = GST_DEBUG_FUNCPTR (gst_bpm_detect_stop);
- trans_class->event = GST_DEBUG_FUNCPTR (gst_bpm_detect_event);
+ trans_class->sink_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;
@@ -113,7 +107,7 @@ gst_bpm_detect_class_init (GstBPMDetectClass * klass)
}
static void
-gst_bpm_detect_init (GstBPMDetect * bpm_detect, GstBPMDetectClass * g_class)
+gst_bpm_detect_init (GstBPMDetect * bpm_detect)
{
bpm_detect->priv = G_TYPE_INSTANCE_GET_PRIVATE ((bpm_detect),
GST_TYPE_BPM_DETECT, GstBPMDetectPrivate);
@@ -159,7 +153,7 @@ 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:
+ case GST_EVENT_SEGMENT:
if (bpm_detect->priv->detect) {
delete bpm_detect->priv->detect;
@@ -175,7 +169,7 @@ gst_bpm_detect_event (GstBaseTransform * trans, GstEvent * event)
}
static gboolean
-gst_bpm_detect_setup (GstAudioFilter * filter, GstRingBufferSpec * format)
+gst_bpm_detect_setup (GstAudioFilter * filter, const GstAudioInfo * info)
{
GstBPMDetect *bpm_detect = GST_BPM_DETECT (filter);
@@ -195,29 +189,33 @@ gst_bpm_detect_transform_ip (GstBaseTransform * trans, GstBuffer * in)
GstAudioFilter *filter = GST_AUDIO_FILTER (trans);
gint nsamples;
gfloat bpm;
+ GstMapInfo info;
if (G_UNLIKELY (!bpm_detect->priv->detect)) {
- if (filter->format.channels == 0 || filter->format.rate == 0) {
+ if (GST_AUDIO_INFO_FORMAT (&filter->info) == GST_AUDIO_FORMAT_UNKNOWN) {
GST_ERROR_OBJECT (bpm_detect, "No channels or rate set yet");
return GST_FLOW_ERROR;
}
#ifdef HAVE_SOUNDTOUCH_1_4
bpm_detect->priv->detect =
- new soundtouch::BPMDetect (filter->format.channels,
- filter->format.rate);
+ new soundtouch::BPMDetect (GST_AUDIO_INFO_CHANNELS (&filter->info),
+ GST_AUDIO_INFO_RATE (&filter->info));
#else
bpm_detect->priv->detect =
- new BPMDetect (filter->format.channels, filter->format.rate);
+ new BPMDetect (GST_AUDIO_INFO_CHANNELS (&filter->info),
+ GST_AUDIO_INFO_RATE (&filter->info));
#endif
}
- nsamples = GST_BUFFER_SIZE (in) / (4 * filter->format.channels);
+ gst_buffer_map (in, &info, GST_MAP_READ);
+
+ nsamples = info.size / (4 * GST_AUDIO_INFO_CHANNELS (&filter->info));
/* For stereo BPMDetect->inputSamples() does downmixing into the input
* data but our buffer data shouldn't be modified.
*/
- if (filter->format.channels == 1) {
- gfloat *inbuf = (gfloat *) GST_BUFFER_DATA (in);
+ if (GST_AUDIO_INFO_CHANNELS (&filter->info) == 1) {
+ gfloat *inbuf = (gfloat *) info.data;
while (nsamples > 0) {
bpm_detect->priv->detect->inputSamples (inbuf, MIN (nsamples, 2048));
@@ -227,7 +225,7 @@ gst_bpm_detect_transform_ip (GstBaseTransform * trans, GstBuffer * in)
} else {
gfloat *inbuf, *intmp, data[2 * 2048];
- inbuf = (gfloat *) GST_BUFFER_DATA (in);
+ inbuf = (gfloat *) info.data;
intmp = data;
while (nsamples > 0) {
@@ -237,14 +235,15 @@ gst_bpm_detect_transform_ip (GstBaseTransform * trans, GstBuffer * in)
inbuf += 2048 * 2;
}
}
+ gst_buffer_unmap (in, &info);
bpm = bpm_detect->priv->detect->getBpm ();
if (bpm >= 1.0 && fabs (bpm_detect->bpm - bpm) >= 1.0) {
- GstTagList *tags = gst_tag_list_new ();
+ GstTagList *tags = gst_tag_list_new_empty ();
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE_ALL, GST_TAG_BEATS_PER_MINUTE,
bpm, (void *) NULL);
- gst_element_found_tags (GST_ELEMENT (bpm_detect), tags);
+ gst_pad_push_event (trans->srcpad, gst_event_new_tag ("bpmdetect", tags));
GST_INFO_OBJECT (bpm_detect, "Detected BPM: %lf\n", bpm);
bpm_detect->bpm = bpm;