diff --git a/src/test.cpp b/src/test.cpp new file mode 100644 index 0000000..bfc6d37 --- /dev/null +++ b/src/test.cpp @@ -0,0 +1,78 @@ +#include +#include +#include + +// For reading FIFO +#include +#include +// Math libs +#include +#include + +// Local files +#include "utility/bitmap.hpp" +#include "utility/buffer.hpp" +#include "signal_processing/fft.hpp" + + +// TODO: +// stereo support (and maybe different bitrates?) +// Optimization: don't copy filename in buffer? +// understand consumption rate +// understand BIN2HZ +// understand values and sizes (DFT_TOTAL, DFT_NONZERO, etc) +// note that wave and spectrum have different sizes +// +// MPD interface +// hid interface to keyboard +// beat detection + + + + +void draw_spectrum_bitmap( + const std::vector& waveform, + Bitmap& bitmap +) { + for (size_t x = 0; x < waveform.size(); x++) { + for (size_t y = 0; y < waveform[x]; y++) { + bitmap.setpixel(bitmap.get_height() - y - 1, x, 0xFF, 0x00, 0x00); + } + } +} + +const size_t width = 300; +const size_t height = 100; + + +int main(int argc, char *argv[]) { + + // buffer size for waveform: + // (44100 / fps * 10), make 10 bigger for slower scrolling + // + // Double both buffer sizes if stereo + + FFT_Visualizer fft = FFT_Visualizer( + width, height, + 20, 20000 + ); + + std::vector waveform; + waveform.resize(width); + + Buffer buf = Buffer( + "/tmp/mpd.fifo", + 44100 / 2, // Keep 500ms of data in buffer + fft.compute_buffer_output_size() + ); + + Bitmap b = Bitmap(width, height); + + while (1) { + b.clear(); + buf.update(); + fft.update(buf); + draw_spectrum_bitmap(fft.get_output(), b); + b.save("/tmp/o.bmp"); + } +} \ No newline at end of file