feat: new music visualizer
This commit is contained in:
@@ -5,23 +5,34 @@
|
||||
|
||||
namespace music_visualizer {
|
||||
|
||||
static constexpr int WAVE_HISTORY = 192;
|
||||
static constexpr int BAND_COUNT = 24;
|
||||
static constexpr int PROBE_COUNT = 3;
|
||||
static constexpr int ANALYSIS_SIZE = 512;
|
||||
|
||||
struct Probe {
|
||||
double coeff;
|
||||
double cosine;
|
||||
double sine;
|
||||
};
|
||||
|
||||
struct State {
|
||||
int16_t min_samples[WAVE_HISTORY];
|
||||
int16_t max_samples[WAVE_HISTORY];
|
||||
uint8_t energy[WAVE_HISTORY];
|
||||
int write_pos;
|
||||
int history_count;
|
||||
int accum_frames;
|
||||
int accum_abs_sum;
|
||||
int accum_min;
|
||||
int accum_max;
|
||||
uint8_t levels[BAND_COUNT];
|
||||
uint8_t peaks[BAND_COUNT];
|
||||
uint8_t peak_hold[BAND_COUNT];
|
||||
|
||||
int sample_rate;
|
||||
int ring_pos;
|
||||
int ring_fill;
|
||||
int samples_since_analyze;
|
||||
|
||||
int16_t ring[ANALYSIS_SIZE];
|
||||
double window[ANALYSIS_SIZE];
|
||||
Probe probes[BAND_COUNT][PROBE_COUNT];
|
||||
};
|
||||
|
||||
void reset(State& state);
|
||||
void tick(State& state);
|
||||
void feed_pcm(State& state, const int16_t* pcm, int frames, int channels);
|
||||
void feed_pcm(State& state, const int16_t* pcm, int frames, int channels, int sample_rate);
|
||||
void render(uint32_t* pixels, int bw, int bh, const gui::Rect& rect,
|
||||
const State& state, gui::Color accent, gui::Color accent_dark,
|
||||
gui::Color track_bg, gui::Color border);
|
||||
|
||||
Reference in New Issue
Block a user