Mercurial > hg > qm-dsp
changeset 58:d72fcd34d9a7
* Fixes to problems shown up by vamp-plugin-tester.
Still not all plugins pass all tests, though
author | cannam |
---|---|
date | Mon, 23 Mar 2009 16:28:53 +0000 |
parents | d241e7701c0c |
children | 2cfe2bc35367 |
files | dsp/keydetection/GetKeyMode.cpp dsp/onsets/PeakPicking.cpp dsp/segmentation/ClusterMeltSegmenter.cpp dsp/segmentation/cluster_segmenter.c dsp/signalconditioning/DFProcess.cpp dsp/signalconditioning/FiltFilt.cpp dsp/tempotracking/DownBeat.cpp hmm/hmm.c maths/MathUtilities.cpp qm-dsp.pro |
diffstat | 10 files changed, 58 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/dsp/keydetection/GetKeyMode.cpp Fri Feb 27 13:07:22 2009 +0000 +++ b/dsp/keydetection/GetKeyMode.cpp Mon Mar 23 16:28:53 2009 +0000 @@ -52,6 +52,7 @@ // Chromagram configuration parameters m_ChromaConfig.normalise = MathUtilities::NormaliseUnitMax; m_ChromaConfig.FS = lrint(sampleRate/(double)m_DecimationFactor); + if (m_ChromaConfig.FS < 1) m_ChromaConfig.FS = 1; // Set C (= MIDI #12) as our base : // This implies that key = 1 => Cmaj, key = 12 => Bmaj, key = 13 => Cmin, etc.
--- a/dsp/onsets/PeakPicking.cpp Fri Feb 27 13:07:22 2009 +0000 +++ b/dsp/onsets/PeakPicking.cpp Mon Mar 23 16:28:53 2009 +0000 @@ -61,6 +61,8 @@ void PeakPicking::process( double* src, unsigned int len, vector<int> &onsets ) { + if (len < 4) return; + vector <double> m_maxima; // Signal conditioning
--- a/dsp/segmentation/ClusterMeltSegmenter.cpp Fri Feb 27 13:07:22 2009 +0000 +++ b/dsp/segmentation/ClusterMeltSegmenter.cpp Mon Mar 23 16:28:53 2009 +0000 @@ -319,10 +319,12 @@ mfcc = 0; delete decimator; decimator = 0; - + + if (features.size() < histogramLength) return; +/* std::cerr << "ClusterMeltSegmenter::segment: have " << features.size() << " features with " << features[0].size() << " coefficients (ncoeff = " << ncoeff << ", ncomponents = " << ncomponents << ")" << std::endl; - +*/ // copy the features to a native array and use the existing C segmenter... double** arrFeatures = new double*[features.size()]; for (int i = 0; i < features.size(); i++)
--- a/dsp/segmentation/cluster_segmenter.c Fri Feb 27 13:07:22 2009 +0000 +++ b/dsp/segmentation/cluster_segmenter.c Mon Mar 23 16:28:53 2009 +0000 @@ -161,10 +161,10 @@ /* train the model */ hmm_train(features, frames_read, model); - +/* printf("\n\nafter training:\n"); hmm_print(model); - +*/ /* decode the hidden state sequence */ viterbi_decode(features, frames_read, model, q); hmm_close(model); @@ -174,10 +174,12 @@ /*****************************/ +/* fprintf(stderr, "HMM state sequence:\n"); for (i = 0; i < frames_read; i++) fprintf(stderr, "%d ", q[i]); fprintf(stderr, "\n\n"); +*/ /* create histograms of states */ double* h = (double*) malloc(frames_read*nHMM_states*sizeof(double)); /* vector in row major order */ @@ -209,12 +211,12 @@ if (feature_type == FEATURE_TYPE_CONSTQ) { - fprintf(stderr, "Converting to dB and normalising...\n"); - +/* fprintf(stderr, "Converting to dB and normalising...\n"); + */ mpeg7_constq(features, frames_read, ncoeff); - +/* fprintf(stderr, "Running PCA...\n"); - +*/ /* do PCA on the features (but not the envelope) */ int ncomponents = 20; pca_project(features, frames_read, ncoeff, ncomponents); @@ -255,8 +257,9 @@ if (feature_type == FEATURE_TYPE_CHROMA) { +/* fprintf(stderr, "Converting to chroma features...\n"); - +*/ /* convert constant-Q to normalised chroma features */ chroma = (double**) malloc(frames_read*sizeof(double*)); for (i = 0; i < frames_read; i++)
--- a/dsp/signalconditioning/DFProcess.cpp Fri Feb 27 13:07:22 2009 +0000 +++ b/dsp/signalconditioning/DFProcess.cpp Mon Mar 23 16:28:53 2009 +0000 @@ -70,6 +70,8 @@ void DFProcess::process(double *src, double* dst) { + if (m_length == 0) return; + removeDCNormalize( src, filtSrc ); m_FiltFilt->process( filtSrc, filtDst, m_length );
--- a/dsp/signalconditioning/FiltFilt.cpp Fri Feb 27 13:07:22 2009 +0000 +++ b/dsp/signalconditioning/FiltFilt.cpp Mon Mar 23 16:28:53 2009 +0000 @@ -48,11 +48,12 @@ { unsigned int i; + if (length == 0) return; + unsigned int nFilt = m_ord + 1; unsigned int nFact = 3 * ( nFilt - 1); unsigned int nExt = length + 2 * nFact; - m_filtScratchIn = new double[ nExt ]; m_filtScratchOut = new double[ nExt ];
--- a/dsp/tempotracking/DownBeat.cpp Fri Feb 27 13:07:22 2009 +0000 +++ b/dsp/tempotracking/DownBeat.cpp Mon Mar 23 16:28:53 2009 +0000 @@ -28,6 +28,7 @@ m_decimator1(0), m_decimator2(0), m_buffer(0), + m_decbuf(0), m_bufsiz(0), m_buffill(0), m_beatframesize(0), @@ -64,6 +65,7 @@ void DownBeat::makeDecimators() { +// std::cerr << "m_factor = " << m_factor << std::endl; if (m_factor < 2) return; int highest = Decimator::getHighestSupportedFactor(); if (m_factor <= highest) { @@ -91,20 +93,25 @@ m_buffer = (float *)realloc(m_buffer, m_bufsiz * sizeof(float)); } } - if (!m_decimator1) makeDecimators(); - float rmsin = 0, rmsout = 0; - for (int i = 0; i < m_increment; ++i) { - rmsin += audio[i] * audio[i]; - } + if (!m_decimator1 && m_factor > 1) makeDecimators(); +// float rmsin = 0, rmsout = 0; +// for (int i = 0; i < m_increment; ++i) { +// rmsin += audio[i] * audio[i]; +// } if (m_decimator2) { m_decimator1->process(audio, m_decbuf); m_decimator2->process(m_decbuf, m_buffer + m_buffill); + } else if (m_decimator1) { + m_decimator1->process(audio, m_buffer + m_buffill); } else { - m_decimator1->process(audio, m_buffer + m_buffill); + // just copy across (m_factor is presumably 1) + for (int i = 0; i < m_increment; ++i) { + (m_buffer + m_buffill)[i] = audio[i]; + } } - for (int i = 0; i < m_increment / m_factor; ++i) { - rmsout += m_buffer[m_buffill + i] * m_buffer[m_buffill + i]; - } +// for (int i = 0; i < m_increment / m_factor; ++i) { +// rmsout += m_buffer[m_buffill + i] * m_buffer[m_buffill + i]; +// } // std::cerr << "pushAudioBlock: rms in " << sqrt(rmsin) << ", out " << sqrt(rmsout) << std::endl; m_buffill += m_increment / m_factor; } @@ -120,6 +127,7 @@ DownBeat::resetAudioBuffer() { if (m_buffer) free(m_buffer); + m_buffer = 0; m_buffill = 0; m_bufsiz = 0; } @@ -161,13 +169,15 @@ // the size varies, it's easier to do this by hand than use // our Window abstraction.) - float rms = 0; - for (size_t j = 0; j < beatlen; ++j) { +// std::cerr << "beatlen = " << beatlen << std::endl; + +// float rms = 0; + for (size_t j = 0; j < beatlen && j < m_beatframesize; ++j) { double mul = 0.5 * (1.0 - cos(TWO_PI * (double(j) / double(beatlen)))); m_beatframe[j] = audio[beatstart + j] * mul; - rms += m_beatframe[j] * m_beatframe[j]; +// rms += m_beatframe[j] * m_beatframe[j]; } - rms = sqrt(rms); +// rms = sqrt(rms); // std::cerr << "beat " << i << ": audio rms " << rms << std::endl; for (size_t j = beatlen; j < m_beatframesize; ++j) {
--- a/hmm/hmm.c Fri Feb 27 13:07:22 2009 +0000 +++ b/hmm/hmm.c Mon Mar 23 16:28:53 2009 +0000 @@ -178,10 +178,10 @@ while (iter < niter && !foundnan && !(iter > 1 && (loglik - loglik1) < thresh * (loglik1 - loglik2))) { ++iter; - +/* fprintf(stderr, "calculating obsprobs...\n"); fflush(stderr); - +*/ /* precalculate obs probs */ invert(cov, L, icov, &detcov); @@ -206,16 +206,16 @@ } */ } - +/* fprintf(stderr, "forwards-backwards...\n"); fflush(stderr); - +*/ forward_backwards(xi, gamma, &loglik, &loglik1, &loglik2, iter, N, T, p0, a, b); - +/* fprintf(stderr, "iteration %d: loglik = %f\n", iter, loglik); fprintf(stderr, "re-estimation...\n"); fflush(stderr); - +*/ if (isnan(loglik)) { foundnan = 1; continue; @@ -293,7 +293,7 @@ { if (sum_gamma[i] == 0) { - fprintf(stderr, "sum_gamma[%d] was zero...\n", i); +/* fprintf(stderr, "sum_gamma[%d] was zero...\n", i); */ } //double s = 0; for (j = 0; j < N; j++)