Skip to content

Commit

Permalink
Make SampleBuffer adjust its members when resampling
Browse files Browse the repository at this point in the history
Fixes #5218.
  • Loading branch information
softrabbit authored and Reflexe committed Oct 19, 2019
1 parent a9262b9 commit 4f11cf1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/SampleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,14 @@ void SampleBuffer::directFloatWrite ( sample_t * & _fbuf, f_cnt_t _frames, int _
void SampleBuffer::normalizeSampleRate( const sample_rate_t _src_sr,
bool _keep_settings )
{
const sample_rate_t old_rate = m_sampleRate;
// do samplerate-conversion to our default-samplerate
if( _src_sr != mixerSampleRate() )
{
SampleBuffer * resampled = resample( _src_sr,
mixerSampleRate() );

m_sampleRate = mixerSampleRate();
MM_FREE( m_data );
m_frames = resampled->frames();
m_data = MM_ALLOC( sampleFrame, m_frames );
Expand All @@ -401,6 +404,16 @@ void SampleBuffer::normalizeSampleRate( const sample_rate_t _src_sr,
m_loopStartFrame = m_startFrame = 0;
m_loopEndFrame = m_endFrame = m_frames;
}
else if( old_rate != mixerSampleRate() )
{
auto old_rate_to_new_rate_ratio = static_cast<float>(mixerSampleRate()) / old_rate;

m_startFrame = qBound(0, f_cnt_t(m_startFrame*old_rate_to_new_rate_ratio), m_frames);
m_endFrame = qBound(m_startFrame, f_cnt_t(m_endFrame*old_rate_to_new_rate_ratio), m_frames);
m_loopStartFrame = qBound(0, f_cnt_t(m_loopStartFrame*old_rate_to_new_rate_ratio), m_frames);
m_loopEndFrame = qBound(m_loopStartFrame, f_cnt_t(m_loopEndFrame*old_rate_to_new_rate_ratio), m_frames);
m_sampleRate = mixerSampleRate();
}
}


Expand Down

0 comments on commit 4f11cf1

Please sign in to comment.