summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/audio/synth.cc19
-rw-r--r--src/gpu/gpu.cc50
-rw-r--r--src/gpu/gpu.h4
-rw-r--r--src/main.cc11
4 files changed, 43 insertions, 41 deletions
diff --git a/src/audio/synth.cc b/src/audio/synth.cc
index 2242d5c..e4f6c75 100644
--- a/src/audio/synth.cc
+++ b/src/audio/synth.cc
@@ -9,9 +9,6 @@
#include <math.h>
#include <string.h> // For memset
-// Declarations for DCT functions (could also be in dct.h)
-void idct_512(const float *input, float *output);
-
struct Voice {
bool active;
int spectrogram_id;
@@ -35,8 +32,7 @@ static struct {
} g_synth_data;
static Voice g_voices[MAX_VOICES];
-static volatile float g_current_output_peak =
- 0.0f; // Global peak for visualization
+static volatile float g_current_output_peak = 0.0f; // Global peak for visualization
void synth_init() {
memset(&g_synth_data, 0, sizeof(g_synth_data));
@@ -137,8 +133,8 @@ void synth_render(float *output_buffer, int num_frames) {
float window[WINDOW_SIZE];
hamming_window_512(window);
- // Apply a decay to the peak value for smooth visuals
- g_current_output_peak *= 0.95f;
+ // Faster decay for more responsive visuals
+ g_current_output_peak *= 0.90f;
for (int i = 0; i < num_frames; ++i) {
float left_sample = 0.0f;
@@ -184,8 +180,9 @@ void synth_render(float *output_buffer, int num_frames) {
output_buffer[i * 2 + 1] = right_sample;
// Update the peak with the new max (attack)
- g_current_output_peak = fmaxf(
- g_current_output_peak, fmaxf(fabsf(left_sample), fabsf(right_sample)));
+ g_current_output_peak =
+ fmaxf(g_current_output_peak,
+ fmaxf(fabsf(left_sample), fabsf(right_sample)));
}
}
@@ -199,6 +196,4 @@ int synth_get_active_voice_count() {
return count;
}
-float synth_get_output_peak() {
- return g_current_output_peak;
-}
+float synth_get_output_peak() { return g_current_output_peak; } \ No newline at end of file
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index 1f2c7f8..6e058bb 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -99,6 +99,7 @@ const char *shader_wgsl_code = R"(
struct Uniforms {
audio_peak : f32,
aspect_ratio: f32,
+ time: f32,
};
@group(0) @binding(0) var<uniform> uniforms : Uniforms;
@@ -108,8 +109,9 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4<
let PI = 3.14159265;
let num_sides = 7.0;
+ // Pulse scale based on audio peak
let base_scale = 0.5;
- let pulse_scale = 0.2 * uniforms.audio_peak;
+ let pulse_scale = 0.3 * uniforms.audio_peak;
let scale = base_scale + pulse_scale;
let tri_idx = f32(vertex_index / 3u);
@@ -119,8 +121,10 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4<
return vec4<f32>(0.0, 0.0, 0.0, 1.0);
}
+ // Apply rotation based on time
+ let rotation = uniforms.time * 0.5;
let i = tri_idx + f32(sub_idx - 1u);
- let angle = i * 2.0 * PI / num_sides;
+ let angle = i * 2.0 * PI / num_sides + rotation;
let x = scale * cos(angle) / uniforms.aspect_ratio;
let y = scale * sin(angle);
@@ -129,12 +133,15 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4<
@fragment
fn fs_main() -> @location(0) vec4<f32> {
- // More vibrant hue: shift through colors based on peak
- let h = uniforms.audio_peak * 2.0;
+ // Dynamic color shifting based on time and responsiveness to peak
+ let h = uniforms.time * 2.0 + uniforms.audio_peak * 3.0;
let r = sin(h + 0.0) * 0.5 + 0.5;
let g = sin(h + 2.0) * 0.5 + 0.5;
let b = sin(h + 4.0) * 0.5 + 0.5;
- return vec4<f32>(r, g, b, 1.0);
+
+ // Add brightness boost on peak
+ let boost = uniforms.audio_peak * 0.5;
+ return vec4<f32>(r + boost, g + boost, b + boost, 1.0);
}
)";
@@ -149,9 +156,10 @@ void gpu_init(GLFWwindow *window) {
adapter_opts.compatibleSurface = g_surface;
adapter_opts.powerPreference = WGPUPowerPreference_HighPerformance;
- wgpuInstanceRequestAdapter(g_instance, &adapter_opts,
- {nullptr, WGPUCallbackMode_WaitAnyOnly,
- handle_request_adapter, &g_adapter, nullptr});
+ wgpuInstanceRequestAdapter(
+ g_instance, &adapter_opts,
+ {nullptr, WGPUCallbackMode_WaitAnyOnly, handle_request_adapter, &g_adapter,
+ nullptr});
while (!g_adapter) {
wgpuInstanceWaitAny(g_instance, 0, nullptr, 0);
@@ -163,9 +171,10 @@ void gpu_init(GLFWwindow *window) {
device_desc.uncapturedErrorCallbackInfo.callback = handle_device_error;
#endif
- wgpuAdapterRequestDevice(g_adapter, &device_desc,
- {nullptr, WGPUCallbackMode_WaitAnyOnly,
- handle_request_device, &g_device, nullptr});
+ wgpuAdapterRequestDevice(
+ g_adapter, &device_desc,
+ {nullptr, WGPUCallbackMode_WaitAnyOnly, handle_request_device, &g_device,
+ nullptr});
while (!g_device) {
wgpuInstanceWaitAny(g_instance, 0, nullptr, 0);
@@ -191,14 +200,14 @@ void gpu_init(GLFWwindow *window) {
WGPUBufferDescriptor uniform_buffer_desc = {};
uniform_buffer_desc.label = label_view("Uniform Buffer");
uniform_buffer_desc.usage = WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst;
- uniform_buffer_desc.size = sizeof(float) * 2;
+ uniform_buffer_desc.size = sizeof(float) * 4; // Padding to 16 bytes
g_uniform_buffer = wgpuDeviceCreateBuffer(g_device, &uniform_buffer_desc);
WGPUBindGroupLayoutEntry bgl_entry = {};
bgl_entry.binding = 0;
bgl_entry.visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment;
bgl_entry.buffer.type = WGPUBufferBindingType_Uniform;
- bgl_entry.buffer.minBindingSize = sizeof(float) * 2;
+ bgl_entry.buffer.minBindingSize = sizeof(float) * 3;
WGPUBindGroupLayoutDescriptor bgl_desc = {};
bgl_desc.label = label_view("Uniform Bind Group Layout");
@@ -210,7 +219,7 @@ void gpu_init(GLFWwindow *window) {
WGPUBindGroupEntry bg_entry = {};
bg_entry.binding = 0;
bg_entry.buffer = g_uniform_buffer;
- bg_entry.size = sizeof(float) * 2;
+ bg_entry.size = sizeof(float) * 3;
WGPUBindGroupDescriptor bg_desc = {};
bg_desc.label = label_view("Uniform Bind Group");
@@ -261,7 +270,7 @@ void gpu_init(GLFWwindow *window) {
wgpuSurfaceConfigure(g_surface, &g_config);
}
-void gpu_draw(float audio_peak, float aspect_ratio) {
+void gpu_draw(float audio_peak, float aspect_ratio, float time) {
WGPUSurfaceTexture surface_texture;
wgpuSurfaceGetCurrentTexture(g_surface, &surface_texture);
if (surface_texture.status !=
@@ -276,7 +285,9 @@ void gpu_draw(float audio_peak, float aspect_ratio) {
struct {
float audio_peak;
float aspect_ratio;
- } uniforms = {audio_peak, aspect_ratio};
+ float time;
+ float padding;
+ } uniforms = {audio_peak, aspect_ratio, time, 0.0f};
wgpuQueueWriteBuffer(g_queue, g_uniform_buffer, 0, &uniforms,
sizeof(uniforms));
@@ -291,8 +302,8 @@ void gpu_draw(float audio_peak, float aspect_ratio) {
color_attachment.loadOp = WGPULoadOp_Clear;
color_attachment.storeOp = WGPUStoreOp_Store;
- // Background flash based on peak
- float flash = uniforms.audio_peak * 0.4f;
+ // Background flash effect
+ float flash = audio_peak * 0.6f;
color_attachment.clearValue = {0.05 + flash, 0.1 + flash, 0.2 + flash, 1.0};
color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
@@ -320,5 +331,4 @@ void gpu_draw(float audio_peak, float aspect_ratio) {
wgpuTextureRelease(surface_texture.texture);
}
-void gpu_shutdown() {
-}
+void gpu_shutdown() {} \ No newline at end of file
diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h
index 028b31b..00f5450 100644
--- a/src/gpu/gpu.h
+++ b/src/gpu/gpu.h
@@ -6,5 +6,5 @@
struct GLFWwindow;
void gpu_init(GLFWwindow *window);
-void gpu_draw(float audio_peak, float aspect_ratio);
-void gpu_shutdown(); \ No newline at end of file
+void gpu_draw(float audio_peak, float aspect_ratio, float time);
+void gpu_shutdown();
diff --git a/src/main.cc b/src/main.cc
index d564de0..5f74302 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -133,14 +133,11 @@ int main(int argc, char **argv) {
glfwGetFramebufferSize(platform_get_window(), &width, &height);
float aspect_ratio = (float)width / (float)height;
- // Stronger amplification for visuals
+ // Adjusted multiplier for visuals (preventing constant 1.0 saturation)
float raw_peak = synth_get_output_peak();
- float visual_peak = raw_peak * 150.0f;
-
- // Add a non-linear boost for loud peaks to make flashes pop
- if (visual_peak > 0.5f) visual_peak += (visual_peak - 0.5f) * 0.5f;
+ float visual_peak = fminf(raw_peak * 8.0f, 1.0f);
- gpu_draw(fminf(visual_peak, 1.0f), aspect_ratio);
+ gpu_draw(visual_peak, aspect_ratio, (float)current_time);
audio_update();
}
@@ -148,4 +145,4 @@ int main(int argc, char **argv) {
gpu_shutdown();
platform_shutdown();
return 0;
-}
+} \ No newline at end of file