You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(stk): use the Csound sample rate in all instrument adapters - #58
STK instruments keep their default 44.1 kHz sample rate even when Csound runs at another rate. In the reported Saxofony example, this makes a 48 kHz render about 147 cents sharper than a 44.1 kHz render. The rate-setting calls were lost in d2e2057.
Restore the effective instrument sample rate (insdshead->esr) in both shared adapters, before construction and noteOn(). Set it on reinitialization too. This covers all 27 Csound 7 STK opcodes and keeps the constructor error handling intact.
Move the adapters to a header so native unit tests can use a small probe instrument. Six tests cover both constructor forms, changes between 44.1/48/96 kHz, and reinitialization of an existing instrument. They check the rate seen by the constructor and noteOn() without rendering audio or starting Csound. CTest runs them when GoogleTest is available, including the existing Linux CI job.
Validation:
All six new tests failed before the fix and pass after it.
Native STK plugin and Nix WASM builds pass; all 11 existing plugin tests pass.
Repeating the Saxofony render at 44.1 and 48 kHz reduces the measured pitch difference from 146.7 to 1.6 cents. The model's small baseline detuning remains.
Summary by CodeRabbit
Bug Fixes
STK instrument opcodes now apply the engine’s current sample rate when instruments are initialized or restarted, helping maintain accurate playback when the sample rate changes.
Improvements
STK instrument playback now handles controller updates and released notes consistently, with silent output outside the active processing period.
Reviewing files that changed from the base of the PR and between 8de8d04 and ebb61ab.
📒 Files selected for processing: 4
7.x/src/stk/CMakeLists.txt
7.x/src/stk/STKInstrumentAdapter.hpp
7.x/src/stk/stkOpcodes.cpp
7.x/src/stk/tests/stk_adapter_test.cpp
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
📝 Walkthrough
The STK adapter templates move from stkOpcodes.cpp into STKInstrumentAdapter.hpp. Native Google Test coverage and a conditional CMake test target are added to check sample-rate behavior for both adapter forms.
Changes: STK adapter changes
Layer / File(s)
Summary
Adapter runtime and opcode integration 7.x/src/stk/STKInstrumentAdapter.hpp, 7.x/src/stk/stkOpcodes.cpp
The two adapter templates now reside in a header included by stkOpcodes.cpp. They set STK’s shared sample rate during initialization, handle instrument creation, controller updates, audio output, and cleanup.
Sample-rate test coverage 7.x/src/stk/tests/stk_adapter_test.cpp, 7.x/src/stk/CMakeLists.txt
Typed tests check sample rates during construction and note start, including reinitialization. CMake builds and registers the tests for native builds when GTest is found.
This change restores Csound's sample rate in the STK instrument adapters, so instruments no longer play out of tune when Csound runs at rates other than 44.1 kHz. It also adds native unit tests for this behavior. No concrete defect was found, and the change appears ready to merge.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 3 files. (1 skipped: 1…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: using the Csound sample rate in all STK instrument adapters.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 3 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
STK instruments keep their default 44.1 kHz sample rate even when Csound runs at another rate. In the reported Saxofony example, this makes a 48 kHz render about 147 cents sharper than a 44.1 kHz render. The rate-setting calls were lost in d2e2057.
Restore the effective instrument sample rate (
insdshead->esr) in both shared adapters, before construction andnoteOn(). Set it on reinitialization too. This covers all 27 Csound 7 STK opcodes and keeps the constructor error handling intact.Move the adapters to a header so native unit tests can use a small probe instrument. Six tests cover both constructor forms, changes between 44.1/48/96 kHz, and reinitialization of an existing instrument. They check the rate seen by the constructor and
noteOn()without rendering audio or starting Csound. CTest runs them when GoogleTest is available, including the existing Linux CI job.Validation:
Summary by CodeRabbit