#include #include #include #include // For reading FIFO #include #include // Local files #include "utility/bitmap.hpp" #include "utility/buffer.hpp" #include "signal_processing/fft.hpp" #include "ergodox.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 = 12; const size_t height = 150; int main(int argc, char *argv[]) { uint8_t hid_buf[20]; Ergodox Dox = Ergodox::init( 0x3297, 0x4976, 0x61, 0xFF60 ); // 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, 100, 10000 ); std::vector waveform; waveform.resize(width); Buffer buf = Buffer( "/tmp/mpd.fifo", //"/home/mark/Workbench/sospi/pulse.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"); hid_buf[0] = 0x01; hid_buf[1] = 0x02; for (size_t i = 0; i < 10; i++) { ssize_t h = fft.get_output()[i + 1] - 10; h = h>100 ? 100 : h; h = h<0 ? 0 : h; hid_buf[i + 2] = h; } Dox.write(hid_buf, 12); } return 0; }