Skip to content

Commit 5fd9bc1

Browse files
committed
some feedback improvements
1 parent 0eec9ed commit 5fd9bc1

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

src/libprojectM/PCM.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
// 1024 is more computationally intensive, but maybe better at detecting lower bass
36-
#define FFT_LENGTH 512
36+
#define FFT_LENGTH 1024
3737

3838

3939
class

src/libprojectM/Renderer/BeatDetect.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@ BeatDetect::BeatDetect(PCM *_pcm)
4343

4444
this->vol_instant=0;
4545
this->vol_history=0;
46-
for (unsigned y=0;y<80;y++)
46+
for (unsigned y=0;y<BEAT_HISTORY_LENGTH;y++)
4747
this->vol_buffer[y]=0;
4848

4949
this->beat_buffer_pos=0;
5050

5151
this->bass_instant = 0;
5252
this->bass_history = 0;
53-
for (unsigned y=0;y<80;y++)
53+
for (unsigned y=0;y<BEAT_HISTORY_LENGTH;y++)
5454
this->bass_buffer[y]=0;
5555

5656
this->mid_instant = 0;
5757
this->mid_history = 0;
58-
for (unsigned y=0;y<80;y++)
58+
for (unsigned y=0;y<BEAT_HISTORY_LENGTH;y++)
5959
this->mid_buffer[y]=0;
6060

6161
this->treb_instant = 0;
6262
this->treb_history = 0;
63-
for (unsigned y=0;y<80;y++)
63+
for (unsigned y=0;y<BEAT_HISTORY_LENGTH;y++)
6464
this->treb_buffer[y]=0;
6565

6666
this->treb = 0;
@@ -125,39 +125,39 @@ void BeatDetect::getBeatVals( float samplerate, unsigned fft_length, float *vdat
125125
bass_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]);
126126
}
127127
bass_instant *= 100.0/(ranges[1]-ranges[0]);
128-
bass_history -= bass_buffer[beat_buffer_pos] *.0125;
128+
bass_history -= bass_buffer[beat_buffer_pos] * (1.0/BEAT_HISTORY_LENGTH);
129129
bass_buffer[beat_buffer_pos] = bass_instant;
130-
bass_history += bass_instant *.0125;
130+
bass_history += bass_instant * (1.0/BEAT_HISTORY_LENGTH);
131131

132132
mid_instant = 0;
133133
for (unsigned i=ranges[1]+1 ; i<=ranges[2] ; i++)
134134
{
135135
mid_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]);
136136
}
137137
mid_instant *= 100.0/(ranges[2]-ranges[1]);
138-
mid_history -= mid_buffer[beat_buffer_pos] *.0125;
138+
mid_history -= mid_buffer[beat_buffer_pos] * (1.0/BEAT_HISTORY_LENGTH);
139139
mid_buffer[beat_buffer_pos] = mid_instant;
140-
mid_history += mid_instant *.0125;
140+
mid_history += mid_instant * (1.0/BEAT_HISTORY_LENGTH);
141141

142142
treb_instant = 0;
143143
for (unsigned i=ranges[2]+1 ; i<=ranges[3] ; i++)
144144
{
145145
treb_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]);
146146
}
147147
treb_instant *= 90.0/(ranges[3]-ranges[2]);
148-
treb_history -= treb_buffer[beat_buffer_pos] *.0125;
148+
treb_history -= treb_buffer[beat_buffer_pos] * (1.0/BEAT_HISTORY_LENGTH);
149149
treb_buffer[beat_buffer_pos] = treb_instant;
150-
treb_history += treb_instant *.0125;
150+
treb_history += treb_instant * (1.0/BEAT_HISTORY_LENGTH);
151151

152152
vol_instant = (bass_instant + mid_instant + treb_instant) / 3.0f;
153-
vol_history -= (vol_buffer[beat_buffer_pos])*.0125;
153+
vol_history -= (vol_buffer[beat_buffer_pos])* (1.0/BEAT_HISTORY_LENGTH);
154154
vol_buffer[beat_buffer_pos] = vol_instant;
155-
vol_history += (vol_instant)*.0125;
155+
vol_history += vol_instant * (1.0/BEAT_HISTORY_LENGTH);
156156

157157
// fprintf(stderr, "%6.3f %6.2f %6.3f\n", bass_history/vol_history, mid_history/vol_history, treb_history/vol_history);
158-
bass = bass_instant / fmax(0.0001, bass_history + 0.5*vol_history);
159-
mid = mid_instant / fmax(0.0001, mid_history + 0.5*vol_history);
160-
treb = treb_instant / fmax(0.0001, treb_history + 0.5*vol_history);
158+
bass = bass_instant / fmax(0.0001, 1.3 * bass_history + 0.2*vol_history);
159+
mid = mid_instant / fmax(0.0001, 1.3 * mid_history + 0.2*vol_history);
160+
treb = treb_instant / fmax(0.0001, 1.3 * treb_history + 0.2*vol_history);
161161
vol = vol_instant / fmax(0.0001, 1.5f * vol_history);
162162

163163
if ( projectM_isnan( treb ) ) {

src/libprojectM/Renderer/BeatDetect.hpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#include <cmath>
3838

3939

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+
4044
class DLLEXPORT BeatDetect
4145
{
4246
public:
@@ -54,17 +58,20 @@ class DLLEXPORT BeatDetect
5458
PCM *pcm;
5559

5660
/** Methods */
57-
BeatDetect(PCM *pcm);
61+
explicit BeatDetect(PCM *pcm);
5862
~BeatDetect();
59-
void initBeatDetect();
6063
void reset();
6164
void detectFromSamples();
6265
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.
6370
float getPCMScale()
6471
{
65-
// added to address https://github.com/projectM-visualizer/projectm/issues/161
66-
// Returning 1.0 results in using the raw PCM data, which can make the presets look pretty unresponsive
67-
// if the application volume is low.
72+
// the constant here just depends on the particulars of getBeatVals(), the
73+
// range of vol_history, and what "looks right".
74+
// larger value means larger, more jagged waveform.
6875
#ifdef WIN32
6976
// this is broken?
7077
#undef max
@@ -75,33 +82,21 @@ class DLLEXPORT BeatDetect
7582

7683
private:
7784
int beat_buffer_pos;
78-
float bass_buffer[80];
85+
float bass_buffer[BEAT_HISTORY_LENGTH];
7986
float bass_history;
8087
float bass_instant;
8188

82-
float mid_buffer[80];
89+
float mid_buffer[BEAT_HISTORY_LENGTH];
8390
float mid_history;
8491
float mid_instant;
8592

86-
float treb_buffer[80];
93+
float treb_buffer[BEAT_HISTORY_LENGTH];
8794
float treb_history;
8895
float treb_instant;
8996

90-
float vol_buffer[80];
97+
float vol_buffer[BEAT_HISTORY_LENGTH];
9198
float vol_history;
9299
float vol_instant;
93-
94-
// /** Vars */
95-
// float beat_buffer[32][80],
96-
// beat_instant[32],
97-
// beat_history[32];
98-
// float beat_val[32],
99-
// beat_att[32],
100-
// beat_variance[32];
101-
// int beat_buffer_pos;
102-
// float vol_buffer[80],
103-
// vol_instant;
104-
// float vol_history;
105100
};
106101

107102
#endif /** !_BEAT_DETECT_H */

0 commit comments

Comments
 (0)