- out->ensure_size (out_offset + frames);
- out->copy_from (pass.get(), frames, 0, out_offset);
- out_offset += frames;
- out->set_frames (out_offset);
+ resampled->ensure_size (out_offset + data.output_frames_gen);
+ resampled->set_frames (out_offset + data.output_frames_gen);
+
+ {
+ auto p = data.data_out;
+ auto q = resampled->data ();
+ for (int i = 0; i < data.output_frames_gen; ++i) {
+ for (int j = 0; j < _channels; ++j) {
+ q[j][out_offset + i] = *p++;
+ }
+ }
+ }
+
+ in_frames -= data.input_frames_used;
+ in_offset += data.input_frames_used;
+ out_offset += data.output_frames_gen;
+ }
+
+ return resampled;
+}
+
+
+shared_ptr<const AudioBuffers>
+Resampler::flush ()
+{
+ auto out = make_shared<AudioBuffers>(_channels, 0);
+ int out_offset = 0;
+ int64_t const output_size = 65536;
+
+ float dummy[1];
+ std::vector<float> buffer(output_size);
+
+ SRC_DATA data;
+ data.data_in = dummy;
+ data.input_frames = 0;
+ data.data_out = buffer.data();
+ data.output_frames = output_size;
+ data.end_of_input = 1;
+ data.src_ratio = double (_out_rate) / _in_rate;
+
+ int const r = src_process (_src, &data);
+ if (r) {
+ throw EncodeError (String::compose(N_("could not run sample-rate converter (%1)"), src_strerror(r)));
+ }
+
+ out->ensure_size (out_offset + data.output_frames_gen);
+
+ auto p = data.data_out;
+ auto q = out->data ();
+ for (int i = 0; i < data.output_frames_gen; ++i) {
+ for (int j = 0; j < _channels; ++j) {
+ q[j][out_offset + i] = *p++;
+ }