Mercurial > hg > vamp-plugin-sdk
changeset 7:c66551966b5f
* Fix a couple of memory management and corruption bugs
* Some textual fixes
author | cannam |
---|---|
date | Fri, 31 Mar 2006 17:39:49 +0000 |
parents | 8f10d35a4090 |
children | c4662bbef275 |
files | Makefile examples/SpectralCentroid.cpp examples/ZeroCrossing.cpp vamp-sdk/PluginAdapter.cpp vamp-sdk/PluginHostAdapter.cpp |
diffstat | 5 files changed, 74 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Fri Mar 31 16:26:28 2006 +0000 +++ b/Makefile Fri Mar 31 17:39:49 2006 +0000 @@ -1,11 +1,11 @@ -all: examples/plugins.so host/simplehost test +all: examples_ host_ test -examples/plugins.so: +examples_: $(MAKE) -C examples all -host/simplehost: +host_: $(MAKE) -C host all test:
--- a/examples/SpectralCentroid.cpp Fri Mar 31 16:26:28 2006 +0000 +++ b/examples/SpectralCentroid.cpp Fri Mar 31 17:39:49 2006 +0000 @@ -36,16 +36,13 @@ #include "SpectralCentroid.h" -/* -#include "dsp/transforms/FFT.h" -#include "base/Window.h" -*/ - using std::string; using std::vector; using std::cerr; using std::endl; +#include <cmath> + SpectralCentroid::SpectralCentroid(float inputSampleRate) : Plugin(inputSampleRate), @@ -75,7 +72,7 @@ string SpectralCentroid::getMaker() const { - return "QMUL"; + return "Queen Mary, University of London"; } int @@ -87,7 +84,7 @@ string SpectralCentroid::getCopyright() const { - return "GPL"; + return "Freely redistributable (BSD license)"; } bool @@ -157,21 +154,6 @@ return FeatureSet(); } -/* - for (size_t i = 0; i < m_blockSize; ++i) { - m_workBuffer[i] = inputBuffers[0][i]; - m_workBuffer[i + m_blockSize] = 0.0; - } - - Window<double>(HanningWindow, m_blockSize).cut(m_workBuffer); - - FFT::process(m_blockSize, false, - m_workBuffer, - m_workBuffer + m_blockSize, - m_workBuffer + m_blockSize*2, - m_workBuffer + m_blockSize*3); -*/ - double numLin = 0.0, numLog = 0.0, denom = 0.0; for (size_t i = 1; i < m_blockSize/2; ++i) {
--- a/examples/ZeroCrossing.cpp Fri Mar 31 16:26:28 2006 +0000 +++ b/examples/ZeroCrossing.cpp Fri Mar 31 17:39:49 2006 +0000 @@ -68,7 +68,7 @@ string ZeroCrossing::getMaker() const { - return "QMUL"; + return "Queen Mary, University of London"; } int @@ -80,7 +80,7 @@ string ZeroCrossing::getCopyright() const { - return "GPL"; + return "Freely redistributable (BSD license)"; } bool
--- a/vamp-sdk/PluginAdapter.cpp Fri Mar 31 16:26:28 2006 +0000 +++ b/vamp-sdk/PluginAdapter.cpp Fri Mar 31 17:39:49 2006 +0000 @@ -62,8 +62,10 @@ m_descriptor.parameterCount = m_parameters.size(); m_descriptor.parameters = (const VampParameterDescriptor **) malloc(m_parameters.size() * sizeof(VampParameterDescriptor)); + + unsigned int i; - for (unsigned int i = 0; i < m_parameters.size(); ++i) { + for (i = 0; i < m_parameters.size(); ++i) { VampParameterDescriptor *desc = (VampParameterDescriptor *) malloc(sizeof(VampParameterDescriptor)); desc->name = strdup(m_parameters[i].name.c_str()); @@ -81,7 +83,7 @@ m_descriptor.programs = (const char **) malloc(m_programs.size() * sizeof(const char *)); - for (unsigned int i = 0; i < m_programs.size(); ++i) { + for (i = 0; i < m_programs.size(); ++i) { m_descriptor.programs[i] = strdup(m_programs[i].c_str()); } @@ -316,16 +318,19 @@ PluginAdapterBase::vampReleaseFeatureSet(VampFeatureList **fs) { if (!fs) return; + for (unsigned int i = 0; fs[i]; ++i) { + for (unsigned int j = 0; j < fs[i]->featureCount; ++j) { VampFeature *feature = &fs[i]->features[j]; if (feature->values) free((void *)feature->values); if (feature->label) free((void *)feature->label); - free((void *)feature); } + if (fs[i]->features) free((void *)fs[i]->features); free((void *)fs[i]); } + free((void *)fs); } @@ -373,15 +378,19 @@ desc->hasFixedValueCount = od.hasFixedValueCount; desc->valueCount = od.valueCount; - desc->valueNames = (const char **) - malloc(od.valueCount * sizeof(const char *)); + if (od.valueCount > 0) { + desc->valueNames = (const char **) + malloc(od.valueCount * sizeof(const char *)); - for (unsigned int i = 0; i < od.valueCount; ++i) { - if (i < od.valueNames.size()) { - desc->valueNames[i] = strdup(od.valueNames[i].c_str()); - } else { - desc->valueNames[i] = 0; + for (unsigned int i = 0; i < od.valueCount; ++i) { + if (i < od.valueNames.size()) { + desc->valueNames[i] = strdup(od.valueNames[i].c_str()); + } else { + desc->valueNames[i] = 0; + } } + } else { + desc->valueNames = 0; } desc->hasKnownExtents = od.hasKnownExtents; @@ -435,28 +444,49 @@ malloc((n + 1) * sizeof(VampFeatureList *)); for (unsigned int i = 0; i < n; ++i) { + fs[i] = (VampFeatureList *)malloc(sizeof(VampFeatureList)); + if (features.find(i) == features.end()) { + fs[i]->featureCount = 0; fs[i]->features = 0; - } else { - Plugin::FeatureSet::const_iterator fi = - features.find(i); - const Plugin::FeatureList &fl = fi->second; - fs[i]->featureCount = fl.size(); - fs[i]->features = (VampFeature *)malloc(fl.size() * - sizeof(VampFeature)); - for (unsigned int j = 0; j < fl.size(); ++j) { - fs[i]->features[j].hasTimestamp = fl[j].hasTimestamp; - fs[i]->features[j].sec = fl[j].timestamp.sec; - fs[i]->features[j].nsec = fl[j].timestamp.nsec; - fs[i]->features[j].valueCount = fl[j].values.size(); - fs[i]->features[j].values = (float *)malloc - (fs[i]->features[j].valueCount * sizeof(float)); - for (unsigned int k = 0; k < fs[i]->features[j].valueCount; ++k) { - fs[i]->features[j].values[k] = fl[j].values[k]; - } - fs[i]->features[j].label = strdup(fl[j].label.c_str()); + continue; + } + + Plugin::FeatureSet::const_iterator fi = features.find(i); + + const Plugin::FeatureList &fl = fi->second; + + fs[i]->featureCount = fl.size(); + + if (fs[i]->featureCount == 0) { + fs[i]->features = 0; + continue; + } + + fs[i]->features = (VampFeature *)malloc(fl.size() * sizeof(VampFeature)); + + for (unsigned int j = 0; j < fl.size(); ++j) { + + VampFeature *feature = &fs[i]->features[j]; + + feature->hasTimestamp = fl[j].hasTimestamp; + feature->sec = fl[j].timestamp.sec; + feature->nsec = fl[j].timestamp.nsec; + feature->valueCount = fl[j].values.size(); + feature->label = strdup(fl[j].label.c_str()); + + if (feature->valueCount == 0) { + feature->values = 0; + continue; + } + + feature->values = (float *)malloc + (feature->valueCount * sizeof(float)); + + for (unsigned int k = 0; k < feature->valueCount; ++k) { + feature->values[k] = fl[j].values[k]; } } }
--- a/vamp-sdk/PluginHostAdapter.cpp Fri Mar 31 16:26:28 2006 +0000 +++ b/vamp-sdk/PluginHostAdapter.cpp Fri Mar 31 17:39:49 2006 +0000 @@ -223,7 +223,7 @@ d.hasFixedValueCount = sd->hasFixedValueCount; d.valueCount = sd->valueCount; for (unsigned int j = 0; j < sd->valueCount; ++j) { - d.valueNames.push_back(sd->valueNames[i] ? sd->valueNames[i] : ""); + d.valueNames.push_back(sd->valueNames[j] ? sd->valueNames[j] : ""); } d.hasKnownExtents = sd->hasKnownExtents; d.minValue = sd->minValue; @@ -286,6 +286,8 @@ PluginHostAdapter::convertFeatures(VampFeatureList **features, FeatureSet &fs) { + if (!features) return; + for (unsigned int i = 0; features[i]; ++i) { VampFeatureList &list = *features[i]; @@ -302,8 +304,10 @@ for (unsigned int k = 0; k < list.features[j].valueCount; ++k) { feature.values.push_back(list.features[j].values[k]); } - - feature.label = list.features[j].label; + + if (list.features[j].label) { + feature.label = list.features[j].label; + } fs[i].push_back(feature); }