diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-05 22:55:56 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-05 22:55:56 +0100 |
| commit | 34afbd6ca21d2b960573d787e6eae46fa86b200e (patch) | |
| tree | 08450aeff4c67fb300428e705910265e6cd59943 | |
| parent | 35c9ebb0a7ce0e726f631a2b04bb26098926cfab (diff) | |
style: run clang-format to adhere to coding style
45 files changed, 184 insertions, 167 deletions
diff --git a/src/3d/renderer_draw.cc b/src/3d/renderer_draw.cc index f2d1323..8a08998 100644 --- a/src/3d/renderer_draw.cc +++ b/src/3d/renderer_draw.cc @@ -60,8 +60,7 @@ void Renderer3D::update_uniforms(const Scene& scene, const Camera& camera, float plane_distance = 0.0f; if (obj.type == ObjectType::PLANE && obj.shared_user_data) { // Safely cast shared_user_data to PlaneData* and get distance - plane_distance = - ((PlaneData*)(obj.shared_user_data.get()))->distance; + plane_distance = ((PlaneData*)(obj.shared_user_data.get()))->distance; } data.params = diff --git a/src/3d/renderer_pipelines.cc b/src/3d/renderer_pipelines.cc index 57e71ae..be4a317 100644 --- a/src/3d/renderer_pipelines.cc +++ b/src/3d/renderer_pipelines.cc @@ -17,8 +17,8 @@ void Renderer3D::create_pipeline() { WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { // Main SDF shader size_t size; - const char* shader_code = (const char*)( - GetAsset(AssetId::ASSET_SHADER_RENDERER_3D, &size)); + const char* shader_code = + (const char*)(GetAsset(AssetId::ASSET_SHADER_RENDERER_3D, &size)); // Compose the final shader by substituting the scene query implementation ShaderComposer::CompositionMap composition_map; @@ -134,8 +134,8 @@ WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { void Renderer3D::create_mesh_pipeline() { size_t size; - const char* shader_code = (const char*)( - GetAsset(AssetId::ASSET_SHADER_MESH, &size)); + const char* shader_code = + (const char*)(GetAsset(AssetId::ASSET_SHADER_MESH, &size)); ShaderComposer::CompositionMap composition_map; if (bvh_enabled_) { @@ -261,8 +261,8 @@ void Renderer3D::create_mesh_pipeline() { void Renderer3D::create_skybox_pipeline() { size_t size; - const char* shader_code = (const char*)( - GetAsset(AssetId::ASSET_SHADER_SKYBOX, &size)); + const char* shader_code = + (const char*)(GetAsset(AssetId::ASSET_SHADER_SKYBOX, &size)); std::string composed_shader = ShaderComposer::Get().Compose({}, std::string(shader_code, size)); diff --git a/src/3d/scene_loader.cc b/src/3d/scene_loader.cc index 1ff2cc2..eb20954 100644 --- a/src/3d/scene_loader.cc +++ b/src/3d/scene_loader.cc @@ -159,8 +159,7 @@ bool LoadScene(Scene& scene, const uint8_t* data, size_t size) { // Assign the plane distance // Safely cast void* to PlaneData* using C-style cast on the shared_ptr's // get() - ((PlaneData*)(obj.shared_user_data.get()))->distance = - plane_distance; + ((PlaneData*)(obj.shared_user_data.get()))->distance = plane_distance; } // Add to scene diff --git a/src/3d/sdf_cpu.h b/src/3d/sdf_cpu.h index e7f9f47..16776fb 100644 --- a/src/3d/sdf_cpu.h +++ b/src/3d/sdf_cpu.h @@ -44,9 +44,12 @@ inline float sdPlane(vec3 p, vec3 n, float h) { */ template <typename F> inline vec3 calc_normal(vec3 p, F sdf_func, float e = 0.001f) { - return vec3(sdf_func(vec3(p.x + e, p.y, p.z)) - sdf_func(vec3(p.x - e, p.y, p.z)), - sdf_func(vec3(p.x, p.y + e, p.z)) - sdf_func(vec3(p.x, p.y - e, p.z)), - sdf_func(vec3(p.x, p.y, p.z + e)) - sdf_func(vec3(p.x, p.y, p.z - e))) + return vec3(sdf_func(vec3(p.x + e, p.y, p.z)) - + sdf_func(vec3(p.x - e, p.y, p.z)), + sdf_func(vec3(p.x, p.y + e, p.z)) - + sdf_func(vec3(p.x, p.y - e, p.z)), + sdf_func(vec3(p.x, p.y, p.z + e)) - + sdf_func(vec3(p.x, p.y, p.z - e))) .normalize(); } diff --git a/src/audio/dct.h b/src/audio/dct.h index ca423c2..a44bb15 100644 --- a/src/audio/dct.h +++ b/src/audio/dct.h @@ -4,9 +4,9 @@ #pragma once -#define DCT_SIZE 512 +#define DCT_SIZE 512 #define OLA_HOP_SIZE 256 -#define OLA_OVERLAP 256 +#define OLA_OVERLAP 256 // Forward declarations void fdct_512(const float* input, float* output); diff --git a/src/audio/fft.cc b/src/audio/fft.cc index 6029454..ddd442e 100644 --- a/src/audio/fft.cc +++ b/src/audio/fft.cc @@ -143,7 +143,8 @@ void dct_fft(const float* input, float* output, size_t N) { // IMDCT via FFT // Produces 2N time-domain samples from N MDCT coefficients. // Formula: x[n] = (2/N) * sum_{k=0}^{N-1} X[k] * cos(pi*(2n+1+N)*(2k+1)/(2N)) -// When windowed (Hann, length 2N) and OLA'd with hop N, gives perfect reconstruction. +// When windowed (Hann, length 2N) and OLA'd with hop N, gives perfect +// reconstruction. void imdct_fft(const float* input, float* output, size_t N) { const float PI = 3.14159265358979323846f; const size_t M = 2 * N; // output length @@ -172,7 +173,8 @@ void imdct_fft(const float* input, float* output, size_t N) { imag[i] *= scale; } - // Post-multiply by 2N * exp(-j*pi*(2n+1)/(4N)) and take real part, scale by 2/N + // Post-multiply by 2N * exp(-j*pi*(2n+1)/(4N)) and take real part, scale by + // 2/N const float gain = 2.0f; for (size_t n = 0; n < M; n++) { const float angle = -PI * (2.0f * n + 1.0f) / (4.0f * N); diff --git a/src/audio/mp3_sample.cc b/src/audio/mp3_sample.cc index 028fbff..9a3805b 100644 --- a/src/audio/mp3_sample.cc +++ b/src/audio/mp3_sample.cc @@ -45,9 +45,10 @@ int mp3_decode(Mp3Decoder* dec, int num_frames, float* out) { } void mp3_close(Mp3Decoder* dec) { - if (!dec) return; + if (!dec) + return; ma_decoder_uninit(&dec->dec); delete dec; } -#endif // !STRIP_ALL +#endif // !STRIP_ALL diff --git a/src/audio/mp3_sample.h b/src/audio/mp3_sample.h index e7e759e..bf3147a 100644 --- a/src/audio/mp3_sample.h +++ b/src/audio/mp3_sample.h @@ -31,4 +31,4 @@ int mp3_decode(Mp3Decoder* dec, int num_frames, float* out); // Release the decoder. void mp3_close(Mp3Decoder* dec); -#endif // !STRIP_ALL +#endif // !STRIP_ALL diff --git a/src/audio/ola.h b/src/audio/ola.h index 3dbc368..2d6267e 100644 --- a/src/audio/ola.h +++ b/src/audio/ola.h @@ -7,8 +7,7 @@ // Returns number of OLA frames for n_samples PCM input. static inline int ola_num_frames(int n_samples) { - return (n_samples > DCT_SIZE) ? (n_samples - DCT_SIZE) / OLA_HOP_SIZE + 1 - : 1; + return (n_samples > DCT_SIZE) ? (n_samples - DCT_SIZE) / OLA_HOP_SIZE + 1 : 1; } // Hann-windowed FDCT with 50% overlap (analysis). diff --git a/src/audio/synth.cc b/src/audio/synth.cc index 3212e0b..0866bda 100644 --- a/src/audio/synth.cc +++ b/src/audio/synth.cc @@ -204,7 +204,8 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan, g_synth_data.spectrograms[spectrogram_id].num_frames; v.ola_mode = (g_synth_data.spectrograms[spectrogram_id].version == SPEC_VERSION_V2_OLA); - v.buffer_pos = v.ola_mode ? OLA_HOP_SIZE : DCT_SIZE; // Force reload on first render + v.buffer_pos = + v.ola_mode ? OLA_HOP_SIZE : DCT_SIZE; // Force reload on first render if (v.ola_mode) memset(v.overlap_buf, 0, sizeof(v.overlap_buf)); v.fractional_pos = diff --git a/src/audio/synth.h b/src/audio/synth.h index 61ecfd0..e5a8197 100644 --- a/src/audio/synth.h +++ b/src/audio/synth.h @@ -21,8 +21,8 @@ #define MAX_SPECTROGRAMS \ 32 // Current track: 14 unique, 32 provides comfortable headroom -#define SPEC_VERSION_V1 1 -#define SPEC_VERSION_V2_OLA 2 +#define SPEC_VERSION_V1 1 +#define SPEC_VERSION_V2_OLA 2 struct Spectrogram { const float* spectral_data_a; // Front buffer diff --git a/src/audio/tracker.cc b/src/audio/tracker.cc index 7ce96fc..93c279e 100644 --- a/src/audio/tracker.cc +++ b/src/audio/tracker.cc @@ -12,7 +12,7 @@ #include "audio/dct.h" #include "audio/mp3_sample.h" #include "audio/window.h" -#endif // !defined(STRIP_ALL) +#endif // !defined(STRIP_ALL) static uint32_t g_last_trigger_idx = 0; @@ -44,7 +44,6 @@ static bool g_cache_initialized = false; // Forward declarations static int get_free_pool_slot(); - #if !defined(STRIP_ALL) // Decode an in-memory MP3 blob to a heap-allocated spectrogram (caller owns). // Uses OLA analysis: 512-sample Hann window, OLA_HOP_SIZE advance per frame. @@ -53,7 +52,8 @@ static float* convert_mp3_to_spectrogram(const uint8_t* data, size_t size, int* out_num_frames) { *out_num_frames = 0; Mp3Decoder* dec = mp3_open(data, size); - if (!dec) return nullptr; + if (!dec) + return nullptr; float window[DCT_SIZE]; hann_window_512(window); @@ -82,11 +82,13 @@ static float* convert_mp3_to_spectrogram(const uint8_t* data, size_t size, fdct_512(pcm_chunk, dct_chunk); spec_data.insert(spec_data.end(), dct_chunk, dct_chunk + DCT_SIZE); - if (decoded == 0) break; + if (decoded == 0) + break; } mp3_close(dec); - if (spec_data.empty()) return nullptr; + if (spec_data.empty()) + return nullptr; const int num_frames = (int)(spec_data.size() / DCT_SIZE); float* result = new float[spec_data.size()]; @@ -94,7 +96,7 @@ static float* convert_mp3_to_spectrogram(const uint8_t* data, size_t size, *out_num_frames = num_frames; return result; } -#endif // !defined(STRIP_ALL) +#endif // !defined(STRIP_ALL) void tracker_init() { g_last_trigger_idx = 0; @@ -159,7 +161,7 @@ void tracker_init() { FATAL_CHECK(data == nullptr || GetAssetType(aid) != AssetType::MP3, "MP3 assets not supported in STRIP_ALL builds\n"); #endif - if (data && size >= sizeof(SpecHeader)) { + if (data && size >= sizeof(SpecHeader)) { const SpecHeader* header = (const SpecHeader*)data; const int note_frames = header->num_frames; const float* spectral_data = diff --git a/src/effects/gaussian_blur_effect.cc b/src/effects/gaussian_blur_effect.cc index a925dee..15d4d0a 100644 --- a/src/effects/gaussian_blur_effect.cc +++ b/src/effects/gaussian_blur_effect.cc @@ -7,9 +7,10 @@ GaussianBlur::GaussianBlur(const GpuContext& ctx, const std::vector<std::string>& inputs, - const std::vector<std::string>& outputs, float start_time, - float end_time) - : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr), bind_group_(nullptr) { + const std::vector<std::string>& outputs, + float start_time, float end_time) + : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr), + bind_group_(nullptr) { HEADLESS_RETURN_IF_NULL(ctx_.device); create_linear_sampler(); diff --git a/src/effects/heptagon_effect.cc b/src/effects/heptagon_effect.cc index c02efb3..ac688df 100644 --- a/src/effects/heptagon_effect.cc +++ b/src/effects/heptagon_effect.cc @@ -9,7 +9,7 @@ Heptagon::Heptagon(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time) + float end_time) : Effect(ctx, inputs, outputs, start_time, end_time) { HEADLESS_RETURN_IF_NULL(ctx_.device); diff --git a/src/effects/heptagon_effect.h b/src/effects/heptagon_effect.h index 4563e47..ab7db8d 100644 --- a/src/effects/heptagon_effect.h +++ b/src/effects/heptagon_effect.h @@ -10,7 +10,7 @@ class Heptagon : public Effect { public: Heptagon(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time); + float end_time); void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) override; diff --git a/src/effects/hybrid3_d_effect.cc b/src/effects/hybrid3_d_effect.cc index 5832b57..37d4158 100644 --- a/src/effects/hybrid3_d_effect.cc +++ b/src/effects/hybrid3_d_effect.cc @@ -10,9 +10,10 @@ Hybrid3D::Hybrid3D(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time) - : Effect(ctx, inputs, outputs, start_time, end_time), depth_node_(outputs[0] + "_depth"), - dummy_texture_(nullptr), dummy_texture_view_(nullptr) { + float end_time) + : Effect(ctx, inputs, outputs, start_time, end_time), + depth_node_(outputs[0] + "_depth"), dummy_texture_(nullptr), + dummy_texture_view_(nullptr) { // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL) HEADLESS_RETURN_IF_NULL(ctx_.device); diff --git a/src/effects/hybrid3_d_effect.h b/src/effects/hybrid3_d_effect.h index e0aa6da..13fd7df 100644 --- a/src/effects/hybrid3_d_effect.h +++ b/src/effects/hybrid3_d_effect.h @@ -13,7 +13,7 @@ class Hybrid3D : public Effect { public: Hybrid3D(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time); + float end_time); ~Hybrid3D() override; void declare_nodes(NodeRegistry& registry) override; diff --git a/src/effects/particles_effect.cc b/src/effects/particles_effect.cc index d0336f6..fc37a88 100644 --- a/src/effects/particles_effect.cc +++ b/src/effects/particles_effect.cc @@ -10,7 +10,7 @@ Particles::Particles(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time) + float end_time) : Effect(ctx, inputs, outputs, start_time, end_time) { HEADLESS_RETURN_IF_NULL(ctx_.device); diff --git a/src/effects/particles_effect.h b/src/effects/particles_effect.h index e855b7b..0d5a07e 100644 --- a/src/effects/particles_effect.h +++ b/src/effects/particles_effect.h @@ -22,7 +22,7 @@ class Particles : public Effect { public: Particles(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time); + float end_time); void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) override; diff --git a/src/effects/peak_meter_effect.cc b/src/effects/peak_meter_effect.cc index 2a7b7f9..d462fa0 100644 --- a/src/effects/peak_meter_effect.cc +++ b/src/effects/peak_meter_effect.cc @@ -8,8 +8,9 @@ PeakMeter::PeakMeter(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time) - : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr), bind_group_(nullptr) { + float end_time) + : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr), + bind_group_(nullptr) { HEADLESS_RETURN_IF_NULL(ctx_.device); const char* shader_main = R"( diff --git a/src/effects/peak_meter_effect.h b/src/effects/peak_meter_effect.h index 1786522..1f19ed6 100644 --- a/src/effects/peak_meter_effect.h +++ b/src/effects/peak_meter_effect.h @@ -9,7 +9,7 @@ class PeakMeter : public Effect { public: PeakMeter(const GpuContext& ctx, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, float start_time, - float end_time); + float end_time); ~PeakMeter() override; void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc index 6c350a7..099d06c 100644 --- a/src/effects/rotating_cube_effect.cc +++ b/src/effects/rotating_cube_effect.cc @@ -9,9 +9,10 @@ RotatingCube::RotatingCube(const GpuContext& ctx, const std::vector<std::string>& inputs, - const std::vector<std::string>& outputs, float start_time, - float end_time) - : Effect(ctx, inputs, outputs, start_time, end_time), depth_node_(outputs[0] + "_depth") { + const std::vector<std::string>& outputs, + float start_time, float end_time) + : Effect(ctx, inputs, outputs, start_time, end_time), + depth_node_(outputs[0] + "_depth") { // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL) HEADLESS_RETURN_IF_NULL(ctx_.device); @@ -166,8 +167,8 @@ void RotatingCube::render(WGPUCommandEncoder encoder, GpuTextureCopyInfo src = { .texture = input_tex, .mipLevel = 0, .aspect = WGPUTextureAspect_All}; GpuTextureCopyInfo dst = {.texture = output_tex, - .mipLevel = 0, - .aspect = WGPUTextureAspect_All}; + .mipLevel = 0, + .aspect = WGPUTextureAspect_All}; WGPUExtent3D copy_size = {(uint32_t)params.resolution.x, (uint32_t)params.resolution.y, 1}; wgpuCommandEncoderCopyTextureToTexture(encoder, &src, &dst, ©_size); @@ -181,7 +182,7 @@ void RotatingCube::render(WGPUCommandEncoder encoder, // Render pass with depth WGPURenderPassColorAttachment color_attachment = { .view = color_view, - #if !defined(DEMO_CROSS_COMPILE_WIN32) +#if !defined(DEMO_CROSS_COMPILE_WIN32) .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED, #endif // .loadOp = WGPULoadOp_Clear, diff --git a/src/effects/scene1_effect.cc b/src/effects/scene1_effect.cc index 71e25a4..0aae94a 100644 --- a/src/effects/scene1_effect.cc +++ b/src/effects/scene1_effect.cc @@ -16,10 +16,11 @@ static CameraParams make_scene1_camera(float time) { CameraParams cam; cam.inv_view = mat4::look_at(ro, la, up).inverse(); - cam.fov = TAU / 6.0f; // full vfov=60°; tan(fov/2)=tan(PI/6)=1/sqrt(3)=1/shader_fov + cam.fov = + TAU / 6.0f; // full vfov=60°; tan(fov/2)=tan(PI/6)=1/sqrt(3)=1/shader_fov cam.near_plane = 0.1f; cam.far_plane = 100.0f; - cam.aspect_ratio = 1.0f; // aspect handled in fs_main + cam.aspect_ratio = 1.0f; // aspect handled in fs_main return cam; } @@ -40,9 +41,7 @@ Scene1::Scene1(const GpuContext& ctx, const std::vector<std::string>& inputs, } void Scene1::render(WGPUCommandEncoder encoder, - const UniformsSequenceParams& params, - NodeRegistry& nodes) { - + const UniformsSequenceParams& params, NodeRegistry& nodes) { camera_params_.update(ctx_.queue, make_scene1_camera(params.time)); WGPUTextureView output_view = nodes.get_view(output_nodes_[0]); diff --git a/src/effects/scene2_effect.cc b/src/effects/scene2_effect.cc index b1b9975..8c05574 100644 --- a/src/effects/scene2_effect.cc +++ b/src/effects/scene2_effect.cc @@ -9,9 +9,9 @@ #include "util/fatal_error.h" Scene2Effect::Scene2Effect(const GpuContext& ctx, - const std::vector<std::string>& inputs, - const std::vector<std::string>& outputs, - float start_time, float end_time) + const std::vector<std::string>& inputs, + const std::vector<std::string>& outputs, + float start_time, float end_time) : Effect(ctx, inputs, outputs, start_time, end_time) { HEADLESS_RETURN_IF_NULL(ctx_.device); create_nearest_sampler(); @@ -21,8 +21,8 @@ Scene2Effect::Scene2Effect(const GpuContext& ctx, } void Scene2Effect::render(WGPUCommandEncoder encoder, - const UniformsSequenceParams& params, - NodeRegistry& nodes) { + const UniformsSequenceParams& params, + NodeRegistry& nodes) { WGPUTextureView output_view = nodes.get_view(output_nodes_[0]); // uniforms_buffer_ auto-updated by base class dispatch_render() diff --git a/src/effects/scene2_effect.h b/src/effects/scene2_effect.h index effc19f..da4cf7e 100644 --- a/src/effects/scene2_effect.h +++ b/src/effects/scene2_effect.h @@ -9,13 +9,11 @@ class Scene2Effect : public Effect { public: - Scene2Effect(const GpuContext& ctx, - const std::vector<std::string>& inputs, - const std::vector<std::string>& outputs, - float start_time, float end_time); + Scene2Effect(const GpuContext& ctx, const std::vector<std::string>& inputs, + const std::vector<std::string>& outputs, float start_time, + float end_time); - void render(WGPUCommandEncoder encoder, - const UniformsSequenceParams& params, + void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) override; private: diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index a94b4a0..4230021 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -19,11 +19,10 @@ Effect::Effect(const GpuContext& ctx, const std::vector<std::string>& inputs, } void Effect::dispatch_render(WGPUCommandEncoder encoder, - const UniformsSequenceParams& params, - NodeRegistry& nodes) { + const UniformsSequenceParams& params, + NodeRegistry& nodes) { // Check if effect is active at current time - const bool active = - (params.time >= start_time_ && params.time < end_time_); + const bool active = (params.time >= start_time_ && params.time < end_time_); // Auto-passthrough for 1:1 input/output effects outside active range if (!active && input_nodes_.size() == 1 && output_nodes_.size() == 1) { @@ -32,11 +31,12 @@ void Effect::dispatch_render(WGPUCommandEncoder encoder, uniforms_buffer_.update(ctx_.queue, params); render(encoder, params, nodes); } - // Multi-output effects: output undefined when inactive (validated at compile time) + // Multi-output effects: output undefined when inactive (validated at compile + // time) } void Effect::blit_input_to_output(WGPUCommandEncoder encoder, - NodeRegistry& nodes) { + NodeRegistry& nodes) { HEADLESS_RETURN_IF_NULL(encoder); WGPUTexture src = nodes.get_texture(input_nodes_[0]); @@ -52,8 +52,7 @@ void Effect::blit_input_to_output(WGPUCommandEncoder encoder, GpuTextureCopyInfo dst_copy = { .texture = dst, .mipLevel = 0, .origin = {0, 0, 0}}; - WGPUExtent3D extent = {(unsigned int)(width_), - (unsigned int)(height_), 1}; + WGPUExtent3D extent = {(unsigned int)(width_), (unsigned int)(height_), 1}; wgpuCommandEncoderCopyTextureToTexture(encoder, &src_copy, &dst_copy, &extent); diff --git a/src/gpu/effect.h b/src/gpu/effect.h index bfd5743..8055783 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -54,7 +54,8 @@ class Effect { int height_ = 720; // Common resources (initialized automatically in base class) - UniformBuffer<UniformsSequenceParams> uniforms_buffer_; // Auto-updated in dispatch_render() + UniformBuffer<UniformsSequenceParams> + uniforms_buffer_; // Auto-updated in dispatch_render() Sampler sampler_; Texture dummy_texture_; TextureView dummy_texture_view_; @@ -65,7 +66,8 @@ class Effect { // Helper: Create nearest sampler (call in subclass constructor if needed) void create_nearest_sampler(); - // Helper: Create dummy texture for scene effects (call in subclass constructor if needed) + // Helper: Create dummy texture for scene effects (call in subclass + // constructor if needed) void create_dummy_scene_texture(); private: diff --git a/src/gpu/pipeline_builder.cc b/src/gpu/pipeline_builder.cc index b3fa5f8..ea4a272 100644 --- a/src/gpu/pipeline_builder.cc +++ b/src/gpu/pipeline_builder.cc @@ -11,7 +11,7 @@ RenderPipelineBuilder::RenderPipelineBuilder(WGPUDevice device) } RenderPipelineBuilder& RenderPipelineBuilder::shader(const char* wgsl, - bool compose) { + bool compose) { shader_text_ = compose ? ShaderComposer::Get().Compose({}, wgsl) : wgsl; if (device_ == nullptr) return *this; @@ -26,8 +26,8 @@ RenderPipelineBuilder& RenderPipelineBuilder::shader(const char* wgsl, return *this; } -RenderPipelineBuilder& RenderPipelineBuilder::bind_group_layout( - WGPUBindGroupLayout layout) { +RenderPipelineBuilder& +RenderPipelineBuilder::bind_group_layout(WGPUBindGroupLayout layout) { layouts_.push_back(layout); return *this; } @@ -48,8 +48,8 @@ RenderPipelineBuilder& RenderPipelineBuilder::blend_alpha() { return *this; } -RenderPipelineBuilder& RenderPipelineBuilder::depth( - WGPUTextureFormat depth_fmt) { +RenderPipelineBuilder& +RenderPipelineBuilder::depth(WGPUTextureFormat depth_fmt) { has_depth_ = true; depth_.format = depth_fmt; depth_.depthWriteEnabled = WGPUOptionalBool_True; diff --git a/src/gpu/pipeline_builder.h b/src/gpu/pipeline_builder.h index 9fd76f9..24b4e8b 100644 --- a/src/gpu/pipeline_builder.h +++ b/src/gpu/pipeline_builder.h @@ -34,8 +34,8 @@ class RenderPipelineBuilder { RenderPipelineBuilder& bind_group_layout(WGPUBindGroupLayout layout); RenderPipelineBuilder& format(WGPUTextureFormat fmt); RenderPipelineBuilder& blend_alpha(); - RenderPipelineBuilder& depth( - WGPUTextureFormat depth_fmt = WGPUTextureFormat_Depth24Plus); + RenderPipelineBuilder& + depth(WGPUTextureFormat depth_fmt = WGPUTextureFormat_Depth24Plus); RenderPipelineBuilder& cull_back(); WGPURenderPipeline build(); }; diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc index 783f3df..1e3be6c 100644 --- a/src/gpu/sequence.cc +++ b/src/gpu/sequence.cc @@ -30,7 +30,8 @@ NodeRegistry::NodeRegistry(WGPUDevice device, int default_width, NodeRegistry::~NodeRegistry() { for (auto& [name, node] : nodes_) { - if (node.texture == nullptr) continue; // External view, not owned + if (node.texture == nullptr) + continue; // External view, not owned if (node.view) { wgpuTextureViewRelease(node.view); } @@ -107,7 +108,8 @@ void NodeRegistry::resize(int width, int height) { default_height_ = height; for (auto& [name, node] : nodes_) { - if (node.texture == nullptr) continue; // External view, not owned + if (node.texture == nullptr) + continue; // External view, not owned // Release old texture if (node.view) { wgpuTextureViewRelease(node.view); @@ -184,8 +186,7 @@ void NodeRegistry::create_texture(Node& node) { WGPUTextureDescriptor desc = {}; desc.usage = usage; desc.dimension = WGPUTextureDimension_2D; - desc.size = {(unsigned int)(node.width), - (unsigned int)(node.height), 1}; + desc.size = {(unsigned int)(node.width), (unsigned int)(node.height), 1}; desc.format = format; desc.mipLevelCount = 1; desc.sampleCount = 1; @@ -218,10 +219,8 @@ Sequence::Sequence(const GpuContext& ctx, int width, int height) void Sequence::preprocess(float seq_time, float beat_time, float beat_phase, float audio_intensity) { - params_.resolution = {(float)(width_), - (float)(height_)}; - params_.aspect_ratio = - (float)(width_) / (float)(height_); + params_.resolution = {(float)(width_), (float)(height_)}; + params_.aspect_ratio = (float)(width_) / (float)(height_); params_.time = seq_time; params_.beat_time = beat_time; params_.beat_phase = beat_phase; diff --git a/src/gpu/sequence.h b/src/gpu/sequence.h index 2ad0a8f..a515d1f 100644 --- a/src/gpu/sequence.h +++ b/src/gpu/sequence.h @@ -15,7 +15,7 @@ class Effect; enum class NodeType { - U8X4_NORM, // RGBAu8 (default Source/Sink) + U8X4_NORM, // RGBAu8 (default Source/Sink) F32X4, F16X8, DEPTH24, @@ -38,7 +38,7 @@ struct UniformsSequenceParams { float beat_time; // Musical beats float beat_phase; // Fractional beat 0.0-1.0 float audio_intensity; - float noise; // Random value [0..1] + float noise; // Random value [0..1] }; static_assert(sizeof(UniformsSequenceParams) == 32, "UniformsSequenceParams must be 32 bytes for WGSL alignment"); diff --git a/src/gpu/shader_composer.cc b/src/gpu/shader_composer.cc index be311dd..d871c5e 100644 --- a/src/gpu/shader_composer.cc +++ b/src/gpu/shader_composer.cc @@ -50,8 +50,9 @@ void ShaderComposer::ResolveRecursive(const std::string& source, std::string suggestion; for (const auto& [sname, _] : snippets_) { auto slash = sname.rfind('/'); - std::string basename = - (slash == std::string::npos) ? sname : sname.substr(slash + 1); + std::string basename = (slash == std::string::npos) + ? sname + : sname.substr(slash + 1); if (basename == name) { suggestion = sname; break; @@ -133,7 +134,8 @@ void ShaderComposer::VerifyIncludes() const { } } if (!missing.empty()) { - fprintf(stderr, "ERROR: Unregistered shader snippets referenced in #include:\n"); + fprintf(stderr, + "ERROR: Unregistered shader snippets referenced in #include:\n"); for (const auto& name : missing) { std::string suggestion; for (const auto& [sname, _] : snippets_) { diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc index 211beed..e512428 100644 --- a/src/gpu/texture_readback.cc +++ b/src/gpu/texture_readback.cc @@ -56,8 +56,7 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance, }, }; - const WGPUExtent3D copy_size = {(uint32_t)(width), - (uint32_t)(height), 1}; + const WGPUExtent3D copy_size = {(uint32_t)(width), (uint32_t)(height), 1}; wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, ©_size); @@ -117,8 +116,8 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance, } // Copy data from mapped buffer (handle row padding) - const uint8_t* mapped_data = (const uint8_t*)( - wgpuBufferGetConstMappedRange(staging, 0, buffer_size)); + const uint8_t* mapped_data = + (const uint8_t*)(wgpuBufferGetConstMappedRange(staging, 0, buffer_size)); if (mapped_data) { // If rows are aligned, copy row by row to remove padding if (aligned_bytes_per_row != unaligned_bytes_per_row) { @@ -212,8 +211,7 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device, .rowsPerImage = (uint32_t)(height), }, }; - const WGPUExtent3D copy_size = {(uint32_t)(width), - (uint32_t)(height), 1}; + const WGPUExtent3D copy_size = {(uint32_t)(width), (uint32_t)(height), 1}; wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, ©_size); WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr); @@ -259,15 +257,15 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device, } // Convert FP16 to U8 ([-1,1] → [0,255]) - const uint16_t* mapped_data = (const uint16_t*)( - wgpuBufferGetConstMappedRange(staging, 0, buffer_size)); + const uint16_t* mapped_data = + (const uint16_t*)(wgpuBufferGetConstMappedRange(staging, 0, buffer_size)); std::vector<uint8_t> pixels(width * height * 4); if (mapped_data) { for (int y = 0; y < height; ++y) { - const uint16_t* src_row = (const uint16_t*)( - (const uint8_t*)(mapped_data) + - y * aligned_bytes_per_row); + const uint16_t* src_row = + (const uint16_t*)((const uint8_t*)(mapped_data) + + y * aligned_bytes_per_row); for (int x = 0; x < width; ++x) { float r = fp16_to_float(src_row[x * 4 + 0]); float g = fp16_to_float(src_row[x * 4 + 1]); diff --git a/src/gpu/wgpu_resource.h b/src/gpu/wgpu_resource.h index e448b18..e12aa45 100644 --- a/src/gpu/wgpu_resource.h +++ b/src/gpu/wgpu_resource.h @@ -11,11 +11,14 @@ #include "platform/platform.h" #include "util/fatal_error.h" -template<typename T, void(*Release)(T)> -class WGPUResource { +template <typename T, void (*Release)(T)> class WGPUResource { public: - WGPUResource() : ptr_(nullptr) {} - ~WGPUResource() { if (ptr_) Release(ptr_); } + WGPUResource() : ptr_(nullptr) { + } + ~WGPUResource() { + if (ptr_) + Release(ptr_); + } void set(T ptr) { FATAL_ASSERT(ptr_ == nullptr); @@ -23,12 +26,17 @@ class WGPUResource { } void replace(T ptr) { - if (ptr_) Release(ptr_); + if (ptr_) + Release(ptr_); ptr_ = ptr; } - T get() const { return ptr_; } - T* get_address() { return &ptr_; } + T get() const { + return ptr_; + } + T* get_address() { + return &ptr_; + } private: T ptr_; @@ -37,8 +45,10 @@ class WGPUResource { }; using BindGroup = WGPUResource<WGPUBindGroup, wgpuBindGroupRelease>; -using RenderPipeline = WGPUResource<WGPURenderPipeline, wgpuRenderPipelineRelease>; -using ComputePipeline = WGPUResource<WGPUComputePipeline, wgpuComputePipelineRelease>; +using RenderPipeline = + WGPUResource<WGPURenderPipeline, wgpuRenderPipelineRelease>; +using ComputePipeline = + WGPUResource<WGPUComputePipeline, wgpuComputePipelineRelease>; using Sampler = WGPUResource<WGPUSampler, wgpuSamplerRelease>; using Texture = WGPUResource<WGPUTexture, wgpuTextureRelease>; using TextureView = WGPUResource<WGPUTextureView, wgpuTextureViewRelease>; diff --git a/src/tests/audio/test_wav_dump.cc b/src/tests/audio/test_wav_dump.cc index bfb9d9a..4d9b7ba 100644 --- a/src/tests/audio/test_wav_dump.cc +++ b/src/tests/audio/test_wav_dump.cc @@ -58,7 +58,8 @@ void test_wav_format_matches_live_audio() { for (float t = 0.0f; t < duration; t += update_dt) { for (int i = 0; i < samples_per_update; i += 2) { - const float phase = 2.0f * 3.14159265f * freq * (float)sample_index / sample_rate; + const float phase = + 2.0f * 3.14159265f * freq * (float)sample_index / sample_rate; const float s = 0.5f * sinf(phase); chunk_buffer[i] = s; // L chunk_buffer[i + 1] = s; // R diff --git a/src/tests/audio/test_wav_roundtrip.cc b/src/tests/audio/test_wav_roundtrip.cc index 79de6ad..30f6cda 100644 --- a/src/tests/audio/test_wav_roundtrip.cc +++ b/src/tests/audio/test_wav_roundtrip.cc @@ -12,8 +12,7 @@ static const int SAMPLE_RATE = 32000; static const float PI = 3.14159265358979323846f; static float compute_snr_db(const std::vector<float>& ref, - const std::vector<float>& out, - int skip_samples) { + const std::vector<float>& out, int skip_samples) { const int n = (int)std::min(ref.size(), out.size()); double sig = 0.0, noise = 0.0; for (int i = skip_samples; i < n; ++i) { @@ -21,7 +20,8 @@ static float compute_snr_db(const std::vector<float>& ref, double e = ref[i] - out[i]; noise += e * e; } - if (noise < 1e-30) return 999.0f; + if (noise < 1e-30) + return 999.0f; return 10.0f * (float)log10(sig / noise); } @@ -45,8 +45,8 @@ int main() { // SNR — skip first DCT_SIZE samples (ramp-up transient) const float snr = compute_snr_db(input, output, DCT_SIZE); - printf("Roundtrip SNR: %.1f dB (frames=%d, out_samples=%zu)\n", - snr, num_frames, output.size()); + printf("Roundtrip SNR: %.1f dB (frames=%d, out_samples=%zu)\n", snr, + num_frames, output.size()); const float MIN_SNR_DB = 30.0f; if (snr < MIN_SNR_DB) { diff --git a/src/tests/gpu/test_demo_effects.cc b/src/tests/gpu/test_demo_effects.cc index b005662..5c4bffc 100644 --- a/src/tests/gpu/test_demo_effects.cc +++ b/src/tests/gpu/test_demo_effects.cc @@ -58,9 +58,9 @@ static void test_effects() { {"Hybrid3D", std::make_shared<Hybrid3D>( fixture.ctx(), std::vector<std::string>{"source"}, std::vector<std::string>{"sink"}, 0.0f, 1000.0f)}, - {"Flash", std::make_shared<Flash>(fixture.ctx(), - std::vector<std::string>{"source"}, - std::vector<std::string>{"sink"}, 0.0f, 1000.0f)}, + {"Flash", std::make_shared<Flash>( + fixture.ctx(), std::vector<std::string>{"source"}, + std::vector<std::string>{"sink"}, 0.0f, 1000.0f)}, {"PeakMeter", std::make_shared<PeakMeter>( fixture.ctx(), std::vector<std::string>{"source"}, std::vector<std::string>{"sink"}, 0.0f, 1000.0f)}, diff --git a/src/tests/gpu/test_effect_base.cc b/src/tests/gpu/test_effect_base.cc index 64e5fa4..e73f4d7 100644 --- a/src/tests/gpu/test_effect_base.cc +++ b/src/tests/gpu/test_effect_base.cc @@ -104,10 +104,9 @@ static void test_effect_in_sequence() { class TestSequence : public Sequence { public: TestSequence(const GpuContext& ctx, int w, int h) : Sequence(ctx, w, h) { - auto effect = - std::make_shared<Passthrough>(ctx, std::vector<std::string>{"source"}, - std::vector<std::string>{"sink"}, 0.0f, - 1000.0f); + auto effect = std::make_shared<Passthrough>( + ctx, std::vector<std::string>{"source"}, + std::vector<std::string>{"sink"}, 0.0f, 1000.0f); effect_dag_.push_back({effect, {"source"}, {"sink"}, 0}); init_effect_nodes(); @@ -137,10 +136,9 @@ static void test_sequence_render() { class TestSequence : public Sequence { public: TestSequence(const GpuContext& ctx, int w, int h) : Sequence(ctx, w, h) { - auto effect = - std::make_shared<Passthrough>(ctx, std::vector<std::string>{"source"}, - std::vector<std::string>{"sink"}, 0.0f, - 1000.0f); + auto effect = std::make_shared<Passthrough>( + ctx, std::vector<std::string>{"source"}, + std::vector<std::string>{"sink"}, 0.0f, 1000.0f); effect_dag_.push_back({effect, {"source"}, {"sink"}, 0}); init_effect_nodes(); diff --git a/src/tests/gpu/test_shader_assets.cc b/src/tests/gpu/test_shader_assets.cc index 084694d..1ceb49d 100644 --- a/src/tests/gpu/test_shader_assets.cc +++ b/src/tests/gpu/test_shader_assets.cc @@ -60,10 +60,9 @@ int main() { all_passed &= validate_shader(AssetId::ASSET_SHADER_PARTICLE_RENDER, "PARTICLE_RENDER", {"@vertex", "vs_main", "@fragment", "fs_main"}); - all_passed &= - validate_shader(AssetId::ASSET_SHADER_PASSTHROUGH, "PASSTHROUGH", - {"#include \"render/fullscreen_uv_vs\"", "@fragment", - "fs_main"}); + all_passed &= validate_shader( + AssetId::ASSET_SHADER_PASSTHROUGH, "PASSTHROUGH", + {"#include \"render/fullscreen_uv_vs\"", "@fragment", "fs_main"}); all_passed &= validate_shader( AssetId::ASSET_SHADER_ELLIPSE, "ELLIPSE", {"#include \"render/fullscreen_vs\"", "@fragment", "fs_main"}); diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h index 09483e5..5380257 100644 --- a/src/util/asset_manager.h +++ b/src/util/asset_manager.h @@ -5,7 +5,12 @@ #pragma once #include "asset_manager_dcl.h" -enum class AssetType : uint8_t { STATIC, PROC, PROC_GPU, MP3 }; +enum class AssetType : uint8_t { + STATIC, + PROC, + PROC_GPU, + MP3 +}; struct AssetRecord { const uint8_t* data; // Pointer to asset data (static or dynamic) diff --git a/tools/asset_packer.cc b/tools/asset_packer.cc index 0d48906..c982a39 100644 --- a/tools/asset_packer.cc +++ b/tools/asset_packer.cc @@ -80,8 +80,8 @@ static bool ParseProceduralParams(const std::string& params_str, // Helper struct to hold all information about an asset during parsing struct AssetBuildInfo { std::string name; - std::string filename; // Original filename for static assets - std::string asset_type; // "STATIC", "PROC", "PROC_GPU", "MP3" + std::string filename; // Original filename for static assets + std::string asset_type; // "STATIC", "PROC", "PROC_GPU", "MP3" std::string proc_func_name; // Function name string std::vector<float> proc_params; // Parameters for procedural function @@ -453,7 +453,8 @@ int main(int argc, char* argv[]) { } else if (compression_type_str == "MP3") { info.asset_type = "MP3"; } else if (compression_type_str != "NONE") { - fprintf(stderr, "Warning: Unknown compression type '%s' for asset: %s\n", + fprintf(stderr, + "Warning: Unknown compression type '%s' for asset: %s\n", compression_type_str.c_str(), info.name.c_str()); } @@ -545,9 +546,8 @@ int main(int argc, char* argv[]) { fprintf(assets_data_cc_file, " { "); if (info.asset_type == "PROC" || info.asset_type == "PROC_GPU") { fprintf(assets_data_cc_file, "nullptr, 0, AssetType::%s, %s, %s, %zu", - info.asset_type.c_str(), - info.func_name_str_name.c_str(), info.params_array_name.c_str(), - info.proc_params.size()); + info.asset_type.c_str(), info.func_name_str_name.c_str(), + info.params_array_name.c_str(), info.proc_params.size()); } else { fprintf(assets_data_cc_file, "%s, ASSET_SIZE_%s, AssetType::%s, nullptr, nullptr, 0", diff --git a/tools/cnn_test.cc b/tools/cnn_test.cc index 1262021..70f857e 100644 --- a/tools/cnn_test.cc +++ b/tools/cnn_test.cc @@ -200,10 +200,8 @@ static WGPUTexture load_texture(WGPUDevice device, WGPUQueue queue, // Upload to GPU const WGPUTexelCopyTextureInfo dst = {.texture = texture, .mipLevel = 0}; const WGPUTexelCopyBufferLayout layout = { - .bytesPerRow = (uint32_t)(width * 4), - .rowsPerImage = (uint32_t)(height)}; - const WGPUExtent3D size = {(uint32_t)(width), - (uint32_t)(height), 1}; + .bytesPerRow = (uint32_t)(width * 4), .rowsPerImage = (uint32_t)(height)}; + const WGPUExtent3D size = {(uint32_t)(width), (uint32_t)(height), 1}; wgpuQueueWriteTexture(queue, &dst, bgra_data.data(), bgra_data.size(), &layout, &size); @@ -255,8 +253,7 @@ static WGPUTexture load_depth_from_alpha(WGPUDevice device, WGPUQueue queue, const WGPUTexelCopyBufferLayout layout = { .bytesPerRow = (uint32_t)(width * sizeof(float)), .rowsPerImage = (uint32_t)(height)}; - const WGPUExtent3D size = {(uint32_t)(width), - (uint32_t)(height), 1}; + const WGPUExtent3D size = {(uint32_t)(width), (uint32_t)(height), 1}; wgpuQueueWriteTexture(queue, &dst, depth_data.data(), depth_data.size() * sizeof(float), &layout, &size); @@ -474,8 +471,7 @@ readback_rgba32uint_to_bgra8(WGPUDevice device, WGPUQueue queue, dst.layout.bytesPerRow = padded_bytes_per_row; dst.layout.rowsPerImage = height; - WGPUExtent3D copy_size = {(uint32_t)(width), - (uint32_t)(height), 1}; + WGPUExtent3D copy_size = {(uint32_t)(width), (uint32_t)(height), 1}; wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, ©_size); diff --git a/tools/shadertoy/template.cc b/tools/shadertoy/template.cc index 81c39ba..bcaea3b 100644 --- a/tools/shadertoy/template.cc +++ b/tools/shadertoy/template.cc @@ -2,8 +2,8 @@ // ShaderToy effect implementation - REPLACE THIS LINE // TODO: Update description, rename class -#include "effects/shadertoy_effect.h" #include "effects/shaders.h" +#include "effects/shadertoy_effect.h" #include "gpu/gpu.h" #include "gpu/post_process_helper.h" #include "util/fatal_error.h" diff --git a/tools/shadertoy/template.h b/tools/shadertoy/template.h index 5f105d5..c8d132a 100644 --- a/tools/shadertoy/template.h +++ b/tools/shadertoy/template.h @@ -11,13 +11,11 @@ class ShaderToyEffect : public Effect { public: // TODO: Rename class, keep same constructor signature - ShaderToyEffect(const GpuContext& ctx, - const std::vector<std::string>& inputs, - const std::vector<std::string>& outputs, - float start_time, float end_time); + ShaderToyEffect(const GpuContext& ctx, const std::vector<std::string>& inputs, + const std::vector<std::string>& outputs, float start_time, + float end_time); - void render(WGPUCommandEncoder encoder, - const UniformsSequenceParams& params, + void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) override; private: diff --git a/tools/spectool.cc b/tools/spectool.cc index 93f8f9a..0728ed8 100644 --- a/tools/spectool.cc +++ b/tools/spectool.cc @@ -3,8 +3,8 @@ // Provides both 'analyze' and 'play' modes for spectral data. #include "audio/audio.h" -#include "audio/ola.h" #include "audio/gen.h" +#include "audio/ola.h" #include "audio/synth.h" #include "platform/platform.h" #include <stdio.h> @@ -184,7 +184,8 @@ int analyze_audio(const char* in_path, const char* out_path, bool normalize, return 0; } -static void write_wav_header(FILE* f, uint32_t num_samples, uint32_t sample_rate) { +static void write_wav_header(FILE* f, uint32_t num_samples, + uint32_t sample_rate) { const uint16_t num_channels = 1; const uint16_t bits_per_sample = 16; const uint32_t data_size = num_samples * num_channels * (bits_per_sample / 8); @@ -259,15 +260,17 @@ int decode_to_wav(const char* in_path, const char* out_path) { for (uint32_t i = 0; i < out_samples; ++i) { float s = pcm[i]; - if (s > 1.0f) s = 1.0f; - if (s < -1.0f) s = -1.0f; + if (s > 1.0f) + s = 1.0f; + if (s < -1.0f) + s = -1.0f; int16_t sample = (int16_t)(s * 32767.0f); fwrite(&sample, sizeof(int16_t), 1, f_out); } fclose(f_out); - printf("Decoded %d frames (%u samples) at %u Hz.\n", - header.num_frames, out_samples, sample_rate); + printf("Decoded %d frames (%u samples) at %u Hz.\n", header.num_frames, + out_samples, sample_rate); return 0; } |
