Added test.cpp

master
Mark 2022-06-24 21:33:12 -07:00
parent 2332e2980a
commit 58fd2821b5
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 78 additions and 0 deletions

78
src/test.cpp Normal file
View File

@ -0,0 +1,78 @@
#include <stdio.h>
#include <cstdint>
#include <vector>
// For reading FIFO
#include <fcntl.h>
#include <unistd.h>
// Math libs
#include <math.h>
#include <fftw3.h>
// 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<size_t>& 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<size_t> 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");
}
}