summaryrefslogtreecommitdiff
path: root/libs/ardour/resampled_source.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-04-09 14:11:47 +0000
committerCarl Hetherington <carl@carlh.net>2010-04-09 14:11:47 +0000
commitf4ac9430f3fc2c405334f3f02fe08a5782454396 (patch)
tree2858264db409fc1bfe778554f86100f01c1f0b3d /libs/ardour/resampled_source.cc
parent77c09fc8248160ab60e2e229710d07934fe08894 (diff)
Prevent clipping during the import of files from sources that have
amplitudes greater than 1 when data is being stored in files that are clamped. e.g. when importing hot sources and resampling them when the session file format is integer. git-svn-id: svn://localhost/ardour2/branches/3.0@6879 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/resampled_source.cc')
-rw-r--r--libs/ardour/resampled_source.cc60
1 files changed, 34 insertions, 26 deletions
diff --git a/libs/ardour/resampled_source.cc b/libs/ardour/resampled_source.cc
index 57811312f1..675a0e426d 100644
--- a/libs/ardour/resampled_source.cc
+++ b/libs/ardour/resampled_source.cc
@@ -30,48 +30,33 @@ const uint32_t ResampledImportableSource::blocksize = 16384U;
ResampledImportableSource::ResampledImportableSource (boost::shared_ptr<ImportableSource> src, nframes_t rate, SrcQuality srcq)
: source (src)
+ , src_state (0)
{
- int err;
-
- source->seek (0);
-
- /* Initialize the sample rate converter. */
-
- int src_type = SRC_SINC_BEST_QUALITY;
+ _src_type = SRC_SINC_BEST_QUALITY;
switch (srcq) {
case SrcBest:
- src_type = SRC_SINC_BEST_QUALITY;
+ _src_type = SRC_SINC_BEST_QUALITY;
break;
case SrcGood:
- src_type = SRC_SINC_MEDIUM_QUALITY;
+ _src_type = SRC_SINC_MEDIUM_QUALITY;
break;
case SrcQuick:
- src_type = SRC_SINC_FASTEST;
+ _src_type = SRC_SINC_FASTEST;
break;
case SrcFast:
- src_type = SRC_ZERO_ORDER_HOLD;
+ _src_type = SRC_ZERO_ORDER_HOLD;
break;
case SrcFastest:
- src_type = SRC_LINEAR;
+ _src_type = SRC_LINEAR;
break;
}
- if ((src_state = src_new (src_type, source->channels(), &err)) == 0) {
- error << string_compose(_("Import: src_new() failed : %1"), src_strerror (err)) << endmsg ;
- throw failed_constructor ();
- }
-
- src_data.end_of_input = 0 ; /* Set this later. */
-
- /* Start with zero to force load in while loop. */
-
- src_data.input_frames = 0 ;
- src_data.data_in = input ;
+ input = new float[blocksize];
+ seek (0);
+
src_data.src_ratio = ((float) rate) / source->samplerate();
-
- input = new float[blocksize];
}
ResampledImportableSource::~ResampledImportableSource ()
@@ -106,7 +91,7 @@ ResampledImportableSource::read (Sample* output, nframes_t nframes)
if (!src_data.end_of_input) {
src_data.output_frames = nframes / source->channels();
} else {
- src_data.output_frames = src_data.input_frames;
+ src_data.output_frames = std::min ((nframes_t) src_data.input_frames, nframes / source->channels());
}
if ((err = src_process (src_state, &src_data))) {
@@ -126,3 +111,26 @@ ResampledImportableSource::read (Sample* output, nframes_t nframes)
return src_data.output_frames_gen * source->channels();
}
+void
+ResampledImportableSource::seek (nframes_t pos)
+{
+ source->seek (pos);
+
+ /* and reset things so that we start from scratch with the conversion */
+
+ if (src_state) {
+ src_delete (src_state);
+ }
+
+ int err;
+
+ if ((src_state = src_new (_src_type, source->channels(), &err)) == 0) {
+ error << string_compose(_("Import: src_new() failed : %1"), src_strerror (err)) << endmsg ;
+ throw failed_constructor ();
+ }
+
+ src_data.input_frames = 0;
+ src_data.data_in = input;
+ src_data.end_of_input = 0;
+}
+