{
}
-#if 0
-void
-AudioDecoder::process_end ()
-{
- if (_swr_context) {
-
- shared_ptr<const Film> film = _film.lock ();
- assert (film);
-
- shared_ptr<AudioBuffers> out (new AudioBuffers (film->audio_mapping().dcp_channels(), 256));
-
- while (1) {
- int const frames = swr_convert (_swr_context, (uint8_t **) out->data(), 256, 0, 0);
-
- if (frames < 0) {
- throw EncodeError (_("could not run sample-rate converter"));
- }
-
- if (frames == 0) {
- break;
- }
-
- out->set_frames (frames);
- _writer->write (out);
- }
-
- }
-}
-#endif
-
void
AudioDecoder::audio (shared_ptr<const AudioBuffers> data, AudioContent::Frame frame)
{
assert (content);
if (content->content_audio_frame_rate() != content->output_audio_frame_rate()) {
- audio = resampler(content)->run (audio);
+ shared_ptr<Resampler> r = resampler (content);
+ audio = r->run (audio);
+ _last_resampler = r;
+ } else {
+ _last_resampler.reset ();
}
/* Remap channels */
_audio_buffers.set_frames (0);
}
+ if (_last_resampler) {
+ shared_ptr<const AudioBuffers> resamp = _last_resampler->flush ();
+ Audio (resamp, _audio_position);
+ _audio_position += _film->audio_frames_to_time (resamp->frames ());
+ }
+
while (_video_position < _audio_position) {
emit_black ();
}
libdcp::Size _video_container_size;
boost::shared_ptr<Image> _black_frame;
std::map<boost::shared_ptr<AudioContent>, boost::shared_ptr<Resampler> > _resamplers;
+ boost::shared_ptr<Resampler> _last_resampler;
struct {
boost::weak_ptr<Piece> piece;
resampled->set_frames (resampled_frames);
return resampled;
}
+
+shared_ptr<const AudioBuffers>
+Resampler::flush ()
+{
+ shared_ptr<AudioBuffers> out (new AudioBuffers (_channels, 0));
+ int out_offset = 0;
+ int64_t const pass_size = 256;
+ shared_ptr<AudioBuffers> pass (new AudioBuffers (_channels, 256));
+
+ while (1) {
+ int const frames = swr_convert (_swr_context, (uint8_t **) pass->data(), pass_size, 0, 0);
+
+ if (frames < 0) {
+ throw EncodeError (_("could not run sample-rate converter"));
+ }
+
+ if (frames == 0) {
+ break;
+ }
+
+ out->ensure_size (out_offset + frames);
+ out->copy_from (pass.get(), frames, 0, out_offset);
+ out_offset += frames;
+ out->set_frames (out_offset);
+ }
+
+ return out;
+}
~Resampler ();
boost::shared_ptr<const AudioBuffers> run (boost::shared_ptr<const AudioBuffers>);
+ boost::shared_ptr<const AudioBuffers> flush ();
private:
SwrContext* _swr_context;