DownBeat.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  QM DSP Library
5 
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2008-2009 Matthew Davies and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef QM_DSP_DOWNBEAT_H
17 #define QM_DSP_DOWNBEAT_H
18 
19 #include <vector>
20 #include <cstddef>
21 
23 
24 class FFTReal;
25 
36 class DownBeat
37 {
38 public:
49  DownBeat(float originalSampleRate,
50  size_t decimationFactor,
51  size_t dfIncrement);
52  ~DownBeat();
53 
54  void setBeatsPerBar(int bpb);
55 
70  void findDownBeats(const float *audio, // downsampled
71  size_t audioLength, // after downsampling
72  const std::vector<double> &beats,
73  std::vector<int> &downbeats);
74 
84  void getBeatSD(std::vector<double> &beatsd) const;
85 
95  void pushAudioBlock(const float *audio);
96 
100  const float *getBufferedAudio(size_t &length) const;
101 
105  void resetAudioBuffer();
106 
107 private:
108  typedef std::vector<int> i_vec_t;
109  typedef std::vector<std::vector<int> > i_mat_t;
110  typedef std::vector<double> d_vec_t;
111  typedef std::vector<std::vector<double> > d_mat_t;
112 
113  void makeDecimators();
114  double measureSpecDiff(d_vec_t oldspec, d_vec_t newspec);
115 
116  int m_bpb;
117  float m_rate;
118  size_t m_factor;
119  size_t m_increment;
122  float *m_buffer;
123  float *m_decbuf;
124  size_t m_bufsiz;
125  size_t m_buffill;
127  double *m_beatframe;
129  double *m_fftRealOut;
130  double *m_fftImagOut;
131  d_vec_t m_beatsd;
132 };
133 
134 #endif
double * m_fftRealOut
Definition: DownBeat.h:129
void getBeatSD(std::vector< double > &beatsd) const
Return the beat spectral difference function.
Definition: DownBeat.cpp:293
void findDownBeats(const float *audio, size_t audioLength, const std::vector< double > &beats, std::vector< int > &downbeats)
Estimate which beats are down-beats.
Definition: DownBeat.cpp:138
size_t m_bufsiz
Definition: DownBeat.h:124
size_t m_beatframesize
Definition: DownBeat.h:126
std::vector< int > i_vec_t
Definition: DownBeat.h:108
void pushAudioBlock(const float *audio)
For your downsampling convenience: call this function repeatedly with input audio blocks containing d...
Definition: DownBeat.cpp:91
DownBeat(float originalSampleRate, size_t decimationFactor, size_t dfIncrement)
Construct a downbeat locator that will operate on audio at the downsampled by the given decimation fa...
Definition: DownBeat.cpp:28
size_t m_factor
Definition: DownBeat.h:118
const float * getBufferedAudio(size_t &length) const
Retrieve the accumulated audio produced by pushAudioBlock calls.
Definition: DownBeat.cpp:120
std::vector< std::vector< double > > d_mat_t
Definition: DownBeat.h:111
float * m_decbuf
Definition: DownBeat.h:123
float * m_buffer
Definition: DownBeat.h:122
size_t m_buffill
Definition: DownBeat.h:125
double * m_fftImagOut
Definition: DownBeat.h:130
void makeDecimators()
Definition: DownBeat.cpp:77
Decimator * m_decimator2
Definition: DownBeat.h:121
double * m_beatframe
Definition: DownBeat.h:127
void resetAudioBuffer()
Clear any buffered downsampled audio data.
Definition: DownBeat.cpp:127
Definition: FFT.h:52
Decimator * m_decimator1
Definition: DownBeat.h:120
size_t m_increment
Definition: DownBeat.h:119
This class takes an input audio signal and a sequence of beat locations (calculated e...
Definition: DownBeat.h:36
std::vector< double > d_vec_t
Definition: DownBeat.h:110
int m_bpb
Definition: DownBeat.h:116
Decimator carries out a fast downsample by a power-of-two factor.
Definition: Decimator.h:24
void setBeatsPerBar(int bpb)
Definition: DownBeat.cpp:71
d_vec_t m_beatsd
Definition: DownBeat.h:131
FFTReal * m_fft
Definition: DownBeat.h:128
double measureSpecDiff(d_vec_t oldspec, d_vec_t newspec)
Definition: DownBeat.cpp:245
std::vector< std::vector< int > > i_mat_t
Definition: DownBeat.h:109
float m_rate
Definition: DownBeat.h:117
~DownBeat()
Definition: DownBeat.cpp:58