summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio/synth.cc11
-rw-r--r--src/gpu/gpu.cc35
-rw-r--r--src/main.cc7
-rw-r--r--src/platform.cc16
4 files changed, 43 insertions, 26 deletions
diff --git a/src/audio/synth.cc b/src/audio/synth.cc
index 77a0d05..a4f3b7a 100644
--- a/src/audio/synth.cc
+++ b/src/audio/synth.cc
@@ -26,7 +26,8 @@ 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));
@@ -172,8 +173,8 @@ 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)));
}
}
@@ -187,4 +188,6 @@ 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;
+}
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index 79498e3..b87c47f 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -28,7 +28,8 @@ static WGPUBindGroup g_bind_group = nullptr;
static WGPUStringView label_view(const char *str) {
#ifndef STRIP_ALL
- if (!str) return {nullptr, 0};
+ if (!str)
+ return {nullptr, 0};
return {str, strlen(str)};
#else
(void)str;
@@ -37,7 +38,8 @@ static WGPUStringView label_view(const char *str) {
}
static WGPUStringView str_view(const char *str) {
- if (!str) return {nullptr, 0};
+ if (!str)
+ return {nullptr, 0};
return {str, strlen(str)};
}
@@ -142,10 +144,9 @@ 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);
@@ -157,10 +158,9 @@ 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);
@@ -259,17 +259,21 @@ void gpu_init(GLFWwindow *window) {
void gpu_draw(float audio_peak, float aspect_ratio) {
WGPUSurfaceTexture surface_texture;
wgpuSurfaceGetCurrentTexture(g_surface, &surface_texture);
- if (surface_texture.status != WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal &&
- surface_texture.status != WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal)
+ if (surface_texture.status !=
+ WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal &&
+ surface_texture.status !=
+ WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal)
return;
- WGPUTextureView view = wgpuTextureCreateView(surface_texture.texture, nullptr);
+ WGPUTextureView view =
+ wgpuTextureCreateView(surface_texture.texture, nullptr);
struct {
float audio_peak;
float aspect_ratio;
} uniforms = {audio_peak, aspect_ratio};
- wgpuQueueWriteBuffer(g_queue, g_uniform_buffer, 0, &uniforms, sizeof(uniforms));
+ wgpuQueueWriteBuffer(g_queue, g_uniform_buffer, 0, &uniforms,
+ sizeof(uniforms));
WGPUCommandEncoderDescriptor encoder_desc = {};
encoder_desc.label = label_view("Command Encoder");
@@ -308,4 +312,5 @@ void gpu_draw(float audio_peak, float aspect_ratio) {
wgpuTextureRelease(surface_texture.texture);
}
-void gpu_shutdown() {} \ No newline at end of file
+void gpu_shutdown() {
+} \ No newline at end of file
diff --git a/src/main.cc b/src/main.cc
index e46468f..31e1c58 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -49,7 +49,7 @@ int main(int argc, char **argv) {
audio_init();
generate_tone(g_spec_buffer_a, 440.0f); // A4
- generate_tone(g_spec_buffer_b, 0.0f); // A5
+ generate_tone(g_spec_buffer_b, 0.0f); // A5
const Spectrogram spec = {g_spec_buffer_a, g_spec_buffer_b, SPEC_FRAMES};
int tone_id = synth_register_spectrogram(&spec);
@@ -71,10 +71,11 @@ int main(int argc, char **argv) {
// Time to update the sound!
float *back_buffer = synth_begin_update(tone_id);
if (back_buffer) {
- generate_tone(back_buffer, (beat_count % 8) == 4 ? 220.0f : 480.f); // A3
+ generate_tone(back_buffer,
+ (beat_count % 8) == 4 ? 220.0f : 480.f); // A3
synth_commit_update(tone_id);
}
- }
+ }
}
int width, height;
diff --git a/src/platform.cc b/src/platform.cc
index b0ec86b..2b6af44 100644
--- a/src/platform.cc
+++ b/src/platform.cc
@@ -42,9 +42,13 @@ void platform_shutdown() {
glfwTerminate();
}
-void platform_poll() { glfwPollEvents(); }
+void platform_poll() {
+ glfwPollEvents();
+}
-bool platform_should_close() { return glfwWindowShouldClose(window); }
+bool platform_should_close() {
+ return glfwWindowShouldClose(window);
+}
void platform_toggle_fullscreen() {
g_is_fullscreen = !g_is_fullscreen;
@@ -62,9 +66,13 @@ void platform_toggle_fullscreen() {
}
}
-GLFWwindow *platform_get_window() { return window; }
+GLFWwindow *platform_get_window() {
+ return window;
+}
-double platform_get_time() { return glfwGetTime(); }
+double platform_get_time() {
+ return glfwGetTime();
+}
WGPUSurface platform_create_wgpu_surface(WGPUInstance instance) {
return glfwCreateWindowWGPUSurface(instance, window);