fix import resampling (don’t cut end short)
This commit is contained in:
parent
2083cd8a4e
commit
0cc2e3b370
@ -36,7 +36,7 @@ class LIBARDOUR_API ResampledImportableSource : public ImportableSource
|
|||||||
~ResampledImportableSource ();
|
~ResampledImportableSource ();
|
||||||
|
|
||||||
framecnt_t read (Sample* buffer, framecnt_t nframes);
|
framecnt_t read (Sample* buffer, framecnt_t nframes);
|
||||||
float ratio() const { return src_data.src_ratio; }
|
float ratio() const { return _src_data.src_ratio; }
|
||||||
uint32_t channels() const { return source->channels(); }
|
uint32_t channels() const { return source->channels(); }
|
||||||
framecnt_t length() const { return source->length(); }
|
framecnt_t length() const { return source->length(); }
|
||||||
framecnt_t samplerate() const { return source->samplerate(); }
|
framecnt_t samplerate() const { return source->samplerate(); }
|
||||||
@ -52,10 +52,11 @@ class LIBARDOUR_API ResampledImportableSource : public ImportableSource
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
boost::shared_ptr<ImportableSource> source;
|
boost::shared_ptr<ImportableSource> source;
|
||||||
float* input;
|
float* _input;
|
||||||
int _src_type;
|
int _src_type;
|
||||||
SRC_STATE* src_state;
|
SRC_STATE* _src_state;
|
||||||
SRC_DATA src_data;
|
SRC_DATA _src_data;
|
||||||
|
bool _end_of_input;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ const uint32_t ResampledImportableSource::blocksize = 16384U;
|
|||||||
|
|
||||||
ResampledImportableSource::ResampledImportableSource (boost::shared_ptr<ImportableSource> src, framecnt_t rate, SrcQuality srcq)
|
ResampledImportableSource::ResampledImportableSource (boost::shared_ptr<ImportableSource> src, framecnt_t rate, SrcQuality srcq)
|
||||||
: source (src)
|
: source (src)
|
||||||
, src_state (0)
|
, _src_state (0)
|
||||||
{
|
{
|
||||||
_src_type = SRC_SINC_BEST_QUALITY;
|
_src_type = SRC_SINC_BEST_QUALITY;
|
||||||
|
|
||||||
@ -56,17 +56,17 @@ ResampledImportableSource::ResampledImportableSource (boost::shared_ptr<Importab
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
input = new float[blocksize];
|
_input = new float[blocksize];
|
||||||
|
|
||||||
seek (0);
|
seek (0);
|
||||||
|
|
||||||
src_data.src_ratio = ((float) rate) / source->samplerate();
|
_src_data.src_ratio = ((float) rate) / source->samplerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResampledImportableSource::~ResampledImportableSource ()
|
ResampledImportableSource::~ResampledImportableSource ()
|
||||||
{
|
{
|
||||||
src_state = src_delete (src_state) ;
|
_src_state = src_delete (_src_state) ;
|
||||||
delete [] input;
|
delete [] _input;
|
||||||
}
|
}
|
||||||
|
|
||||||
framecnt_t
|
framecnt_t
|
||||||
@ -75,44 +75,47 @@ ResampledImportableSource::read (Sample* output, framecnt_t nframes)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* If the input buffer is empty, refill it. */
|
/* If the input buffer is empty, refill it. */
|
||||||
|
if (_src_data.input_frames == 0) {
|
||||||
|
|
||||||
if (src_data.input_frames == 0) {
|
_src_data.input_frames = source->read (_input, blocksize);
|
||||||
|
|
||||||
src_data.input_frames = source->read (input, blocksize);
|
|
||||||
|
|
||||||
/* The last read will not be a full buffer, so set end_of_input. */
|
/* 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 < blocksize) {
|
_end_of_input = true;
|
||||||
src_data.end_of_input = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src_data.input_frames /= source->channels();
|
_src_data.input_frames /= source->channels();
|
||||||
src_data.data_in = input;
|
_src_data.data_in = _input;
|
||||||
}
|
}
|
||||||
|
|
||||||
src_data.data_out = output;
|
_src_data.data_out = output;
|
||||||
|
_src_data.output_frames = nframes / source->channels();
|
||||||
|
|
||||||
if (!src_data.end_of_input) {
|
if (_end_of_input && _src_data.input_frames * _src_data.src_ratio <= _src_data.output_frames) {
|
||||||
src_data.output_frames = nframes / source->channels();
|
/* only set src_data.end_of_input for the last cycle.
|
||||||
} else {
|
*
|
||||||
src_data.output_frames = std::min ((framecnt_t) src_data.input_frames, nframes / source->channels());
|
* The flag only affects writing out remaining data in the
|
||||||
|
* internal buffer of src_state.
|
||||||
|
* SRC is not aware of data bufered here in _src_data.input
|
||||||
|
* which needs to be processed first.
|
||||||
|
*/
|
||||||
|
_src_data.end_of_input = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = src_process (src_state, &src_data))) {
|
if ((err = src_process (_src_state, &_src_data))) {
|
||||||
error << string_compose(_("Import: %1"), src_strerror (err)) << endmsg ;
|
error << string_compose(_("Import: %1"), src_strerror (err)) << endmsg ;
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Terminate if at end */
|
/* Terminate if at end */
|
||||||
|
if (_src_data.end_of_input && _src_data.output_frames_gen == 0) {
|
||||||
if (src_data.end_of_input && src_data.output_frames_gen == 0) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
src_data.data_in += src_data.input_frames_used * source->channels();
|
_src_data.data_in += _src_data.input_frames_used * source->channels();
|
||||||
src_data.input_frames -= src_data.input_frames_used ;
|
_src_data.input_frames -= _src_data.input_frames_used ;
|
||||||
|
|
||||||
return src_data.output_frames_gen * source->channels();
|
return _src_data.output_frames_gen * source->channels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -122,20 +125,21 @@ ResampledImportableSource::seek (framepos_t pos)
|
|||||||
|
|
||||||
/* and reset things so that we start from scratch with the conversion */
|
/* and reset things so that we start from scratch with the conversion */
|
||||||
|
|
||||||
if (src_state) {
|
if (_src_state) {
|
||||||
src_delete (src_state);
|
src_delete (_src_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((src_state = src_new (_src_type, source->channels(), &err)) == 0) {
|
if ((_src_state = src_new (_src_type, source->channels(), &err)) == 0) {
|
||||||
error << string_compose(_("Import: src_new() failed : %1"), src_strerror (err)) << endmsg ;
|
error << string_compose(_("Import: src_new() failed : %1"), src_strerror (err)) << endmsg ;
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
|
|
||||||
src_data.input_frames = 0;
|
_src_data.input_frames = 0;
|
||||||
src_data.data_in = input;
|
_src_data.data_in = _input;
|
||||||
src_data.end_of_input = 0;
|
_src_data.end_of_input = 0;
|
||||||
|
_end_of_input = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
framepos_t
|
framepos_t
|
||||||
|
Loading…
Reference in New Issue
Block a user