# HG changeset patch # User Chris Cannam # Date 1406307008 -3600 # Node ID 41b09144491bda6e2a1330af29b79c81532a1a7f # Parent d960c4931501f76d30b00778807c26ae56d84de1 Start to calculate some roughly stereo-related things diff -r d960c4931501 -r 41b09144491b Azi.cpp --- a/Azi.cpp Fri Jul 25 17:11:57 2014 +0100 +++ b/Azi.cpp Fri Jul 25 17:50:08 2014 +0100 @@ -1,12 +1,13 @@ #include "Azi.h" +#include + +using std::vector; Azi::Azi(float inputSampleRate) : - Plugin(inputSampleRate) - // 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 + Plugin(inputSampleRate), + m_width(32) { } @@ -81,13 +82,13 @@ size_t Azi::getMinChannelCount() const { - return 1; + return 2; } size_t Azi::getMaxChannelCount() const { - return 1; + return 2; } Azi::ParameterList @@ -106,35 +107,18 @@ // not explicitly set your parameters to their defaults for you if // they have not changed in the mean time. - ParameterDescriptor d; - d.identifier = "parameter"; - d.name = "Some Parameter"; - d.description = ""; - d.unit = ""; - d.minValue = 0; - d.maxValue = 10; - d.defaultValue = 5; - d.isQuantized = false; - list.push_back(d); - return list; } float Azi::getParameter(string identifier) const { - if (identifier == "parameter") { - return 5; // return the ACTUAL current value of your parameter here! - } return 0; } void Azi::setParameter(string identifier, float value) { - if (identifier == "parameter") { - // set the actual value of your parameter - } } Azi::ProgramList @@ -168,12 +152,12 @@ // Every plugin must have at least one output. OutputDescriptor d; - d.identifier = "output"; - d.name = "My Output"; + d.identifier = "plan"; + d.name = "Plan"; d.description = ""; d.unit = ""; d.hasFixedBinCount = true; - d.binCount = 1; + d.binCount = m_width * 2 + 1; d.hasKnownExtents = false; d.isQuantized = false; d.sampleType = OutputDescriptor::OneSamplePerStep; @@ -189,7 +173,7 @@ if (channels < getMinChannelCount() || channels > getMaxChannelCount()) return false; - // Real initialisation work goes here! + m_blockSize = blockSize; return true; } @@ -200,11 +184,71 @@ // Clear buffers, reset stored values, etc } +float +Azi::rms(const float *buffer, int size) +{ + float sum = 0; + if (size == 0) { + return 0; + } + for (int i = 0; i < size; ++i) { + sum += buffer[i] * buffer[i]; + } + return sqrt(sum / size); +} + Azi::FeatureSet Azi::process(const float *const *inputBuffers, Vamp::RealTime timestamp) { - // Do actual work! - return FeatureSet(); + const float *left = inputBuffers[0]; + const float *right = inputBuffers[1]; + + float *mixed = new float[m_blockSize]; + for (int i = 0; i < m_blockSize; ++i) { + mixed[i] = inputBuffers[0][i] + inputBuffers[1][i]; + } + float mixedRms = rms(mixed, m_blockSize); + + FeatureSet fs; + Feature f; + + float *unpanned = new float[m_blockSize]; + + vector levels; + + for (int j = -m_width; j <= m_width; ++j) { + + float unpan = float(j) / m_width; + + float leftGain = 1.f, rightGain = 1.f; + if (unpan > 0.f) leftGain *= 1.f - unpan; + if (unpan < 0.f) rightGain *= unpan + 1.f; + + for (int i = 0; i < m_blockSize; ++i) { + unpanned[i] = (leftGain * left[i]) - (rightGain * right[i]); + } + + float unpannedRms = rms(unpanned, m_blockSize); + levels.push_back((mixedRms - unpannedRms) / mixedRms); + } + + for (int i = 1; i+1 < int(levels.size()); ++i) { + f.values.push_back(1.f - levels[i]); +/* + if (levels[i] < levels[i-1] && levels[i] < levels[i+1]) { + f.values.push_back(levels[i]); + } else { + f.values.push_back(0); + } +*/ + } + + delete[] unpanned; + delete[] mixed; + + fs[0].push_back(f); + + return fs; } Azi::FeatureSet diff -r d960c4931501 -r 41b09144491b Azi.h --- a/Azi.h Fri Jul 25 17:11:57 2014 +0100 +++ b/Azi.h Fri Jul 25 17:50:08 2014 +0100 @@ -44,7 +44,10 @@ FeatureSet getRemainingFeatures(); protected: - // plugin-specific data and methods go here + int m_width; + int m_blockSize; + + float rms(const float *buffer, int size); }; diff -r d960c4931501 -r 41b09144491b Makefile.inc --- a/Makefile.inc Fri Jul 25 17:11:57 2014 +0100 +++ b/Makefile.inc Fri Jul 25 17:50:08 2014 +0100 @@ -17,7 +17,7 @@ PLUGIN := azi$(PLUGIN_EXT) PLUGIN_HEADERS := $(SRC_DIR)/Azi.h -PLUGIN_SOURCES := $(SRC_DIR)/Azi.cpp +PLUGIN_SOURCES := $(SRC_DIR)/Azi.cpp $(SRC_DIR)/plugins.cpp HEADERS := $(PLUGIN_HEADERS) SOURCES := $(PLUGIN_SOURCES)