From 18eb8a07ba39a8aad1c75521cee027b9c9c72e40 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 1 Feb 2026 00:58:20 +0100 Subject: clang-format --- src/main.cc | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'src/main.cc') diff --git a/src/main.cc b/src/main.cc index f63c803..8cedfce 100644 --- a/src/main.cc +++ b/src/main.cc @@ -28,11 +28,12 @@ struct SpecHeader { int register_spec_asset(AssetId id) { size_t size; - const uint8_t *data = GetAsset(id, &size); - if (!data || size < sizeof(SpecHeader)) return -1; + const uint8_t* data = GetAsset(id, &size); + if (!data || size < sizeof(SpecHeader)) + return -1; - const SpecHeader *header = (const SpecHeader *)data; - const float *spectral_data = (const float *)(data + sizeof(SpecHeader)); + const SpecHeader* header = (const SpecHeader*)data; + const float* spectral_data = (const float*)(data + sizeof(SpecHeader)); Spectrogram spec; spec.spectral_data_a = spectral_data; @@ -42,8 +43,8 @@ int register_spec_asset(AssetId id) { return synth_register_spectrogram(&spec); } -static float *g_spec_buffer_a[SPEC_FRAMES * DCT_SIZE] = {0}; -static float *g_spec_buffer_b[SPEC_FRAMES * DCT_SIZE] = {0}; +static float* g_spec_buffer_a[SPEC_FRAMES * DCT_SIZE] = {0}; +static float* g_spec_buffer_b[SPEC_FRAMES * DCT_SIZE] = {0}; // Global storage for the melody to ensure it persists std::vector g_melody_data; @@ -61,11 +62,13 @@ int generate_melody() { srand(12345); // Fixed seed for reproducibility for (int i = 0; i < 128; ++i) { - if (i % 4 == 0) continue; // Rest on beat 1 of every bar + if (i % 4 == 0) + continue; // Rest on beat 1 of every bar NoteParams params = {}; params.base_freq = notes[rand() % num_notes]; - if (rand() % 4 == 0) params.base_freq *= 2.0f; // Occasional octave up + if (rand() % 4 == 0) + params.base_freq *= 2.0f; // Occasional octave up params.duration_sec = (rand() % 2 == 0) ? 0.2f : 0.4f; params.amplitude = 0.4f; @@ -107,33 +110,35 @@ int generate_melody() { return synth_register_spectrogram(&spec); } -float *generate_tone(float *buffer, float freq) { +float* generate_tone(float* buffer, float freq) { if (buffer == nullptr) { - buffer = (float *)calloc(SPEC_FRAMES * DCT_SIZE, sizeof(float)); + buffer = (float*)calloc(SPEC_FRAMES * DCT_SIZE, sizeof(float)); } else { memset(buffer, 0, SPEC_FRAMES * DCT_SIZE * sizeof(float)); } for (int frame = 0; frame < SPEC_FRAMES; ++frame) { - float *spec_frame = buffer + frame * DCT_SIZE; + float* spec_frame = buffer + frame * DCT_SIZE; float amplitude = 1000. * powf(1.0f - (float)frame / SPEC_FRAMES, 2.0f); int bin = (int)(freq / (32000.0f / 2.0f) * DCT_SIZE); - if (bin > 0 && bin < DCT_SIZE) { spec_frame[bin] = amplitude; } + if (bin > 0 && bin < DCT_SIZE) { + spec_frame[bin] = amplitude; + } } return buffer; } -int main(int argc, char **argv) { +int main(int argc, char** argv) { bool fullscreen_enabled = false; double seek_time = 0.0; -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--fullscreen") == 0) { fullscreen_enabled = true; } else if (strcmp(argv[i], "--seek") == 0 && i + 1 < argc) { seek_time = atof(argv[i + 1]); - i++; + ++i; } } #else @@ -154,8 +159,8 @@ int main(int argc, char **argv) { int hihat_id = register_spec_asset(AssetId::ASSET_HIHAT_1); // Still keep the dynamic tone for bass - const float *g_spec_buffer_a = generate_tone(nullptr, 110.0f); // A2 - const float *g_spec_buffer_b = generate_tone(nullptr, 110.0f); + const float* g_spec_buffer_a = generate_tone(nullptr, 110.0f); // A2 + const float* g_spec_buffer_b = generate_tone(nullptr, 110.0f); const Spectrogram bass_spec = {g_spec_buffer_a, g_spec_buffer_b, SPEC_FRAMES}; int bass_id = synth_register_spectrogram(&bass_spec); @@ -183,11 +188,13 @@ int main(int argc, char **argv) { } // Hihat on every offbeat - if (step % 2 == 1) { synth_trigger_voice(hihat_id, 0.5f, 0.3f); } + if (step % 2 == 1) { + synth_trigger_voice(hihat_id, 0.5f, 0.3f); + } // Bass pattern if (step % 4 == 0) { - float *back_buffer = synth_begin_update(bass_id); + float* back_buffer = synth_begin_update(bass_id); if (back_buffer) { float bass_freq = (step < 8) ? 110.0f : 164.82f; // A3 then E3 generate_tone(back_buffer, bass_freq); @@ -200,7 +207,7 @@ int main(int argc, char **argv) { } }; -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) if (seek_time > 0.0) { printf("Seeking to %.2f seconds...\n", seek_time); @@ -215,7 +222,7 @@ int main(int argc, char **argv) { // Simulate Visuals gpu_simulate_until((float)seek_time); } -#endif +#endif /* !defined(STRIP_ALL) */ // Start real audio audio_start(); @@ -244,4 +251,4 @@ int main(int argc, char **argv) { gpu_shutdown(); platform_shutdown(); return 0; -} \ No newline at end of file +} -- cgit v1.2.3