# HG changeset patch # User Carl Bussey # Date 1408112248 -3600 # Node ID de7213b3575549b9b0f4e3d1f384bf887d2144be # Parent e90a4797e579742870c18e5b7083e450e153e60e * Removed warnings of comparisons with ints and size_t diff -r e90a4797e579 -r de7213b35755 FIRFilter.cpp --- a/FIRFilter.cpp Fri Aug 15 12:34:07 2014 +0100 +++ b/FIRFilter.cpp Fri Aug 15 15:17:28 2014 +0100 @@ -51,7 +51,7 @@ m_pFftOutputReal = new double[m_lengthFIRFFT]; m_pFftOutputImag = new double[m_lengthFIRFFT]; - for(unsigned int i = 0; i < m_lengthFIRFFT; i++){ + for(int i = 0; i < (int)m_lengthFIRFFT; i++){ m_pFftInput[i] = m_pFftCoefficients[i] = m_pFftReal1[i] = m_pFftImag1[i] = m_pFftReal2[i] = m_pFftImag2[i] = m_pFftFilteredReal[i] = m_pFftFilteredImag[i] = m_pFftOutputReal[i] = m_pFftOutputImag[i] = 0.0; } } @@ -61,16 +61,16 @@ { //Copy to same length FFT buffers - for(unsigned int i = 0; i < m_lengthFIRFFT; i++){ - m_pFftInput[i] = i < m_lengthInput ? pInput[i] : 0.0; - m_pFftCoefficients[i] = i < m_numberOfCoefficients ? pCoefficients[i] : 0.0; + for(int i = 0; i < (int)m_lengthFIRFFT; i++){ + m_pFftInput[i] = i < (int)m_lengthInput ? pInput[i] : 0.0; + m_pFftCoefficients[i] = i < (int)m_numberOfCoefficients ? pCoefficients[i] : 0.0; } FFT::forward(m_lengthFIRFFT, m_pFftInput, 0, m_pFftReal1, m_pFftImag1); FFT::forward(m_lengthFIRFFT, m_pFftCoefficients, 0, m_pFftReal2, m_pFftImag2); //Multiply FFT coefficients. Multiplication in freq domain is convolution in time domain. - for (unsigned int i = 0; i < m_lengthFIRFFT; i++){ + for (int i = 0; i < (int)m_lengthFIRFFT; i++){ m_pFftFilteredReal[i] = (m_pFftReal1[i] * m_pFftReal2[i]) - (m_pFftImag1[i] * m_pFftImag2[i]); m_pFftFilteredImag[i] = (m_pFftReal1[i] * m_pFftImag2[i]) + (m_pFftReal2[i] * m_pFftImag1[i]); } @@ -79,12 +79,12 @@ //copy to output int offset = 0; - unsigned int outputLength = m_lengthInput; - if (outputType == all) outputLength = m_lengthFIRFFT; - else if (outputType == middle) offset = floor((float)m_numberOfCoefficients/2); + int outputLength = m_lengthInput; + if (outputType == all) outputLength = (int)m_lengthFIRFFT; + else if (outputType == middle) offset = floor(m_numberOfCoefficients/2.0f); else if (outputType != first) cerr << "FIRFilter::process(params) - " << outputType << " is not a valid argument. outputType is set to first." << endl; - for (unsigned int i = 0; i < outputLength; i++){ + for (int i = 0; i < outputLength; i++){ pOutput[i] = m_pFftOutputReal[i + offset]; } } diff -r e90a4797e579 -r de7213b35755 FIRFilter.h --- a/FIRFilter.h Fri Aug 15 12:34:07 2014 +0100 +++ b/FIRFilter.h Fri Aug 15 15:17:28 2014 +0100 @@ -28,7 +28,7 @@ private: size_t m_lengthInput; size_t m_numberOfCoefficients; - int m_lengthFIRFFT; + size_t m_lengthFIRFFT; double *m_pFftInput; double *m_pFftCoefficients; diff -r e90a4797e579 -r de7213b35755 Makefile --- a/Makefile Fri Aug 15 12:34:07 2014 +0100 +++ b/Makefile Fri Aug 15 15:17:28 2014 +0100 @@ -40,7 +40,7 @@ CXX := g++ #-mmacosx-version-min=10.6 -CXXFLAGS := -mmacosx-version-min=10.6 -arch x86_64 -I$(VAMP_SDK_DIR) -Wall -fPIC +CXXFLAGS := -mmacosx-version-min=10.6 -arch x86_64 -I$(VAMP_SDK_DIR) -Wall -Wextra -fPIC PLUGIN_EXT := .dylib LDFLAGS := $(CXXFLAGS) -dynamiclib -install_name $(PLUGIN_LIBRARY_NAME)$(PLUGIN_EXT) /usr/local/lib/libvamp-sdk.a -exported_symbols_list vamp-plugin.list diff -r e90a4797e579 -r de7213b35755 NoveltyCurveProcessor.cpp --- a/NoveltyCurveProcessor.cpp Fri Aug 15 12:34:07 2014 +0100 +++ b/NoveltyCurveProcessor.cpp Fri Aug 15 15:17:28 2014 +0100 @@ -97,13 +97,13 @@ WindowFunction::hanning(diffHannWindow, smoothLength, true); if(smoothLength%2) diffHannWindow[(smoothLength+1)/2 - 1] = 0; - for(unsigned int i = (smoothLength+1)/2; i < smoothLength; i++){ + for(int i = (smoothLength+1)/2; i < (int)smoothLength; i++){ diffHannWindow[i] = -diffHannWindow[i]; } FIRFilter smoothFilter(m_numberOfBlocks, smoothLength); - for (unsigned int i = 0; i < m_blockSize; i++){ + for (int i = 0; i < (int)m_blockSize; i++){ smoothFilter.process(&spectrogram[i][0], diffHannWindow, &spectrogram[i][0], FIRFilter::middle); } } @@ -111,8 +111,8 @@ //half rectification (set negative to zero) void NoveltyCurveProcessor::halfWaveRectify(vector< vector > &spectrogram) const { - for (unsigned int block = 0; block < m_numberOfBlocks; block++){ - for (unsigned int k = 0; k < m_blockSize; k++){ + for (int block = 0; block < (int)m_numberOfBlocks; block++){ + for (int k = 0; k < (int)m_blockSize; k++){ if (spectrogram[k][block] < 0.0) spectrogram[k][block] = 0.0; } } @@ -130,8 +130,8 @@ //normalise and log spectrogram float normaliseScale = calculateMax(spectrogram); - for (unsigned int block = 0; block < m_numberOfBlocks; block++){ - for (unsigned int k = 0; k < m_blockSize; k++){ + for (int block = 0; block < (int)m_numberOfBlocks; block++){ + for (int k = 0; k < (int)m_blockSize; k++){ if(normaliseScale != 0.0) spectrogram[k][block] /= normaliseScale; //normalise spectrogram[k][block] = log(1+m_compressionConstant*spectrogram[k][block]); } @@ -143,8 +143,8 @@ halfWaveRectify(spectrogram); //bandwise processing - for (unsigned int block = 0; block < m_numberOfBlocks; block++){ - for (unsigned int band = 0; band < m_numberOfBands; band++){ + for (int block = 0; block < (int)m_numberOfBlocks; block++){ + for (int band = 0; band < (int)m_numberOfBands; band++){ int k = m_pBandBoundaries[band]; int bandEnd = m_pBandBoundaries[band+1]; m_pBandSum[band] = 0; @@ -155,7 +155,7 @@ } } float total = 0; - for(unsigned int band = 0; band < m_numberOfBands; band++){ + for(int band = 0; band < (int)m_numberOfBands; band++){ total += m_pBandSum[band]; } noveltyCurve[block] = total/m_numberOfBands; diff -r e90a4797e579 -r de7213b35755 NoveltyCurveProcessor.h --- a/NoveltyCurveProcessor.h Fri Aug 15 12:34:07 2014 +0100 +++ b/NoveltyCurveProcessor.h Fri Aug 15 15:17:28 2014 +0100 @@ -22,11 +22,11 @@ class NoveltyCurveProcessor{ float m_samplingFrequency; - int m_fftLength; - int m_blockSize; - int m_numberOfBlocks; + size_t m_fftLength; + size_t m_blockSize; + size_t m_numberOfBlocks; int m_compressionConstant; - int m_numberOfBands; + size_t m_numberOfBands; int * m_pBandBoundaries; float * m_pBandSum; diff -r e90a4797e579 -r de7213b35755 SpectrogramProcessor.cpp --- a/SpectrogramProcessor.cpp Fri Aug 15 12:34:07 2014 +0100 +++ b/SpectrogramProcessor.cpp Fri Aug 15 15:17:28 2014 +0100 @@ -68,7 +68,7 @@ while(readBlockPointerIndex <= inputLength) { int readPointer = readBlockPointerIndex - m_windowLength/2; - for (unsigned int n = 0; n < m_windowLength; n++){ + for (int n = 0; n < (int)m_windowLength; n++){ if(readPointer < 0 || readPointer >= (int)inputLength){ m_pFftInput[n] = 0.0; //pad with zeros } @@ -77,7 +77,7 @@ } readPointer++; } - for (unsigned int n = m_windowLength; n < m_fftLength; n++){ + for (int n = m_windowLength; n < (int)m_fftLength; n++){ m_pFftInput[n] = 0.0; } @@ -85,7 +85,7 @@ vector binValues; //@todo: sample at logarithmic spacing? Leave for host? - for(unsigned int k = 0; k < m_numberOfOutputBins; k++){ + for(int k = 0; k < (int)m_numberOfOutputBins; k++){ binValues.push_back(m_pFftOutputReal[k]*m_pFftOutputReal[k] + m_pFftOutputImag[k]*m_pFftOutputImag[k]); //Magnitude or power? //std::cout << spectrogram[k][writeBlockPointer] << std::endl; } diff -r e90a4797e579 -r de7213b35755 SpectrogramProcessor.h --- a/SpectrogramProcessor.h Fri Aug 15 12:34:07 2014 +0100 +++ b/SpectrogramProcessor.h Fri Aug 15 15:17:28 2014 +0100 @@ -11,6 +11,7 @@ #include #include #include +#include typedef std::vector > Spectrogram; typedef std::vector > SpectrogramTransposed; diff -r e90a4797e579 -r de7213b35755 TempogramPlugin.cpp --- a/TempogramPlugin.cpp Fri Aug 15 12:34:07 2014 +0100 +++ b/TempogramPlugin.cpp Fri Aug 15 15:17:28 2014 +0100 @@ -383,17 +383,7 @@ return list; } -bool -TempogramPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) -{ - if (channels < getMinChannelCount() || - channels > getMaxChannelCount()) return false; - - // Real initialisation work goes here! - m_inputBlockSize = blockSize; - m_inputStepSize = stepSize; - - m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2 + 1); +void TempogramPlugin::checkParameterValues(){ if (m_tempogramFftLength < m_tempogramWindowLength){ m_tempogramFftLength = m_tempogramWindowLength; @@ -415,6 +405,20 @@ int numberOfBinsInFirstOctave = bpmToBin(m_cyclicTempogramMinBPM); if (m_cyclicTempogramOctaveDivider > numberOfBinsInFirstOctave) m_cyclicTempogramOctaveDivider = numberOfBinsInFirstOctave; +} + +bool +TempogramPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) +{ + if (channels < getMinChannelCount() || + channels > getMaxChannelCount()) return false; + + // Real initialisation work goes here! + m_inputBlockSize = blockSize; + m_inputStepSize = stepSize; + + m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2.0f + 1); + checkParameterValues(); //cout << m_cyclicTempogramOctaveDivider << endl; return true; @@ -425,7 +429,8 @@ { // Clear buffers, reset stored values, etc m_spectrogram.clear(); - m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2 + 1); + m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2.0f + 1); + checkParameterValues(); } TempogramPlugin::FeatureSet @@ -439,7 +444,7 @@ const float *in = inputBuffers[0]; //calculate magnitude of FrequencyDomain input - for (unsigned int i = 0; i < n; i++){ + for (int i = 0; i < (int)n; i++){ float magnitude = sqrt(in[2*i] * in[2*i] + in[2*i + 1] * in[2*i + 1]); magnitude = magnitude > m_noveltyCurveMinDB ? magnitude : m_noveltyCurveMinDB; m_spectrogram[i].push_back(magnitude); @@ -457,10 +462,10 @@ int bin = bpmToBin(bpm); logBins.push_back(bin); - cerr << bin << endl; + //cerr << bin << endl; } - cerr << logBins.size() << endl; + //cerr << logBins.size() << endl; return logBins; } @@ -472,7 +477,7 @@ int bin = floor((float)m_tempogramFftLength*w/sampleRate + 0.5); if(bin < 0) bin = 0; - else if(bin > m_tempogramFftLength/2) bin = m_tempogramFftLength; + else if(bin > m_tempogramFftLength/2.0f) bin = m_tempogramFftLength; return bin; } @@ -482,7 +487,7 @@ { float * hannWindow = new float[m_tempogramWindowLength]; - for (unsigned int i = 0; i < m_tempogramWindowLength; i++){ + for (int i = 0; i < (int)m_tempogramWindowLength; i++){ hannWindow[i] = 0.0; } @@ -490,11 +495,13 @@ //initialise novelty curve processor size_t numberOfBlocks = m_spectrogram[0].size(); + //cerr << numberOfBlocks << endl; NoveltyCurveProcessor nc(m_inputSampleRate, m_inputBlockSize, numberOfBlocks, m_noveltyCurveCompressionConstant); vector noveltyCurve = nc.spectrogramToNoveltyCurve(m_spectrogram); //calculate novelty curve from magnitude data + //if(noveltyCurve.size() > 50) for (int i = 0; i < 50; i++) cerr << noveltyCurve[i] << endl; //push novelty curve data to featureset 1 and set timestamps - for (unsigned int i = 0; i < numberOfBlocks; i++){ + for (int i = 0; i < (int)numberOfBlocks; i++){ Feature noveltyCurveFeature; noveltyCurveFeature.values.push_back(noveltyCurve[i]); noveltyCurveFeature.hasTimestamp = false; @@ -528,14 +535,14 @@ //Calculate cyclic tempogram vector logBins = calculateTempogramNearestNeighbourLogBins(); - assert(logBins.back() <= m_tempogramFftLength/2); - assert(logBins.size() == m_cyclicTempogramOctaveDivider*m_cyclicTempogramNumberOfOctaves); + assert(logBins.back() <= m_tempogramFftLength/2.0f); + assert((int)logBins.size() == m_cyclicTempogramOctaveDivider*m_cyclicTempogramNumberOfOctaves); for (int block = 0; block < tempogramLength; block++){ Feature cyclicTempogramFeature; - for (int i = 0; i < m_cyclicTempogramOctaveDivider; i++){ + for (int i = 0; i < (int)m_cyclicTempogramOctaveDivider; i++){ float sum = 0; - for (int j = 0; j < m_cyclicTempogramNumberOfOctaves; j++){ + for (int j = 0; j < (int)m_cyclicTempogramNumberOfOctaves; j++){ sum += tempogram[block][logBins[i+j*m_cyclicTempogramOctaveDivider]]; } cyclicTempogramFeature.values.push_back(sum/m_cyclicTempogramNumberOfOctaves); diff -r e90a4797e579 -r de7213b35755 TempogramPlugin.h --- a/TempogramPlugin.h Fri Aug 15 12:34:07 2014 +0100 +++ b/TempogramPlugin.h Fri Aug 15 15:17:28 2014 +0100 @@ -104,6 +104,7 @@ string floatToString(float value) const; vector calculateTempogramNearestNeighbourLogBins() const; int bpmToBin(const float &bpm) const; + void checkParameterValues(); }; diff -r e90a4797e579 -r de7213b35755 WindowFunction.cpp --- a/WindowFunction.cpp Fri Aug 15 12:34:07 2014 +0100 +++ b/WindowFunction.cpp Fri Aug 15 15:17:28 2014 +0100 @@ -14,12 +14,12 @@ WindowFunction::hanning(float * window, const unsigned int &N, const bool &normalise){ float sum = 0; - for(unsigned int i = 0; i < N; i++){ + for(int i = 0; i < (int)N; i++){ window[i] = 0.5*(1-cos((float)2*M_PI*i/N)); sum += window[i]; } if (normalise){ - for(int i = 0; i < N; i++){ + for(int i = 0; i < (int)N; i++){ window[i] /= sum; } }