summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-11 12:57:53 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-11 12:57:53 +0100
commit49deab5be257f3a11f5b053224f4a3218fad8da3 (patch)
treeedb4593b33d2a062614cdfaba9cc96d4aab8c1ed /src/lib
parentcb2d996875db099ce456c18e9751f5dfe3d9056d (diff)
Untested flushing of resamplers.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_decoder.cc30
-rw-r--r--src/lib/player.cc12
-rw-r--r--src/lib/player.h1
-rw-r--r--src/lib/resampler.cc28
-rw-r--r--src/lib/resampler.h1
5 files changed, 41 insertions, 31 deletions
diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc
index dc49a1846..ade11cc32 100644
--- a/src/lib/audio_decoder.cc
+++ b/src/lib/audio_decoder.cc
@@ -37,36 +37,6 @@ AudioDecoder::AudioDecoder (shared_ptr<const Film> f)
{
}
-#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)
{
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 467f92374..18c42296f 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -261,7 +261,11 @@ Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers
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 */
@@ -313,6 +317,12 @@ Player::flush ()
_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 ();
}
diff --git a/src/lib/player.h b/src/lib/player.h
index 5a4ee97be..b3eadd7c0 100644
--- a/src/lib/player.h
+++ b/src/lib/player.h
@@ -110,6 +110,7 @@ private:
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;
diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc
index 1235b9038..ebb507cb1 100644
--- a/src/lib/resampler.cc
+++ b/src/lib/resampler.cc
@@ -59,3 +59,31 @@ Resampler::run (shared_ptr<const AudioBuffers> in)
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;
+}
diff --git a/src/lib/resampler.h b/src/lib/resampler.h
index cda718934..21979846e 100644
--- a/src/lib/resampler.h
+++ b/src/lib/resampler.h
@@ -12,6 +12,7 @@ public:
~Resampler ();
boost::shared_ptr<const AudioBuffers> run (boost::shared_ptr<const AudioBuffers>);
+ boost::shared_ptr<const AudioBuffers> flush ();
private:
SwrContext* _swr_context;