annotate dsp/tempotracking/DownBeat.h @ 321:f1e6be2de9a5

A threshold (delta) is added in the peak picking parameters structure (PPickParams). It is used as an offset when computing the smoothed detection function. A constructor for the structure PPickParams is also added to set the parameters to 0 when a structure instance is created. Hence programmes using the peak picking parameter structure and which do not set the delta parameter (e.g. QM Vamp note onset detector) won't be affected by the modifications. Functions modified: - dsp/onsets/PeakPicking.cpp - dsp/onsets/PeakPicking.h - dsp/signalconditioning/DFProcess.cpp - dsp/signalconditioning/DFProcess.h
author mathieub <mathieu.barthet@eecs.qmul.ac.uk>
date Mon, 20 Jun 2011 19:01:48 +0100
parents d5014ab8b0e5
children 915365c58758
rev   line source
c@279 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@279 2
c@279 3 /*
c@279 4 QM DSP Library
c@279 5
c@279 6 Centre for Digital Music, Queen Mary, University of London.
c@279 7 This file copyright 2008-2009 Matthew Davies and QMUL.
c@309 8
c@309 9 This program is free software; you can redistribute it and/or
c@309 10 modify it under the terms of the GNU General Public License as
c@309 11 published by the Free Software Foundation; either version 2 of the
c@309 12 License, or (at your option) any later version. See the file
c@309 13 COPYING included with this distribution for more information.
c@279 14 */
c@279 15
c@279 16 #ifndef DOWNBEAT_H
c@279 17 #define DOWNBEAT_H
c@279 18
c@279 19 #include <vector>
c@279 20
c@279 21 #include "dsp/rateconversion/Decimator.h"
c@279 22
c@279 23 using std::vector;
c@279 24
c@289 25 class FFTReal;
c@289 26
c@279 27 /**
c@279 28 * This class takes an input audio signal and a sequence of beat
c@279 29 * locations (calculated e.g. by TempoTrackV2) and estimates which of
c@279 30 * the beat locations are downbeats (first beat of the bar).
c@279 31 *
c@279 32 * The input audio signal is expected to have been downsampled to a
c@279 33 * very low sampling rate (e.g. 2700Hz). A utility function for
c@279 34 * downsampling and buffering incoming block-by-block audio is
c@279 35 * provided.
c@279 36 */
c@279 37 class DownBeat
c@279 38 {
c@279 39 public:
c@279 40 /**
c@279 41 * Construct a downbeat locator that will operate on audio at the
c@279 42 * downsampled by the given decimation factor from the given
c@279 43 * original sample rate, plus beats extracted from the same audio
c@279 44 * at the given original sample rate with the given frame
c@279 45 * increment.
c@279 46 *
c@279 47 * decimationFactor must be a power of two no greater than 64, and
c@279 48 * dfIncrement must be a multiple of decimationFactor.
c@279 49 */
c@279 50 DownBeat(float originalSampleRate,
c@279 51 size_t decimationFactor,
c@279 52 size_t dfIncrement);
c@279 53 ~DownBeat();
c@279 54
c@280 55 void setBeatsPerBar(int bpb);
c@280 56
c@279 57 /**
c@279 58 * Estimate which beats are down-beats.
c@279 59 *
c@279 60 * audio contains the input audio stream after downsampling, and
c@279 61 * audioLength contains the number of samples in this downsampled
c@279 62 * stream.
c@279 63 *
c@279 64 * beats contains a series of beat positions expressed in
c@279 65 * multiples of the df increment at the audio's original sample
c@279 66 * rate, as described to the constructor.
c@279 67 *
c@279 68 * The returned downbeat array contains a series of indices to the
c@279 69 * beats array.
c@279 70 */
c@280 71 void findDownBeats(const float *audio, // downsampled
c@279 72 size_t audioLength, // after downsampling
c@279 73 const vector<double> &beats,
c@279 74 vector<int> &downbeats);
c@281 75
c@281 76 /**
c@281 77 * Return the beat spectral difference function. This is
c@281 78 * calculated during findDownBeats, so this function can only be
c@281 79 * meaningfully called after that has completed. The returned
c@281 80 * vector contains one value for each of the beat times passed in
c@281 81 * to findDownBeats, less one. Each value contains the spectral
c@281 82 * difference between region prior to the beat's nominal position
c@281 83 * and the region following it.
c@281 84 */
c@281 85 void getBeatSD(vector<double> &beatsd) const;
c@279 86
c@279 87 /**
c@279 88 * For your downsampling convenience: call this function
c@279 89 * repeatedly with input audio blocks containing dfIncrement
c@279 90 * samples at the original sample rate, to decimate them to the
c@279 91 * downsampled rate and buffer them within the DownBeat class.
c@279 92 *
c@279 93 * Call getBufferedAudio() to retrieve the results after all
c@279 94 * blocks have been processed.
c@279 95 */
c@280 96 void pushAudioBlock(const float *audio);
c@279 97
c@279 98 /**
c@279 99 * Retrieve the accumulated audio produced by pushAudioBlock calls.
c@279 100 */
c@280 101 const float *getBufferedAudio(size_t &length) const;
c@280 102
c@280 103 /**
c@280 104 * Clear any buffered downsampled audio data.
c@280 105 */
c@280 106 void resetAudioBuffer();
c@279 107
c@279 108 private:
c@279 109 typedef vector<int> i_vec_t;
c@279 110 typedef vector<vector<int> > i_mat_t;
c@279 111 typedef vector<double> d_vec_t;
c@279 112 typedef vector<vector<double> > d_mat_t;
c@279 113
c@279 114 void makeDecimators();
c@279 115 double measureSpecDiff(d_vec_t oldspec, d_vec_t newspec);
c@279 116
c@280 117 int m_bpb;
c@279 118 float m_rate;
c@279 119 size_t m_factor;
c@279 120 size_t m_increment;
c@279 121 Decimator *m_decimator1;
c@279 122 Decimator *m_decimator2;
c@280 123 float *m_buffer;
c@280 124 float *m_decbuf;
c@279 125 size_t m_bufsiz;
c@279 126 size_t m_buffill;
c@279 127 size_t m_beatframesize;
c@279 128 double *m_beatframe;
c@289 129 FFTReal *m_fft;
c@279 130 double *m_fftRealOut;
c@279 131 double *m_fftImagOut;
c@281 132 d_vec_t m_beatsd;
c@279 133 };
c@279 134
c@279 135 #endif