Skip to content

Commit

Permalink
feat: added support for playing different AudioBuffer sample rates (#283
Browse files Browse the repository at this point in the history
)

Co-authored-by: Maciej Makowski <[email protected]>
  • Loading branch information
maciejmakowski2003 and Maciej Makowski authored Feb 3, 2025
1 parent 06e04a0 commit 0ea9016
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ float AudioBufferSourceNode::getPlaybackRateValue(size_t &startOffset) {
auto time = context_->getCurrentTime() +
static_cast<double>(startOffset) / context_->getSampleRate();

return playbackRateParam_->getValueAtTime(time) *
std::pow(2.0f, detuneParam_->getValueAtTime(time) / 1200.0f);
auto sampleRateFactor = buffer_->getSampleRate() / context_->getSampleRate();
auto detune = std::pow(2.0f, detuneParam_->getValueAtTime(time) / 1200.0f);
auto playbackRate = playbackRateParam_->getValueAtTime(time);

return playbackRate * sampleRateFactor * detune;
}

double AudioBufferSourceNode::getVirtualStartFrame() {
Expand Down

0 comments on commit 0ea9016

Please sign in to comment.