RGB Sunglasses Animation Extension API fw-v3.8.1-1-geacf2f0
rgbx ABI + C++ wrapper for sandboxed .llext animations
Loading...
Searching...
No Matches
rgbx_audio_bars.h
Go to the documentation of this file.
1
43#ifndef RGBX_AUDIO_BARS_H
44#define RGBX_AUDIO_BARS_H
45
46#include <math.h>
47#include <rgbx/rgbx_api.h>
48#include <stddef.h>
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
55#define RGBX_AUDIO_BAR_FLOOR_DB (-36.0f)
56
59#define RGBX_AUDIO_BAR_RANGE_DB (36.0f)
60
63#define RGBX_AUDIO_BAR_TILT_DB_PER_OCTAVE (3.0f)
64
66#define RGBX_AUDIO_BAR_POWER_FLOOR (1e-9f)
67
76 0.0000f, 1.0995f, 1.5850f, 1.8931f, 2.1468f, 2.3626f, 2.6521f, 2.9206f, 3.1234f, 3.3424f,
77 3.5677f, 3.7318f, 3.8791f, 4.0000f, 4.0753f, 4.1584f, 4.2907f, 4.4500f, 4.5935f, 4.7240f};
78
84static inline float rgbx_audio_bar_power_db(float energy) {
85 /* `!(x > floor)` rather than `x <= floor`: NaN fails every comparison, so
86 * this one form catches zero, negative AND non-finite input. */
87 if (!(energy > RGBX_AUDIO_BAR_POWER_FLOOR)) {
89 }
90 /* 10*log10(x) = (10 / ln 10) * ln(x); logf is the allowed import. */
91 return 4.3429448f * logf(energy);
92}
93
104static inline float rgbx_audio_bar_height(float energy, size_t bucket, float floor_db,
105 float range_db, float tilt_db_per_octave) {
106 float tilt, range, h;
107 /* No signal, no bar — whatever the window. Without this the -90 dB log
108 * floor plus a large tilt and a low floor would draw a bar out of nothing. */
109 if (!(energy > 0.0f)) {
110 return 0.0f;
111 }
112 tilt = (bucket < RGBX_AUDIO_NUM_DISPLAY_BUCKETS)
113 ? tilt_db_per_octave * rgbx_audio_bar_octaves[bucket]
114 : 0.0f;
115 range = (range_db > 0.0f) ? range_db : 1.0f;
116 h = (rgbx_audio_bar_power_db(energy) + tilt - floor_db) / range;
117 if (!(h > 0.0f)) { /* also NaN, should any window value be non-finite */
118 return 0.0f;
119 }
120 if (h > 1.0f) {
121 return 1.0f;
122 }
123 return h;
124}
125
126#ifdef __cplusplus
127} /* extern "C" */
128#endif
129
130#endif /* RGBX_AUDIO_BARS_H */
SPDX-License-Identifier: MIT Copyright (c) 2026 Stuart Alldritt.
#define RGBX_AUDIO_NUM_DISPLAY_BUCKETS
Number of fine-grained audio display buckets (bar-graph style).
Definition rgbx_api.h:62
static float rgbx_audio_bar_height(float energy, size_t bucket, float floor_db, float range_db, float tilt_db_per_octave)
Bar-height fraction for one bucket under a dB window.
Definition rgbx_audio_bars.h:104
static float rgbx_audio_bar_power_db(float energy)
Bucket power to dB, floored at RGBX_AUDIO_BAR_POWER_FLOOR.
Definition rgbx_audio_bars.h:84
#define RGBX_AUDIO_BAR_POWER_FLOOR
Power below this reads as -90 dB, so a silent bucket stays finite.
Definition rgbx_audio_bars.h:66
static const float rgbx_audio_bar_octaves[RGBX_AUDIO_NUM_DISPLAY_BUCKETS]
log2(centre_b / centre_0) for each display bucket.
Definition rgbx_audio_bars.h:75