Adds Math::sin_cos() - This computes sine and cosine of the same angle together, which reduces cycles and should improve performance slightly.#1298
Conversation
…e together, which reduces cycles and should improve performance slightly.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughThis PR adds ChangesMath::sin_cos rollout
Estimated code review effort: 2 (Simple) | ~15 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
servers/audio/effects/audio_effect_spectrum_analyzer.cpp (1)
84-87: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider using
floatinstead ofreal_tforsc_sin/sc_cos.Same observation as the
smbFftinaudio_effect_pitch_shift.cpp: all surrounding variables arefloat, so declaringsc_sin/sc_cosasreal_tis inconsistent and may cause an unnecessary promote-narrow ifreal_tisdouble.♻️ Proposed refactor
- real_t sc_sin, sc_cos; + float sc_sin, sc_cos;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@servers/audio/effects/audio_effect_spectrum_analyzer.cpp` around lines 84 - 87, The `AudioEffectSpectrumAnalyzer` FFT twiddle setup uses `real_t` for `sc_sin` and `sc_cos`, which is inconsistent with the surrounding `float` variables and may introduce unnecessary conversions. Update the `Math::sin_cos` locals in the spectrum analyzer code path to use `float`, matching the `smbFft` style in `AudioEffectPitchShift`, and keep the subsequent assignments to `wr` and `wi` in the same `float` type flow.servers/audio/effects/audio_effect_pitch_shift.cpp (1)
262-265: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider using
floatinstead ofreal_tforsc_sin/sc_cos.All surrounding variables in
smbFft(wr,wi,arg,ur,ui) arefloat, butsc_sin/sc_cosare declared asreal_t. Ifreal_tis configured asdouble, this triggers thesin_cos(float, double&, double&)overload which computes in float viasincosfthen promotes todouble, only to narrow back tofloaton assignment towr/wi. Usingfloatdirectly is consistent with the rest of the function and avoids the unnecessary promotion.♻️ Proposed refactor
- real_t sc_sin, sc_cos; + float sc_sin, sc_cos;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@servers/audio/effects/audio_effect_pitch_shift.cpp` around lines 262 - 265, The smbFft implementation in audio_effect_pitch_shift.cpp uses real_t for sc_sin/sc_cos even though the surrounding values are float. Update the sc_sin and sc_cos declarations in smbFft to float so Math::sin_cos uses the float overload consistently, matching wr, wi, arg, ur, and ui and avoiding the extra promote/narrow path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@servers/audio/effects/audio_effect_pitch_shift.cpp`:
- Around line 262-265: The smbFft implementation in audio_effect_pitch_shift.cpp
uses real_t for sc_sin/sc_cos even though the surrounding values are float.
Update the sc_sin and sc_cos declarations in smbFft to float so Math::sin_cos
uses the float overload consistently, matching wr, wi, arg, ur, and ui and
avoiding the extra promote/narrow path.
In `@servers/audio/effects/audio_effect_spectrum_analyzer.cpp`:
- Around line 84-87: The `AudioEffectSpectrumAnalyzer` FFT twiddle setup uses
`real_t` for `sc_sin` and `sc_cos`, which is inconsistent with the surrounding
`float` variables and may introduce unnecessary conversions. Update the
`Math::sin_cos` locals in the spectrum analyzer code path to use `float`,
matching the `smbFft` style in `AudioEffectPitchShift`, and keep the subsequent
assignments to `wr` and `wi` in the same `float` type flow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1553b08b-27c8-4218-ad72-fa90c4572700
📒 Files selected for processing (17)
core/math/basis.cppcore/math/math_funcs.hcore/math/quaternion.cppcore/math/transform_2d.cppcore/math/transform_2d.hcore/math/vector2.cppmodules/godot_physics_3d/godot_collision_solver_3d.cppmodules/godot_physics_3d/godot_collision_solver_3d_sat.cppscene/2d/cpu_particles_2d.cppscene/3d/cpu_particles_3d.cppscene/main/canvas_item.cppscene/resources/style_box_flat.cppservers/audio/effects/audio_effect_pitch_shift.cppservers/audio/effects/audio_effect_spectrum_analyzer.cppservers/rendering/renderer_canvas_cull.cppservers/rendering/renderer_rd/renderer_compositor_rd.cppservers/rendering/renderer_scene_cull.cpp
|
Fantastic work McDubh! I am seeing a pretty good speed up here compared to #1273 . |

I also replaced certain individual calls of sin and cos with sin_cos. I did not do every single instance of sine and cosine because it is mostly not necessary in every case and I did not want to add more code to review. Plus I wanted to not touch tons of files. We can, if someone wanted to, but the pay off is a one-off and I don't think it will be impactful outside of hot paths.
Summary by CodeRabbit
Math::sin_cos(leveraging compiler builtins when available).