1 /**
2  * projectM -- Milkdrop-esque visualisation SDK
3  * Copyright (C)2003-2007 projectM Team
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  * See 'LICENSE.txt' included within this release
19  *
20  */
21 /**
22  * $Id$
23  *
24  * Beat detection class. Takes decompressed sound buffers and returns
25  * various characteristics
26  *
27  * $Log$
28  *
29  */
30 
31 #ifndef _BEAT_DETECT_H
32 #define _BEAT_DETECT_H
33 
34 #include "../PCM.hpp"
35 #include "../dlldefs.h"
36 #include <algorithm>
37 #include <cmath>
38 
39 
40 // this is the size of the buffer used to determine avg levels of the input audio
41 // the actual time represented in the history depends on FPS
42 #define BEAT_HISTORY_LENGTH 80
43 
44 class DLLEXPORT BeatDetect
45 {
46 	public:
47 		float treb ;
48 		float mid ;
49 		float bass ;
50 		float vol_old ;
51 		float beatSensitivity;
52 		float treb_att ;
53 		float mid_att ;
54 		float bass_att ;
55 		float vol;
56         float vol_att ;
57 
58 		PCM *pcm;
59 
60 		/** Methods */
61 		explicit BeatDetect(PCM *pcm);
62 		~BeatDetect();
63 		void reset();
64 		void detectFromSamples();
65 		void getBeatVals( float samplerate, unsigned fft_length, float *vdataL, float *vdataR );
66 
67         // getPCMScale() was added to address https://github.com/projectM-visualizer/projectm/issues/161
68         // Returning 1.0 results in using the raw PCM data, which can make the presets look pretty unresponsive
69         // if the application volume is low.
70 		float getPCMScale();
71 
72 	private:
73 		int beat_buffer_pos;
74         float bass_buffer[BEAT_HISTORY_LENGTH];
75 		float bass_history;
76         float bass_instant;
77 
78 		float mid_buffer[BEAT_HISTORY_LENGTH];
79         float mid_history;
80 		float mid_instant;
81 
82 		float treb_buffer[BEAT_HISTORY_LENGTH];
83 		float treb_history;
84 		float treb_instant;
85 
86         float vol_buffer[BEAT_HISTORY_LENGTH];
87         float vol_history;
88         float vol_instant;
89 };
90 
91 #endif /** !_BEAT_DETECT_H */
92