Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 7 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 37 additions and 16 deletions.
  1. +1 −1 README
  2. +35 −15 SpeechMusicSegmenter.cpp
  3. +1 −0 SpeechMusicSegmenter.h
View
2 README
@@ -22,7 +22,7 @@ Getting started
1) Edit the Makefile for your platform
2) Run make
3) Copy speechmusic-segmenter.so to your Vamp plugin directory, as defined in http://www.vamp-plugins.org/ (~/vamp/ on Linux)
-4) Use in any Vamp host, e.g. Sonic Visualiser
+4) Use in any Vamp host, e.g. Sonic Visualiser. If using vamp-simple-host, please note labels will only displayed for > 2.3
Parameters
----------
View
50 SpeechMusicSegmenter.cpp
@@ -25,7 +25,8 @@ SpeechMusicSegmenter::SpeechMusicSegmenter(float inputSampleRate) :
resolution(256),
margin(14),
change_threshold(0.0781),
- decision_threshold(0.2734)
+ decision_threshold(0.2734),
+ min_music_length(0)
// Also be sure to set your plugin parameters (presumably stored
// in member variables) to their default values here -- the host
// will not do that for you
@@ -160,6 +161,17 @@ SpeechMusicSegmenter::getParameterDescriptors() const
d22.isQuantized = false;
list.push_back(d22);
+ ParameterDescriptor d23;
+ d23.identifier = "min_music_length";
+ d23.name = "Minimum music segment length";
+ d23.description = "The minimum length of a music segment";
+ d23.unit = "";
+ d23.minValue = 0;
+ d23.maxValue = 100;
+ d23.defaultValue = 0;
+ d23.isQuantized = false;
+ list.push_back(d23);
+
ParameterDescriptor d3;
d3.identifier = "margin";
d3.name = "Margin";
@@ -189,6 +201,10 @@ SpeechMusicSegmenter::getParameter(string identifier) const
return decision_threshold;
}
+ if (identifier == "min_music_length") {
+ return min_music_length;
+ }
+
if (identifier == "margin") {
return margin;
}
@@ -216,6 +232,11 @@ SpeechMusicSegmenter::setParameter(string identifier, float value)
return;
}
+ if (identifier == "min_music_length") {
+ min_music_length = value;
+ return;
+ }
+
if (identifier == "margin") {
margin = value;
return;
@@ -329,10 +350,9 @@ SpeechMusicSegmenter::process(const float *const *inputBuffers, Vamp::RealTime t
SpeechMusicSegmenter::FeatureSet
SpeechMusicSegmenter::getRemainingFeatures()
{
- FeatureSet returnFeatures;
+ FeatureSet features;
vector<double> skewness = getSkewnessFunction();
double old_mean = 0.0;
- Feature previous_feature;
for (int n = 0; n < m_nframes / resolution; n++) {
double mean = 0.0;
for (int i = 0; i < resolution; i++) {
@@ -341,13 +361,7 @@ SpeechMusicSegmenter::getRemainingFeatures()
mean /= resolution;
if ((n > 0 && std::abs(mean - old_mean) > change_threshold) || n == 0) {
Feature feature; feature.hasTimestamp = true;
- int segment_start_frame;
- if (n > 0) {
- segment_start_frame = (n * resolution + resolution / 2.0) * m_blockSize;
- } else {
- segment_start_frame = 0;
- }
- feature.timestamp = Vamp::RealTime::frame2RealTime(segment_start_frame, static_cast<unsigned int>(m_inputSampleRate));
+ feature.timestamp = Vamp::RealTime::frame2RealTime((n * resolution + resolution / 2.0) * m_blockSize, static_cast<unsigned int>(m_inputSampleRate));
vector<float> floatval;
floatval.push_back(mean);
if (mean < decision_threshold) {
@@ -356,10 +370,16 @@ SpeechMusicSegmenter::getRemainingFeatures()
feature.label = "Speech";
}
feature.values = floatval;
- if (n == 0 || (feature.label != previous_feature.label)) {
- returnFeatures[0].push_back(feature);
+ if (features[0].size() == 0 || (features[0].size() > 0 && feature.label != features[0].back().label)) {
+ if (features[0].size() > 0 && features[0].back().label == "Music" &&
+ (feature.timestamp - features[0].back().timestamp < Vamp::RealTime::fromSeconds(min_music_length))
+ ) {
+ features[0].pop_back();
+ } else {
+ if (features[0].size() == 0) feature.timestamp = Vamp::RealTime::fromSeconds(0);
+ features[0].push_back(feature);
+ }
}
- previous_feature = feature;
}
old_mean = mean;
}
@@ -371,10 +391,10 @@ SpeechMusicSegmenter::getRemainingFeatures()
vector<float> floatval;
floatval.push_back(skewness[n]);
feature.values = floatval;
- returnFeatures[1].push_back(feature);
+ features[1].push_back(feature);
}
- return returnFeatures;
+ return features;
}
vector<double>
View
1 SpeechMusicSegmenter.h
@@ -74,6 +74,7 @@ class SpeechMusicSegmenter : public Vamp::Plugin
double margin;
double change_threshold;
double decision_threshold;
+ double min_music_length;
};

No commit comments for this range

Something went wrong with that request. Please try again.