wscript: first waf draft
[vamp-aubio-plugins.git] / plugins / Silence.cpp
index cf3dda4..c1d7f99 100644 (file)
@@ -6,11 +6,21 @@
     Centre for Digital Music, Queen Mary, University of London.
     This file copyright 2006-2008 Chris Cannam and QMUL.
     
     Centre for Digital Music, Queen Mary, University of London.
     This file copyright 2006-2008 Chris Cannam and QMUL.
     
-    This program is free software; you can redistribute it and/or
-    modify it under the terms of the GNU General Public License as
-    published by the Free Software Foundation; either version 2 of the
-    License, or (at your option) any later version.  See the file
-    COPYING included with this distribution for more information.
+    This file is part of vamp-aubio-plugins.
+
+    vamp-aubio is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    vamp-aubio 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
 */
 
 #include <math.h>
 */
 
 #include <math.h>
@@ -25,7 +35,6 @@ Silence::Silence(float inputSampleRate) :
     Plugin(inputSampleRate),
     m_ibuf(0),
     m_pbuf(0),
     Plugin(inputSampleRate),
     m_ibuf(0),
     m_pbuf(0),
-    m_tmpptrs(0),
     m_threshold(-80),
     m_prevSilent(false),
     m_first(true)
     m_threshold(-80),
     m_prevSilent(false),
     m_first(true)
@@ -36,7 +45,6 @@ Silence::~Silence()
 {
     if (m_ibuf) del_fvec(m_ibuf);
     if (m_pbuf) del_fvec(m_pbuf);
 {
     if (m_ibuf) del_fvec(m_ibuf);
     if (m_pbuf) del_fvec(m_pbuf);
-    if (m_tmpptrs) delete[] m_tmpptrs;
 }
 
 string
 }
 
 string
@@ -88,7 +96,6 @@ Silence::initialise(size_t channels, size_t stepSize, size_t blockSize)
 
     m_ibuf = new_fvec(stepSize);
     m_pbuf = new_fvec(stepSize);
 
     m_ibuf = new_fvec(stepSize);
     m_pbuf = new_fvec(stepSize);
-    m_tmpptrs = new smpl_t *[channels];
 
     return true;
 }
 
     return true;
 }
@@ -120,6 +127,7 @@ Silence::getParameterDescriptors() const
     desc = ParameterDescriptor();
     desc.identifier = "silencethreshold";
     desc.name = "Silence Threshold";
     desc = ParameterDescriptor();
     desc.identifier = "silencethreshold";
     desc.name = "Silence Threshold";
+    desc.description = "Threshold for silence detection";
     desc.minValue = -120;
     desc.maxValue = 0;
     desc.defaultValue = -80;
     desc.minValue = -120;
     desc.maxValue = 0;
     desc.defaultValue = -80;
@@ -199,9 +207,7 @@ Silence::process(const float *const *inputBuffers,
                  Vamp::RealTime timestamp)
 {
     for (size_t i = 0; i < m_stepSize; ++i) {
                  Vamp::RealTime timestamp)
 {
     for (size_t i = 0; i < m_stepSize; ++i) {
-        for (size_t j = 0; j < m_channelCount; ++j) {
-            fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
-        }
+        fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
     }
 
     bool silent = aubio_silence_detection(m_ibuf, m_threshold);
     }
 
     bool silent = aubio_silence_detection(m_ibuf, m_threshold);
@@ -221,13 +227,9 @@ Silence::process(const float *const *inputBuffers,
 
             fvec_t vec;
             vec.length = incr * 4;
 
             fvec_t vec;
             vec.length = incr * 4;
-            vec.channels = m_channelCount;
-            vec.data = m_tmpptrs;
             
             for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
             
             for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
-                for (size_t j = 0; j < m_channelCount; ++j) {
-                    m_tmpptrs[j] = m_ibuf->data[j] + i;
-                }
+                vec.data = m_ibuf->data + i;
                 bool subsilent = aubio_silence_detection(&vec, m_threshold);
                 if (silent == subsilent) {
                     off = i;
                 bool subsilent = aubio_silence_detection(&vec, m_threshold);
                 if (silent == subsilent) {
                     off = i;
@@ -237,9 +239,7 @@ Silence::process(const float *const *inputBuffers,
 
             if (silent && (off == 0)) {
                 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
 
             if (silent && (off == 0)) {
                 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
-                    for (size_t j = 0; j < m_channelCount; ++j) {
-                        m_tmpptrs[j] = m_pbuf->data[j] + m_stepSize - i - incr;
-                    }
+                    vec.data = m_pbuf->data + m_stepSize - i - incr;
                     bool subsilent = aubio_silence_detection(&vec, m_threshold);
                     if (!subsilent) {
                         off = -(long)i;
                     bool subsilent = aubio_silence_detection(&vec, m_threshold);
                     if (!subsilent) {
                         off = -(long)i;
@@ -284,7 +284,7 @@ Silence::process(const float *const *inputBuffers,
     // swap ibuf and pbuf data pointers, so that this block's data is
     // available in pbuf when processing the next block, without
     // having to allocate new storage for it
     // swap ibuf and pbuf data pointers, so that this block's data is
     // available in pbuf when processing the next block, without
     // having to allocate new storage for it
-    smpl_t **tmpdata = m_ibuf->data;
+    smpl_t *tmpdata = m_ibuf->data;
     m_ibuf->data = m_pbuf->data;
     m_pbuf->data = tmpdata;
 
     m_ibuf->data = m_pbuf->data;
     m_pbuf->data = tmpdata;