summaryrefslogtreecommitdiff
path: root/src/lib/audio_decoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-12-18 23:43:55 +0000
committerCarl Hetherington <cth@carlh.net>2013-12-18 23:43:55 +0000
commit0b2223212b20910717d63d65517b4a8abe5d2bd4 (patch)
treeeeddca28e61a4836f207bff404a4244dfadabfa2 /src/lib/audio_decoder.cc
parentff1ab29c3ea270061a54bde529270953e14b9adc (diff)
Attempt to move resampling into AudioDecoder.
Diffstat (limited to 'src/lib/audio_decoder.cc')
-rw-r--r--src/lib/audio_decoder.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc
index 7ff8529c6..aecf39644 100644
--- a/src/lib/audio_decoder.cc
+++ b/src/lib/audio_decoder.cc
@@ -35,12 +35,33 @@ using boost::shared_ptr;
AudioDecoder::AudioDecoder (shared_ptr<const Film> film, shared_ptr<const AudioContent> content)
: Decoder (film)
, _audio_content (content)
+ , _last_audio (0)
{
-
+ if (content->output_audio_frame_rate() != content->content_audio_frame_rate() && content->audio_channels ()) {
+ _resampler.reset (new Resampler (content->content_audio_frame_rate(), content->output_audio_frame_rate(), content->audio_channels ()));
+ }
}
void
AudioDecoder::audio (shared_ptr<const AudioBuffers> data, ContentTime time)
{
+ if (_resampler) {
+ data = _resampler->run (data);
+ }
+
_pending.push_back (shared_ptr<DecodedAudio> (new DecodedAudio (data, time)));
+ _last_audio = time + (data->frames() * TIME_HZ / _audio_content->output_audio_frame_rate());
+}
+
+void
+AudioDecoder::flush ()
+{
+ if (!_resampler) {
+ return;
+ }
+
+ shared_ptr<const AudioBuffers> b = _resampler->flush ();
+ if (b) {
+ audio (b, _last_audio);
+ }
}