Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use src_set_ratio to fix artifacts in Sample playback #7321

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading