summaryrefslogtreecommitdiffstats
path: root/ext/soundtouch
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2008-01-28 11:47:18 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2008-01-28 11:47:18 +0000
commite6e86c4f2d5cd9213cb71a30dfdd9d9441e40ac9 (patch)
treec6b1f247523861af702778e9c904e17e25a1c6c5 /ext/soundtouch
parentb0c8b0f3227ebe75e18064821ed981bbd5d935a4 (diff)
downloadgst-plugins-bad-e6e86c4f2d5cd9213cb71a30dfdd9d9441e40ac9.tar.gz
gst-plugins-bad-e6e86c4f2d5cd9213cb71a30dfdd9d9441e40ac9.tar.bz2
gst-plugins-bad-e6e86c4f2d5cd9213cb71a30dfdd9d9441e40ac9.zip
ext/soundtouch/gstbpmdetect.cc: Clean up a bit and only allocate a temporary buffer for the data if processing stereo...
Original commit message from CVS: * ext/soundtouch/gstbpmdetect.cc: Clean up a bit and only allocate a temporary buffer for the data if processing stereo data as BPMDetect downmixes from stereo to mono and stores the result in the input data. Thanks to Stefan Kost for the suggestions.
Diffstat (limited to 'ext/soundtouch')
-rw-r--r--ext/soundtouch/gstbpmdetect.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/ext/soundtouch/gstbpmdetect.cc b/ext/soundtouch/gstbpmdetect.cc
index d9949182..1ec5452a 100644
--- a/ext/soundtouch/gstbpmdetect.cc
+++ b/ext/soundtouch/gstbpmdetect.cc
@@ -189,23 +189,32 @@ gst_bpm_detect_transform_ip (GstBaseTransform * trans, GstBuffer * in)
GstBPMDetect *bpm_detect = GST_BPM_DETECT (trans);
GstAudioFilter *filter = GST_AUDIO_FILTER (trans);
gint nsamples;
- gfloat *data;
gfloat bpm;
- 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 (G_UNLIKELY (!bpm_detect->priv->detect)) {
+ if (filter->format.channels == 0 || filter->format.rate == 0) {
+ GST_ERROR_OBJECT (bpm_detect, "No channels or rate set yet");
+ return GST_FLOW_ERROR;
+ }
- 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);
+ nsamples = GST_BUFFER_SIZE (in) / (4 * filter->format.channels);
+
+ /* For stereo BPMDetect->inputSamples() does downmixing into the input
+ * data but our buffer data shouldn't be modified.
+ */
+ if (filter->format.channels == 1) {
+ bpm_detect->priv->detect->inputSamples ((gfloat *) GST_BUFFER_DATA (in),
+ nsamples);
+ } else {
+ gfloat *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 >= 1.0 && fabs (bpm_detect->bpm - bpm) >= 1.0) {