Close

Playing with 8 bit - fix_fft

A project log for VU-meter Esp8266 - WS2812B

VU-meter (Winamp plugin ) sending udp to a Esp8266 controlling a Ws2812B

mr.jbmr.jb 02/22/2015 at 14:400 Comments

Here is a snippet on how to play with the fix_fft in winamp. The reason for this is, it gives a good idea if it's worth the effort to implement in the Esp8266 ( which I think it is ;-). It's just a quick & dirty hack... to get a feeling.

Current goal :

* Sample with Esp8266 ADC in approximate 10kHz

* 8 bit fix_fft: 16 fft bin is enough ( but I'll probably calculate more, or use a filter ;-)

* Predict beat

Track active frequencies with histogram - predict beat

This-Is-Your-Brain-On-Music

A different way to visualize rhythm - John Varney

Beat detection C++

Beatbots

* Make something fun..."synchronized party stuff"

Download Video as MP4

// http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=960&lngWId=3
// By: David Overton
// vis_spectrum.cpp

winampVisModule waModule = {
  ...
 1, // spectrumNch
 1, // waveformNch
 ...
};

char g_real[600];
char g_imag[600];

OnPluginRender  

int n=0;  

// Get a grip on which ADC rate would be necessary
// Divide 44100/4 = 11025 sample rate
for( int i=0; i<576; i+=4 /* play with sample rate 1-9 */)
{
    g_real[n]=mod->waveformData[0][i];
    ++n;
}

fix_fft(g_real, g_imag, 6/* 2^6 = number of FFT points */, 0); 

for (int i=0; i<32/* number of bins = FFT points/2 */; i++)
{
  // just a "scale factor" not much thought put into it.....
    g_real[i] = 8.6*( (sqrt((float)g_real[i] * (float)g_real[i] + (float)g_imag[i] * (float)g_imag[i])));

}


HBRUSH NewBrush  = CreateSolidBrush(RGB(255, 255, 255));
HBRUSH hbrushOld = (HBRUSH)SelectObject(Plugin.hMemDC, NewBrush);

int x=7;
int y;

/* just hard coded values without respect of actual size */
/* ignore the upper half of the spectrum */
for( int i=0; i<16/* number of bins to display*/; ++i )  
{   
    y=118-g_real[i];
    if( y<8 )
        y=8;
    Rectangle(Plugin.hMemDC, x, y, x+16, 118);
    x+=16; /* bar width*/
}


SelectObject(Plugin.hMemDC, hbrushOld);
DeleteObject (NewBrush) ;
 

.....  // Blit all to hDC

Discussions