From b779be76eeb8fbd5b774a5a1de458de11f09faaf Mon Sep 17 00:00:00 2001 From: Matthew Bellew Date: Sat, 25 Jan 2020 17:26:40 -0800 Subject: [PATCH 1/4] attempt to improve freq responsiveness --- src/libprojectM/PCM.cpp | 84 +++++--- src/libprojectM/PCM.hpp | 9 +- src/libprojectM/Renderer/BeatDetect.cpp | 257 ++++++++++++------------ src/libprojectM/Renderer/BeatDetect.hpp | 39 +++- 4 files changed, 215 insertions(+), 174 deletions(-) diff --git a/src/libprojectM/PCM.cpp b/src/libprojectM/PCM.cpp index c88be2cc03..2ed8c2a2d8 100755 --- a/src/libprojectM/PCM.cpp +++ b/src/libprojectM/PCM.cpp @@ -74,11 +74,15 @@ void PCM::_initPCM(int samples) { start=0; //Allocate FFT workspace - w= (double *)wipemalloc(maxsamples*sizeof(double)); - ip= (int *)wipemalloc(maxsamples*sizeof(int)); + // per rdft() documentation + // length of ip >= 2+sqrt(n) and length of w == n/2 +#if FFT_LENGTH > 1024 +#error update this code +#endif + w = (double *)wipemalloc(FFT_LENGTH/2*sizeof(double)); + ip = (int *)wipemalloc(34 * sizeof(int)); ip[0]=0; - /** PCM data */ // this->maxsamples = 2048; // this->numsamples = 0; @@ -134,8 +138,8 @@ void PCM::addPCMfloat(const float *PCMdata, int samples) if (newsamples>maxsamples) newsamples=maxsamples; numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); - getPCM(vdataL,512,0,1,0,0); - getPCM(vdataR,512,1,1,0,0); + getPCM(vdataL,FFT_LENGTH,0,1,0,0); + getPCM(vdataR,FFT_LENGTH,1,1,0,0); } @@ -158,8 +162,8 @@ void PCM::addPCMfloat_2ch(const float *PCMdata, int samples) newsamples=maxsamples; numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); - getPCM(vdataL,512,0,1,0,0); - getPCM(vdataR,512,1,1,0,0); + getPCM(vdataL,FFT_LENGTH,0,1,0,0); + getPCM(vdataR,FFT_LENGTH,1,1,0,0); } @@ -178,8 +182,8 @@ void PCM::addPCM16Data(const short* pcm_data, short samples) { if (newsamples>maxsamples) newsamples=maxsamples; numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); - getPCM(vdataL,512,0,1,0,0); - getPCM(vdataR,512,1,1,0,0); + getPCM(vdataL,FFT_LENGTH,0,1,0,0); + getPCM(vdataR,FFT_LENGTH,1,1,0,0); } @@ -210,8 +214,8 @@ void PCM::addPCM16(short PCMdata[2][512]) numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); - getPCM(vdataL,512,0,1,0,0); - getPCM(vdataR,512,1,1,0,0); + getPCM(vdataL,FFT_LENGTH,0,1,0,0); + getPCM(vdataR,FFT_LENGTH,1,1,0,0); } @@ -243,8 +247,8 @@ void PCM::addPCM8( unsigned char PCMdata[2][1024]) if (newsamples>maxsamples) newsamples=maxsamples; numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); - getPCM(vdataL,512,0,1,0,0); - getPCM(vdataR,512,1,1,0,0); + getPCM(vdataL,FFT_LENGTH,0,1,0,0); + getPCM(vdataR,FFT_LENGTH,1,1,0,0); } void PCM::addPCM8_512( const unsigned char PCMdata[2][512]) @@ -275,8 +279,8 @@ void PCM::addPCM8_512( const unsigned char PCMdata[2][512]) if (newsamples>maxsamples) newsamples=maxsamples; numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); - getPCM(vdataL,512,0,1,0,0); - getPCM(vdataR,512,1,1,0,0); + getPCM(vdataL,FFT_LENGTH,0,1,0,0); + getPCM(vdataR,FFT_LENGTH,1,1,0,0); } @@ -291,43 +295,57 @@ void PCM::addPCM8_512( const unsigned char PCMdata[2][512]) void PCM::getPCM(float *PCMdata, int samples, int channel, int freq, float smoothing, int derive) { - int index; - - index=start-1; - - if (index<0) index=maxsamples+index; + if (smoothing == 0) + { + for (int i = 0; i < samples; i++) + { + int index = start - 1 - i; + if (index < 0) + index = maxsamples + index; + PCMdata[i] = PCMd[channel][index]; + } + } + else + { + int index=start-1; - PCMdata[0]=PCMd[channel][index]; + if (index<0) + index=maxsamples+index; - for(int i=1;i #include "BeatDetect.hpp" -BeatDetect::BeatDetect(PCM *_pcm) { - int x,y; - this->pcm=_pcm; +BeatDetect::BeatDetect(PCM *_pcm) +{ + this->pcm=_pcm; - this->vol_instant=0; - this->vol_history=0; + this->vol_instant=0; + this->vol_history=0; + for (unsigned y=0;y<80;y++) + this->vol_buffer[y]=0; - for (y=0;y<80;y++) - { - this->vol_buffer[y]=0; - } + this->beat_buffer_pos=0; - this->beat_buffer_pos=0; - - for (x=0;x<32;x++) { - this->beat_instant[x]=0; - this->beat_history[x]=0; - this->beat_val[x]=1.0; - this->beat_att[x]=1.0; - this->beat_variance[x]=0; - for (y=0;y<80;y++) { - this->beat_buffer[x][y]=0; - } - } + this->bass_instant = 0; + this->bass_history = 0; + for (unsigned y=0;y<80;y++) + this->bass_buffer[y]=0; + + this->mid_instant = 0; + this->mid_history = 0; + for (unsigned y=0;y<80;y++) + this->mid_buffer[y]=0; + + this->treb_instant = 0; + this->treb_history = 0; + for (unsigned y=0;y<80;y++) + this->treb_buffer[y]=0; this->treb = 0; this->mid = 0; @@ -72,119 +73,119 @@ BeatDetect::BeatDetect(PCM *_pcm) { this->bass_att = 0; this->vol_att = 0; this->vol = 0; - - - } +} + -BeatDetect::~BeatDetect() +BeatDetect::~BeatDetect() { } -void BeatDetect::reset() { - this->treb = 0; - this->mid = 0; - this->bass = 0; - this->treb_att = 0; - this->mid_att = 0; - this->bass_att = 0; - this->vol_att = 0; - } - -void BeatDetect::detectFromSamples() { + +void BeatDetect::reset() +{ + this->treb = 0; + this->mid = 0; + this->bass = 0; + this->treb_att = 0; + this->mid_att = 0; + this->bass_att = 0; + this->vol_att = 0; + this->vol_old = 0; + this->vol_instant=0; +} + + +void BeatDetect::detectFromSamples() +{ vol_old = vol; - bass=0;mid=0;treb=0; - - getBeatVals(pcm->pcmdataL,pcm->pcmdataR); - } - -void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { - - int linear=0; - int x,y; - float temp2=0; - - vol_instant=0; - for ( x=0;x<16;x++) - { - - beat_instant[x]=0; - for ( y=linear*2;y<(linear+8+x)*2;y++) - { - beat_instant[x]+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/(8+x)); -// printf( "beat_instant[%d]: %f %f %f\n", x, beat_instant[x], vdataL[y], vdataR[y] ); - vol_instant+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/512.0); - - } -//printf("1"); - linear=y/2; - beat_history[x]-=(beat_buffer[x][beat_buffer_pos])*.0125; - beat_buffer[x][beat_buffer_pos]=beat_instant[x]; - beat_history[x]+=(beat_instant[x])*.0125; - - beat_val[x]=(beat_instant[x])/(beat_history[x]); - - beat_att[x]+=(beat_instant[x])/(beat_history[x]); - -//printf("2\n"); - - } -//printf("b\n"); - vol_history-=(vol_buffer[beat_buffer_pos])*.0125; - vol_buffer[beat_buffer_pos]=vol_instant; - vol_history+=(vol_instant)*.0125; - - mid=0; - for(x=1;x<10;x++) - { - mid+=(beat_instant[x]); - temp2+=(beat_history[x]); - - } - - mid=mid/(1.5*temp2); - temp2=0; - treb=0; - for(x=10;x<16;x++) - { - treb+=(beat_instant[x]); - temp2+=(beat_history[x]); - } -//printf("c\n"); - treb=treb/(1.5*temp2); -// *vol=vol_instant/(1.5*vol_history); - vol=vol_instant/(1.5*vol_history); - - bass=(beat_instant[0])/(1.5*beat_history[0]); - - - if ( projectM_isnan( treb ) ) { - treb = 0.0; - } - if ( projectM_isnan( mid ) ) { - mid = 0.0; - } - if ( projectM_isnan( bass ) ) { - bass = 0.0; - } - treb_att=.6 * treb_att + .4 * treb; - mid_att=.6 * mid_att + .4 * mid; - bass_att=.6 * bass_att + .4 * bass; - vol_att=.6 * vol_att + .4 * vol; - - if(bass_att>100)bass_att=100; - if(bass >100)bass=100; - if(mid_att>100)mid_att=100; - if(mid >100)mid=100; - if(treb_att>100)treb_att=100; - if(treb >100)treb=100; - if(vol_att>100)vol_att=100; - if(vol>100)vol=100; - - // *vol=(beat_instant[3])/(beat_history[3]); - beat_buffer_pos++; - if( beat_buffer_pos>79)beat_buffer_pos=0; - + bass=0; + mid=0; + treb=0; + vol=0; + + // TODO: get sample rate from PCM? Assume 44100 + getBeatVals(44100.0f, FFT_LENGTH, pcm->pcmdataL, pcm->pcmdataR); +} + + +void BeatDetect::getBeatVals( float samplerate, unsigned fft_length, float *vdataL, float *vdataR ) +{ + assert( 512==fft_length || 1024==fft_length ); // should be power of 2, expect >= 512 + + // TODO: compute ranges based on samplerate + unsigned ranges512[4] = {0, 3, 23, 200}; + unsigned ranges1024[4] = {0, 5, 46, 400}; + unsigned *ranges = fft_length==1024 ? ranges1024 : ranges512; + + bass_instant = 0; + for (unsigned i=ranges[0]+1 ; i<=ranges[1] ; i++) + { + bass_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]); + } + bass_instant *= 100.0/(ranges[1]-ranges[0]); + bass_history -= bass_buffer[beat_buffer_pos] *.0125; + bass_buffer[beat_buffer_pos] = bass_instant; + bass_history += bass_instant *.0125; + + mid_instant = 0; + for (unsigned i=ranges[1]+1 ; i<=ranges[2] ; i++) + { + mid_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]); + } + mid_instant *= 100.0/(ranges[2]-ranges[1]); + mid_history -= mid_buffer[beat_buffer_pos] *.0125; + mid_buffer[beat_buffer_pos] = mid_instant; + mid_history += mid_instant *.0125; + + treb_instant = 0; + for (unsigned i=ranges[2]+1 ; i<=ranges[3] ; i++) + { + treb_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]); + } + treb_instant *= 90.0/(ranges[3]-ranges[2]); + treb_history -= treb_buffer[beat_buffer_pos] *.0125; + treb_buffer[beat_buffer_pos] = treb_instant; + treb_history += treb_instant *.0125; + + vol_instant = (bass_instant + mid_instant + treb_instant) / 3.0f; + vol_history -= (vol_buffer[beat_buffer_pos])*.0125; + vol_buffer[beat_buffer_pos] = vol_instant; + vol_history += (vol_instant)*.0125; + +// fprintf(stderr, "%6.3f %6.2f %6.3f\n", bass_history/vol_history, mid_history/vol_history, treb_history/vol_history); + bass = bass_instant / fmax(0.0001, bass_history + 0.5*vol_history); + mid = mid_instant / fmax(0.0001, mid_history + 0.5*vol_history); + treb = treb_instant / fmax(0.0001, treb_history + 0.5*vol_history); + vol = vol_instant / fmax(0.0001, 1.5f * vol_history); + + if ( projectM_isnan( treb ) ) { + treb = 0.0; + } + if ( projectM_isnan( mid ) ) { + mid = 0.0; + } + if ( projectM_isnan( bass ) ) { + bass = 0.0; + } + + treb_att = .6f * treb_att + .4f * treb; + mid_att = .6f * mid_att + .4f * mid; + bass_att = .6f * bass_att + .4f * bass; + vol_att = .6f * vol_att + .4f * vol; + + if (bass_att>100) bass_att=100; + if (bass >100) bass=100; + if (mid_att>100) mid_att=100; + if (mid >100) mid=100; + if (treb_att>100) treb_att=100; + if (treb >100) treb=100; + if (vol_att>100) vol_att=100; + if (vol>100) vol=100; + + beat_buffer_pos++; + if (beat_buffer_pos>79) + beat_buffer_pos=0; } diff --git a/src/libprojectM/Renderer/BeatDetect.hpp b/src/libprojectM/Renderer/BeatDetect.hpp index 99c8e7e86c..d023589399 100755 --- a/src/libprojectM/Renderer/BeatDetect.hpp +++ b/src/libprojectM/Renderer/BeatDetect.hpp @@ -59,7 +59,7 @@ class DLLEXPORT BeatDetect void initBeatDetect(); void reset(); void detectFromSamples(); - void getBeatVals ( float *vdataL, float *vdataR ); + void getBeatVals( float samplerate, unsigned fft_length, float *vdataL, float *vdataR ); float getPCMScale() { // added to address https://github.com/projectM-visualizer/projectm/issues/161 @@ -74,17 +74,34 @@ class DLLEXPORT BeatDetect } private: - /** Vars */ - float beat_buffer[32][80], - beat_instant[32], - beat_history[32]; - float beat_val[32], - beat_att[32], - beat_variance[32]; int beat_buffer_pos; - float vol_buffer[80], - vol_instant; - float vol_history; + float bass_buffer[80]; + float bass_history; + float bass_instant; + + float mid_buffer[80]; + float mid_history; + float mid_instant; + + float treb_buffer[80]; + float treb_history; + float treb_instant; + + float vol_buffer[80]; + float vol_history; + float vol_instant; + + // /** Vars */ +// float beat_buffer[32][80], +// beat_instant[32], +// beat_history[32]; +// float beat_val[32], +// beat_att[32], +// beat_variance[32]; +// int beat_buffer_pos; +// float vol_buffer[80], +// vol_instant; +// float vol_history; }; #endif /** !_BEAT_DETECT_H */ From 197b2f2736909dd2a54fb29fcc05a01598a32d27 Mon Sep 17 00:00:00 2001 From: Matthew Bellew Date: Sun, 26 Jan 2020 10:20:16 -0800 Subject: [PATCH 2/4] fix getPCMScale() to match getBeatVals() --- src/libprojectM/Renderer/BeatDetect.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libprojectM/Renderer/BeatDetect.hpp b/src/libprojectM/Renderer/BeatDetect.hpp index d023589399..00f953c178 100755 --- a/src/libprojectM/Renderer/BeatDetect.hpp +++ b/src/libprojectM/Renderer/BeatDetect.hpp @@ -70,7 +70,7 @@ class DLLEXPORT BeatDetect #undef max //work0around #endif /** WIN32 */ - return 0.5f / std::max(0.0001f,sqrtf(vol_history)); + return 4.0f / std::max(0.0001f,sqrtf(vol_history)); } private: From 0eec9ed694b04da008e2fac26a1dd9b6b93c38ac Mon Sep 17 00:00:00 2001 From: Matthew Bellew Date: Sun, 26 Jan 2020 17:31:06 -0800 Subject: [PATCH 3/4] comments on frequency ranges --- src/libprojectM/Renderer/BeatDetect.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libprojectM/Renderer/BeatDetect.cpp b/src/libprojectM/Renderer/BeatDetect.cpp index ff56e9357a..b3c750171c 100755 --- a/src/libprojectM/Renderer/BeatDetect.cpp +++ b/src/libprojectM/Renderer/BeatDetect.cpp @@ -114,8 +114,9 @@ void BeatDetect::getBeatVals( float samplerate, unsigned fft_length, float *vdat assert( 512==fft_length || 1024==fft_length ); // should be power of 2, expect >= 512 // TODO: compute ranges based on samplerate - unsigned ranges512[4] = {0, 3, 23, 200}; - unsigned ranges1024[4] = {0, 5, 46, 400}; + // roughly aiming or basee-mid cutoff of 220ish and mid-treb cutoff of 2000ish, if I did my math right + unsigned ranges512[4] = {0, 3 /* 3*441000/512 = =258 */, 23 /* 23*441000/512 = =1981 */ , 200}; + unsigned ranges1024[4] = {0, 5 /* 5*44100/1024 == 215 */, 46 /* 46*44100/1024 == 1981 */, 400}; unsigned *ranges = fft_length==1024 ? ranges1024 : ranges512; bass_instant = 0; From 5fd9bc13ecf091009af7e0a2a2a590546e0a360f Mon Sep 17 00:00:00 2001 From: Matthew Bellew Date: Sat, 1 Feb 2020 12:47:18 -0800 Subject: [PATCH 4/4] some feedback improvements --- src/libprojectM/PCM.hpp | 2 +- src/libprojectM/Renderer/BeatDetect.cpp | 30 ++++++++++---------- src/libprojectM/Renderer/BeatDetect.hpp | 37 +++++++++++-------------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/libprojectM/PCM.hpp b/src/libprojectM/PCM.hpp index cc8e176396..916da0bfa5 100755 --- a/src/libprojectM/PCM.hpp +++ b/src/libprojectM/PCM.hpp @@ -33,7 +33,7 @@ // 1024 is more computationally intensive, but maybe better at detecting lower bass -#define FFT_LENGTH 512 +#define FFT_LENGTH 1024 class diff --git a/src/libprojectM/Renderer/BeatDetect.cpp b/src/libprojectM/Renderer/BeatDetect.cpp index b3c750171c..a8a51b55f6 100755 --- a/src/libprojectM/Renderer/BeatDetect.cpp +++ b/src/libprojectM/Renderer/BeatDetect.cpp @@ -43,24 +43,24 @@ BeatDetect::BeatDetect(PCM *_pcm) this->vol_instant=0; this->vol_history=0; - for (unsigned y=0;y<80;y++) + for (unsigned y=0;yvol_buffer[y]=0; this->beat_buffer_pos=0; this->bass_instant = 0; this->bass_history = 0; - for (unsigned y=0;y<80;y++) + for (unsigned y=0;ybass_buffer[y]=0; this->mid_instant = 0; this->mid_history = 0; - for (unsigned y=0;y<80;y++) + for (unsigned y=0;ymid_buffer[y]=0; this->treb_instant = 0; this->treb_history = 0; - for (unsigned y=0;y<80;y++) + for (unsigned y=0;ytreb_buffer[y]=0; this->treb = 0; @@ -125,9 +125,9 @@ void BeatDetect::getBeatVals( float samplerate, unsigned fft_length, float *vdat bass_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]); } bass_instant *= 100.0/(ranges[1]-ranges[0]); - bass_history -= bass_buffer[beat_buffer_pos] *.0125; + bass_history -= bass_buffer[beat_buffer_pos] * (1.0/BEAT_HISTORY_LENGTH); bass_buffer[beat_buffer_pos] = bass_instant; - bass_history += bass_instant *.0125; + bass_history += bass_instant * (1.0/BEAT_HISTORY_LENGTH); mid_instant = 0; for (unsigned i=ranges[1]+1 ; i<=ranges[2] ; i++) @@ -135,9 +135,9 @@ void BeatDetect::getBeatVals( float samplerate, unsigned fft_length, float *vdat mid_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]); } mid_instant *= 100.0/(ranges[2]-ranges[1]); - mid_history -= mid_buffer[beat_buffer_pos] *.0125; + mid_history -= mid_buffer[beat_buffer_pos] * (1.0/BEAT_HISTORY_LENGTH); mid_buffer[beat_buffer_pos] = mid_instant; - mid_history += mid_instant *.0125; + mid_history += mid_instant * (1.0/BEAT_HISTORY_LENGTH); treb_instant = 0; for (unsigned i=ranges[2]+1 ; i<=ranges[3] ; i++) @@ -145,19 +145,19 @@ void BeatDetect::getBeatVals( float samplerate, unsigned fft_length, float *vdat treb_instant += (vdataL[i*2]*vdataL[i*2]) + (vdataR[i*2]*vdataR[i*2]); } treb_instant *= 90.0/(ranges[3]-ranges[2]); - treb_history -= treb_buffer[beat_buffer_pos] *.0125; + treb_history -= treb_buffer[beat_buffer_pos] * (1.0/BEAT_HISTORY_LENGTH); treb_buffer[beat_buffer_pos] = treb_instant; - treb_history += treb_instant *.0125; + treb_history += treb_instant * (1.0/BEAT_HISTORY_LENGTH); vol_instant = (bass_instant + mid_instant + treb_instant) / 3.0f; - vol_history -= (vol_buffer[beat_buffer_pos])*.0125; + vol_history -= (vol_buffer[beat_buffer_pos])* (1.0/BEAT_HISTORY_LENGTH); vol_buffer[beat_buffer_pos] = vol_instant; - vol_history += (vol_instant)*.0125; + vol_history += vol_instant * (1.0/BEAT_HISTORY_LENGTH); // fprintf(stderr, "%6.3f %6.2f %6.3f\n", bass_history/vol_history, mid_history/vol_history, treb_history/vol_history); - bass = bass_instant / fmax(0.0001, bass_history + 0.5*vol_history); - mid = mid_instant / fmax(0.0001, mid_history + 0.5*vol_history); - treb = treb_instant / fmax(0.0001, treb_history + 0.5*vol_history); + bass = bass_instant / fmax(0.0001, 1.3 * bass_history + 0.2*vol_history); + mid = mid_instant / fmax(0.0001, 1.3 * mid_history + 0.2*vol_history); + treb = treb_instant / fmax(0.0001, 1.3 * treb_history + 0.2*vol_history); vol = vol_instant / fmax(0.0001, 1.5f * vol_history); if ( projectM_isnan( treb ) ) { diff --git a/src/libprojectM/Renderer/BeatDetect.hpp b/src/libprojectM/Renderer/BeatDetect.hpp index 00f953c178..6538642673 100755 --- a/src/libprojectM/Renderer/BeatDetect.hpp +++ b/src/libprojectM/Renderer/BeatDetect.hpp @@ -37,6 +37,10 @@ #include +// this is the size of the buffer used to determine avg levels of the input audio +// the actual time represented in the history depends on FPS +#define BEAT_HISTORY_LENGTH 80 + class DLLEXPORT BeatDetect { public: @@ -54,17 +58,20 @@ class DLLEXPORT BeatDetect PCM *pcm; /** Methods */ - BeatDetect(PCM *pcm); + explicit BeatDetect(PCM *pcm); ~BeatDetect(); - void initBeatDetect(); void reset(); void detectFromSamples(); void getBeatVals( float samplerate, unsigned fft_length, float *vdataL, float *vdataR ); + + // getPCMScale() was added to address https://github.com/projectM-visualizer/projectm/issues/161 + // Returning 1.0 results in using the raw PCM data, which can make the presets look pretty unresponsive + // if the application volume is low. float getPCMScale() { - // added to address https://github.com/projectM-visualizer/projectm/issues/161 - // Returning 1.0 results in using the raw PCM data, which can make the presets look pretty unresponsive - // if the application volume is low. + // the constant here just depends on the particulars of getBeatVals(), the + // range of vol_history, and what "looks right". + // larger value means larger, more jagged waveform. #ifdef WIN32 // this is broken? #undef max @@ -75,33 +82,21 @@ class DLLEXPORT BeatDetect private: int beat_buffer_pos; - float bass_buffer[80]; + float bass_buffer[BEAT_HISTORY_LENGTH]; float bass_history; float bass_instant; - float mid_buffer[80]; + float mid_buffer[BEAT_HISTORY_LENGTH]; float mid_history; float mid_instant; - float treb_buffer[80]; + float treb_buffer[BEAT_HISTORY_LENGTH]; float treb_history; float treb_instant; - float vol_buffer[80]; + float vol_buffer[BEAT_HISTORY_LENGTH]; float vol_history; float vol_instant; - - // /** Vars */ -// float beat_buffer[32][80], -// beat_instant[32], -// beat_history[32]; -// float beat_val[32], -// beat_att[32], -// beat_variance[32]; -// int beat_buffer_pos; -// float vol_buffer[80], -// vol_instant; -// float vol_history; }; #endif /** !_BEAT_DETECT_H */