+ float progress_multiplier = 1;
+ float progress_base = 0;
+
+ if (!source->clamped_at_unity() && s->clamped_at_unity()) {
+
+ /* The source we are importing from can return sample values with a magnitude greater than 1,
+ and the file we are writing the imported data to cannot handle such values. Compute the gain
+ factor required to normalize the input sources to have a magnitude of less than 1.
+ */
+
+ float peak = 0;
+ uint read_count = 0;
+
+ while (!status.cancel) {
+ framecnt_t const nread = source->read (data.get(), nframes);
+ if (nread == 0) {
+ break;
+ }
+
+ peak = compute_peak (data.get(), nread, peak);
+
+ read_count += nread;
+ status.progress = 0.5 * read_count / (source->ratio() * source->length() * channels);
+ }
+
+ if (peak >= 1) {
+ /* we are out of range: compute a gain to fix it */
+ gain = (1 - FLT_EPSILON) / peak;
+ }
+
+ source->seek (0);
+ progress_multiplier = 0.5;
+ progress_base = 0.5;
+ }
+
+ uint read_count = 0;