Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Correct Interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
cujomalainey committed Jan 29, 2017
1 parent e8ec0c2 commit f3027c7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,25 @@ class VolumeBars : public ThreadedCanvasManipulator {
while (running()) {
float fft[1024];
BASS_ChannelGetData(chan,fft,BASS_DATA_FFT2048); // get the FFT data
for (x=0;x<SPECWIDTH;x++) {
for (x=0;x<SPECWIDTH*2;x+=2) {
y=sqrt(fft[x+1])*3*SPECHEIGHT-4; // scale it (sqrt to make low values more visible)
if (y>SPECHEIGHT) y=SPECHEIGHT; // cap it
y2 = SPECHEIGHT + 1;
while (--y2>MAX(y,y1)) drawBarRow(x, y2, {0,0,0});
if (x && (y1=(y+y1)/2)) // interpolate from previous to make the display smoother
while (--y1>=0) drawBarRow(x, y1, palette[y1]);
y1 = (y1+y)/2;
while (--y2>y1) drawBarRow(x, y2, {0,0,0});
while (--y1>=0) drawBarRow(x, y1, palette[y1]);
y1=y;
while (--y>=0) drawBarRow(x, y, palette[y]); // draw level
y2 = SPECHEIGHT + 1;
while (--y2>y) drawBarRow(x+1, y2, {0,0,0});
while (--y>=0) drawBarRow(x+1, y, palette[y]); // draw level
}
usleep(refresh_rate * 1000);
}
}

private:
void drawBarRow(int bar, uint8_t y, RGB color) {
for (uint8_t x=bar*barWidth_; x<(bar+1)*barWidth_; ++x) {
canvas()->SetPixel(x, height_-1-y, color.rgbRed, color.rgbGreen, color.rgbBlue);
}
canvas()->SetPixel(bar, height_-1-y, color.rgbRed, color.rgbGreen, color.rgbBlue);
}

int delay_ms_;
Expand Down

0 comments on commit f3027c7

Please sign in to comment.