Skip to content

Commit

Permalink
Use src_set_ratio to fix artifacts within Sample playback (LMMS#7321
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sakertooth authored Jun 15, 2024
1 parent 68ea3f5 commit 01ffa95
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/AudioResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class LMMS_EXPORT AudioResampler
auto resample(const float* in, long inputFrames, float* out, long outputFrames, double ratio) -> ProcessResult;
auto interpolationMode() const -> int { return m_interpolationMode; }
auto channels() const -> int { return m_channels; }
void setRatio(double ratio);

private:
int m_interpolationMode = -1;
Expand Down
5 changes: 5 additions & 0 deletions src/core/AudioResampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ auto AudioResampler::resample(const float* in, long inputFrames, float* out, lon
return {src_process(m_state, &data), data.input_frames_used, data.output_frames_gen};
}

void AudioResampler::setRatio(double ratio)
{
src_set_ratio(m_state, ratio);
}

} // namespace lmms
2 changes: 2 additions & 0 deletions src/core/Sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ bool Sample::play(sampleFrame* dst, PlaybackState* state, size_t numFrames, floa
auto playBuffer = std::vector<sampleFrame>(numFrames / resampleRatio + marginSize);
playRaw(playBuffer.data(), playBuffer.size(), state, loopMode);

state->resampler().setRatio(resampleRatio);

const auto resampleResult
= state->resampler().resample(&playBuffer[0][0], playBuffer.size(), &dst[0][0], numFrames, resampleRatio);
advance(state, resampleResult.inputFramesUsed, loopMode);
Expand Down

0 comments on commit 01ffa95

Please sign in to comment.