# HG changeset patch # User Chris Cannam # Date 1199978112 0 # Node ID 9a2edd83775f35f53064dc462165c5ca85e10f32 # Parent 9ce0db4770a241a7c79239842160cb029ab639cf * Fixes and tidying in segmenter &c diff -r 9ce0db4770a2 -r 9a2edd83775f plugins/KeyDetect.cpp --- a/plugins/KeyDetect.cpp Wed Jan 09 16:51:59 2008 +0000 +++ b/plugins/KeyDetect.cpp Thu Jan 10 15:15:12 2008 +0000 @@ -1,37 +1,10 @@ /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ /* - Vamp - - An API for audio analysis and feature extraction plugins. + QM Vamp Plugin Set Centre for Digital Music, Queen Mary, University of London. - Copyright 2006-2007 QMUL. - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, copy, - modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR - ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - Except as contained in this notice, the names of the Centre for - Digital Music; Queen Mary, University of London; and Chris Cannam - shall not be used in advertising or otherwise to promote the sale, - use or other dealings in this Software without prior written - authorization. + All rights reserved. */ #include "KeyDetect.h" @@ -98,7 +71,7 @@ string KeyDetector::getCopyright() const { - return "Copyright (c) 2006-2007 - All Rights Reserved"; + return "Copyright (c) 2006-2008 - All Rights Reserved"; } KeyDetector::ParameterList @@ -311,9 +284,9 @@ if (minor) feature.label += " minor"; else feature.label += " major"; returnFeatures[2].push_back(feature); // key - cerr << "int key = "<initialise(static_cast(m_inputSampleRate)); - hopsize = segmenter->getHopsize(); - windowsize = segmenter->getWindowsize(); + ClusterMeltSegmenterParams params = ClusterMeltSegmenterParams(); + params.featureType = (feature_types) featureType; + + if (params.featureType == FEATURE_TYPE_CONSTQ) + { + params.ncomponents = 20; + params.neighbourhoodLimit = 30; + } + if (params.featureType == FEATURE_TYPE_CHROMA) + { + params.hopSize = 0.1; + params.windowSize = 0.372; + params.nbins = 12; + params.histogramLength = 20; + params.neighbourhoodLimit = 40; + } + delete segmenter; + + segmenter = new ClusterMeltSegmenter(params); + segmenter->initialise(m_inputSampleRate); + hopsize = segmenter->getHopsize(); + windowsize = segmenter->getWindowsize(); + + std::cerr << "segmenter window size: " << segmenter->getWindowsize() + << std::endl; } SegmenterPlugin::OutputList @@ -185,23 +196,23 @@ { OutputList list; - OutputDescriptor segmentation; - segmentation.identifier = "segmentation"; + OutputDescriptor segmentation; + segmentation.identifier = "segmentation"; segmentation.name = "Segmentation"; segmentation.description = "Segmentation"; segmentation.unit = "segment-type"; segmentation.hasFixedBinCount = true; segmentation.binCount = 1; - segmentation.minValue = 1; - segmentation.maxValue = nSegmentTypes; - segmentation.isQuantized = true; - segmentation.quantizeStep = 1; + segmentation.minValue = 1; + segmentation.maxValue = nSegmentTypes; + segmentation.isQuantized = true; + segmentation.quantizeStep = 1; segmentation.sampleType = OutputDescriptor::VariableSampleRate; segmentation.sampleRate = m_inputSampleRate / getPreferredStepSize(); list.push_back(segmentation); - return list; + return list; } SegmenterPlugin::FeatureSet @@ -210,41 +221,41 @@ // convert float* to double* double *tempBuffer = new double[windowsize]; for (size_t i = 0; i < windowsize; ++i) { - tempBuffer[i] = inputBuffers[0][i]; + tempBuffer[i] = inputBuffers[0][i]; } + + segmenter->extractFeatures(tempBuffer, segmenter->getWindowsize()); + + delete [] tempBuffer; - segmenter->extractFeatures(tempBuffer, windowsize); - - delete [] tempBuffer; - - return FeatureSet(); + return FeatureSet(); } SegmenterPlugin::FeatureSet SegmenterPlugin::getRemainingFeatures() { segmenter->segment(nSegmentTypes); - Segmentation segm = segmenter->getSegmentation(); + Segmentation segm = segmenter->getSegmentation(); - FeatureSet returnFeatures; + FeatureSet returnFeatures; for (int i = 0; i < segm.segments.size(); ++i) { - Segment s = segm.segments[i]; + Segment s = segm.segments[i]; - Feature feature; - feature.hasTimestamp = true; - feature.timestamp = Vamp::RealTime::frame2RealTime(s.start, static_cast(m_inputSampleRate)); + Feature feature; + feature.hasTimestamp = true; + feature.timestamp = Vamp::RealTime::frame2RealTime(s.start, static_cast(m_inputSampleRate)); - vector floatval; - floatval.push_back(s.type); - feature.values = floatval; + vector floatval; + floatval.push_back(s.type); + feature.values = floatval; - ostringstream oss; - oss << s.type; - feature.label = oss.str(); + ostringstream oss; + oss << s.type; + feature.label = oss.str(); - returnFeatures[0].push_back(feature); + returnFeatures[0].push_back(feature); } return returnFeatures; diff -r 9ce0db4770a2 -r 9a2edd83775f plugins/SegmenterPlugin.h --- a/plugins/SegmenterPlugin.h Wed Jan 09 16:51:59 2008 +0000 +++ b/plugins/SegmenterPlugin.h Thu Jan 10 15:15:12 2008 +0000 @@ -1,10 +1,11 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + /* - * SegmeterPlugin.h - * soundbite + * SegmenterPlugin.h * - * Created by Mark Levy on 24/03/2006. - * Copyright 2006 Centre for Digital Music, Queen Mary, University of London. All rights reserved. - * + * Created by Mark Levy on 24/03/2006. + * Copyright 2006 Centre for Digital Music, Queen Mary, University of London. + * All rights reserved. */ #ifndef _SEGMENTER_PLUGIN_H_ @@ -15,6 +16,8 @@ #include "dsp/segmentation/Segmenter.h" #include "dsp/segmentation/segment.h" +class Decimator; + class SegmenterPlugin : public Vamp::Plugin { public: @@ -24,8 +27,8 @@ bool initialise(size_t channels, size_t stepSize, size_t blockSize); void reset(); - std::string getIdentifier() const { return "qm-segmenter"; } - std::string getName() const { return "Segmenter"; } + std::string getIdentifier() const { return "qm-segmenter"; } + std::string getName() const { return "Segmenter"; } std::string getDescription() const { return "Divide the track into a sequence of consistent segments"; } std::string getMaker() const; int getPluginVersion() const; @@ -33,26 +36,26 @@ size_t getPreferredStepSize() const; size_t getPreferredBlockSize() const; - InputDomain getInputDomain() const { return TimeDomain; } - - SegmenterPlugin::ParameterList getParameterDescriptors() const; - float getParameter(std::string param) const; - void setParameter(std::string param, float value); - + InputDomain getInputDomain() const { return TimeDomain; } + + SegmenterPlugin::ParameterList getParameterDescriptors() const; + float getParameter(std::string param) const; + void setParameter(std::string param, float value); + OutputList getOutputDescriptors() const; - + FeatureSet process(const float *const *inputBuffers, Vamp::RealTime timestamp); - + FeatureSet getRemainingFeatures(); protected: - mutable Segmenter* segmenter; - mutable int hopsize; - mutable int windowsize; - int nSegmentTypes; - feature_types featureType; // 1 = constant-Q, 2 = chroma - - void makeSegmenter() const; + mutable Segmenter* segmenter; + mutable int hopsize; + mutable int windowsize; + int nSegmentTypes; + feature_types featureType; // 1 = constant-Q, 2 = chroma + + void makeSegmenter() const; }; #endif