From 425c40ff08f56f9a719e1ee6ba0f1b5897974447 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 17 Jun 2016 22:17:19 +0200 Subject: fix upsampling import of X-channel files where buffersize % X != 0 --- libs/ardour/import.cc | 8 ++++---- libs/ardour/resampled_source.cc | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index dbb3db6285..fd5d3bf98a 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -265,14 +265,14 @@ write_audio_data_to_new_files (ImportableSource* source, ImportStatus& status, uint32_t read_count = 0; while (!status.cancel) { - framecnt_t const nread = source->read (data.get(), nframes); + framecnt_t const nread = source->read (data.get(), nframes * channels); if (nread == 0) { break; } - peak = compute_peak (data.get(), nread, peak); + peak = compute_peak (data.get(), nread * channels, peak); - read_count += nread; + read_count += nread / channels; status.progress = 0.5 * read_count / (source->ratio() * source->length() * channels); } @@ -294,7 +294,7 @@ write_audio_data_to_new_files (ImportableSource* source, ImportStatus& status, uint32_t x; uint32_t chn; - if ((nread = source->read (data.get(), nframes)) == 0) { + if ((nread = source->read (data.get(), nframes * channels)) == 0) { #ifdef PLATFORM_WINDOWS /* Flush the data once we've finished importing the file. Windows can */ /* cache the data for very long periods of time (perhaps not writing */ diff --git a/libs/ardour/resampled_source.cc b/libs/ardour/resampled_source.cc index 5c811706d0..ca59d20b58 100644 --- a/libs/ardour/resampled_source.cc +++ b/libs/ardour/resampled_source.cc @@ -73,14 +73,15 @@ framecnt_t ResampledImportableSource::read (Sample* output, framecnt_t nframes) { int err; + size_t bs = floor (blocksize / source->channels()) * source->channels(); /* If the input buffer is empty, refill it. */ if (_src_data.input_frames == 0) { - _src_data.input_frames = source->read (_input, blocksize); + _src_data.input_frames = source->read (_input, bs); /* The last read will not be a full buffer, so set end_of_input. */ - if ((framecnt_t) _src_data.input_frames < blocksize) { + if ((framecnt_t) _src_data.input_frames < bs) { _end_of_input = true; } -- cgit v1.2.3