Rename AudioContent frame_rate methods and move resampled_audio_frame_rate into Audio...
authorCarl Hetherington <cth@carlh.net>
Fri, 2 May 2014 17:17:35 +0000 (18:17 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 2 May 2014 17:17:35 +0000 (18:17 +0100)
12 files changed:
src/lib/audio_content.cc
src/lib/audio_content.h
src/lib/audio_decoder.cc
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/lib/player.cc
src/lib/sndfile_content.cc
src/lib/sndfile_content.h
src/lib/sndfile_decoder.cc
src/wx/audio_panel.cc
test/audio_decoder_test.cc
test/frame_rate_test.cc

index c84f5713011d5a02ffd7636262eafb092a9f19e2..d9e00ff1401ca4e3335ea51c2944aff404a94fae 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -150,11 +150,11 @@ string
 AudioContent::technical_summary () const
 {
        return String::compose (
-               "audio: channels %1, length %2, raw rate %3, out rate %4",
+               "audio: channels %1, length %2, content rate %3, resampled rate %4",
                audio_channels(),
                audio_length().seconds(),
-               content_audio_frame_rate(),
-               output_audio_frame_rate()
+               audio_frame_rate(),
+               resampled_audio_frame_rate()
                );
 }
 
@@ -163,3 +163,29 @@ AudioContent::set_audio_mapping (AudioMapping)
 {
        signal_changed (AudioContentProperty::AUDIO_MAPPING);
 }
+
+/** @return the frame rate that this content should be resampled to in order
+ *  that it is in sync with the active video content at its start time.
+ */
+int
+AudioContent::resampled_audio_frame_rate () const
+{
+       shared_ptr<const Film> film = _film.lock ();
+       assert (film);
+       
+       /* Resample to a DCI-approved sample rate */
+       double t = dcp_audio_frame_rate (audio_frame_rate ());
+
+       FrameRateChange frc = film->active_frame_rate_change (position ());
+
+       /* Compensate if the DCP is being run at a different frame rate
+          to the source; that is, if the video is run such that it will
+          look different in the DCP compared to the source (slower or faster).
+       */
+
+       if (frc.change_speed) {
+               t /= frc.speed_up;
+       }
+
+       return rint (t);
+}
index 60d53b3439c0dff089d626f570fac476b998b93e..09f90b85c256c7f4327938d838a29e414219d6cc 100644 (file)
@@ -63,12 +63,13 @@ public:
        /** @return the length of the audio in the content */
        virtual ContentTime audio_length () const = 0;
        /** @return the frame rate of the content */
-       virtual int content_audio_frame_rate () const = 0;
-       virtual int output_audio_frame_rate () const = 0;
+       virtual int audio_frame_rate () const = 0;
        virtual AudioMapping audio_mapping () const = 0;
        virtual void set_audio_mapping (AudioMapping);
        virtual boost::filesystem::path audio_analysis_path () const;
 
+       int resampled_audio_frame_rate () const;
+
        boost::signals2::connection analyse_audio (boost::function<void()>);
 
        void set_audio_gain (float);
index f914ecf8a7a2145a9a80c3251758a5345911000e..4a543cea9351af00cf652b6bcfd755ad013d2860 100644 (file)
@@ -39,8 +39,8 @@ using boost::shared_ptr;
 AudioDecoder::AudioDecoder (shared_ptr<const AudioContent> content)
        : _audio_content (content)
 {
-       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 ()));
+       if (content->resampled_audio_frame_rate() != content->audio_frame_rate() && content->audio_channels ()) {
+               _resampler.reset (new Resampler (content->audio_frame_rate(), content->resampled_audio_frame_rate(), content->audio_channels ()));
        }
 
        reset_decoded_audio ();
@@ -61,7 +61,7 @@ AudioDecoder::get_audio (AudioFrame frame, AudioFrame length, bool accurate)
                
        if (frame < _decoded_audio.frame || end > (_decoded_audio.frame + length * 4)) {
                /* Either we have no decoded data, or what we do have is a long way from what we want: seek */
-               seek (ContentTime::from_frames (frame, _audio_content->content_audio_frame_rate()), accurate);
+               seek (ContentTime::from_frames (frame, _audio_content->audio_frame_rate()), accurate);
        }
 
        /* Offset of the data that we want from the start of _decoded_audio.audio
@@ -126,7 +126,7 @@ AudioDecoder::audio (shared_ptr<const AudioBuffers> data, ContentTime time)
        }
 
        if (!_audio_position) {
-               _audio_position = time.frames (_audio_content->output_audio_frame_rate ());
+               _audio_position = time.frames (_audio_content->resampled_audio_frame_rate ());
        }
 
        assert (_audio_position.get() >= (_decoded_audio.frame + _decoded_audio.audio->frames()));
index 4e14802e8a9a7e5b0aee5e6703069338f1bbc0cd..a51cb3de805cdcdefe8910e9c8bade812601441d 100644 (file)
@@ -288,7 +288,7 @@ FFmpegContent::audio_channels () const
 }
 
 int
-FFmpegContent::content_audio_frame_rate () const
+FFmpegContent::audio_frame_rate () const
 {
        boost::mutex::scoped_lock lm (_mutex);
 
@@ -299,29 +299,6 @@ FFmpegContent::content_audio_frame_rate () const
        return _audio_stream->frame_rate;
 }
 
-int
-FFmpegContent::output_audio_frame_rate () const
-{
-       shared_ptr<const Film> film = _film.lock ();
-       assert (film);
-       
-       /* Resample to a DCI-approved sample rate */
-       double t = dcp_audio_frame_rate (content_audio_frame_rate ());
-
-       FrameRateChange frc (video_frame_rate(), film->video_frame_rate());
-
-       /* Compensate if the DCP is being run at a different frame rate
-          to the source; that is, if the video is run such that it will
-          look different in the DCP compared to the source (slower or faster).
-       */
-
-       if (frc.change_speed) {
-               t /= frc.speed_up;
-       }
-
-       return rint (t);
-}
-
 bool
 operator== (FFmpegStream const & a, FFmpegStream const & b)
 {
index d86c90af904b3650539f67c854fbeb2c8010562d..1ab0a92d0ed2f89dc329d66a0b392581a499af5c 100644 (file)
@@ -146,8 +146,7 @@ public:
        /* AudioContent */
        int audio_channels () const;
        ContentTime audio_length () const;
-       int content_audio_frame_rate () const;
-       int output_audio_frame_rate () const;
+       int audio_frame_rate () const;
        AudioMapping audio_mapping () const;
        void set_audio_mapping (AudioMapping);
        boost::filesystem::path audio_analysis_path () const;
index 5fe35e34d736ed455cada873eac294d925c5f6fa..75b5500936f9bf56fd7cb5a6bcd41ce61983bd2f 100644 (file)
@@ -439,7 +439,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
                shared_ptr<AudioDecoder> decoder = dynamic_pointer_cast<AudioDecoder> ((*i)->decoder);
                assert (decoder);
 
-               if (content->content_audio_frame_rate() == 0) {
+               if (content->audio_frame_rate() == 0) {
                        /* This AudioContent has no audio (e.g. if it is an FFmpegContent with no
                         * audio stream).
                         */
index 5b408f2da564ddc2fcec0ebd01c6b073a4222ae6..0cf65967f2172ac1f8ad7d57a6a648cfcd05a45d 100644 (file)
@@ -80,8 +80,8 @@ SndfileContent::information () const
        s << String::compose (
                _("%1 channels, %2kHz, %3 samples"),
                audio_channels(),
-               content_audio_frame_rate() / 1000.0,
-               audio_length().frames (content_audio_frame_rate ())
+               audio_frame_rate() / 1000.0,
+               audio_length().frames (audio_frame_rate ())
                );
        
        return s.str ();
@@ -134,7 +134,7 @@ SndfileContent::as_xml (xmlpp::Node* node) const
 
        node->add_child("AudioChannels")->add_child_text (lexical_cast<string> (audio_channels ()));
        node->add_child("AudioLength")->add_child_text (lexical_cast<string> (audio_length().get ()));
-       node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (content_audio_frame_rate ()));
+       node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (audio_frame_rate ()));
        _audio_mapping.as_xml (node->add_child("AudioMapping"));
 }
 
@@ -146,15 +146,6 @@ SndfileContent::full_length () const
        return DCPTime (audio_length(), film->active_frame_rate_change (position ()));
 }
 
-int
-SndfileContent::output_audio_frame_rate () const
-{
-       shared_ptr<const Film> film = _film.lock ();
-       assert (film);
-       
-       return film->audio_frame_rate ();
-}
-
 void
 SndfileContent::set_audio_mapping (AudioMapping m)
 {
index 04d157131843470640dd0567b675d6521d1b116c..bbc5111ffa8184747b22c887e808f80e74f92d62 100644 (file)
@@ -57,13 +57,11 @@ public:
                return _audio_length;
        }
        
-       int content_audio_frame_rate () const {
+       int audio_frame_rate () const {
                boost::mutex::scoped_lock lm (_mutex);
                return _audio_frame_rate;
        }
 
-       int output_audio_frame_rate () const;
-
        AudioMapping audio_mapping () const {
                boost::mutex::scoped_lock lm (_mutex);
                return _audio_mapping;
index c37a8447483ba49d3e39ade148d08ebfd26f6841..602014d5883d2dba1381588bb44a7036debc9c96 100644 (file)
@@ -74,7 +74,7 @@ SndfileDecoder::pass ()
        /* Do things in half second blocks as I think there may be limits
           to what FFmpeg (and in particular the resampler) can cope with.
        */
-       sf_count_t const block = _sndfile_content->content_audio_frame_rate() / 2;
+       sf_count_t const block = _sndfile_content->audio_frame_rate() / 2;
        sf_count_t const this_time = min (block, _remaining);
 
        int const channels = _sndfile_content->audio_channels ();
index 1c679d336c003fc7404f64ddff9b55cc88d46eec..eb95e17abe59db17dca28b496b5025edd22a3a5f 100644 (file)
@@ -237,7 +237,7 @@ AudioPanel::setup_stream_description ()
                } else {
                        s << fcs->audio_channels() << wxT (" ") << _("channels");
                }
-               s << wxT (", ") << fcs->content_audio_frame_rate() << _("Hz");
+               s << wxT (", ") << fcs->audio_frame_rate() << _("Hz");
                _description->SetLabel (s);
        }
 }
index 46f9d5ac63163894dc9dfd9849bee6a30306f2b4..a14e2f9be0ace14299c1c6d756828699af53236c 100644 (file)
@@ -44,7 +44,7 @@ public:
        {
                AudioFrame const N = min (
                        AudioFrame (2000),
-                       _audio_content->audio_length().frames (_audio_content->output_audio_frame_rate ()) - _position
+                       _audio_content->audio_length().frames (_audio_content->resampled_audio_frame_rate ()) - _position
                        );
 
                shared_ptr<AudioBuffers> buffers (new AudioBuffers (_audio_content->audio_channels(), N));
@@ -54,7 +54,7 @@ public:
                        }
                }
 
-               audio (buffers, ContentTime::from_frames (_position, _audio_content->output_audio_frame_rate ()));
+               audio (buffers, ContentTime::from_frames (_position, _audio_content->resampled_audio_frame_rate ()));
                _position += N;
 
                return N < 2000;
@@ -63,7 +63,7 @@ public:
        void seek (ContentTime t, bool accurate)
        {
                AudioDecoder::seek (t, accurate);
-               _position = t.frames (_audio_content->output_audio_frame_rate ());
+               _position = t.frames (_audio_content->resampled_audio_frame_rate ());
        }
 
 private:
@@ -98,11 +98,7 @@ public:
                return ContentTime::from_seconds (61.2942);
        }
 
-       int content_audio_frame_rate () const {
-               return 48000;
-       }
-
-       int output_audio_frame_rate () const {
+       int audio_frame_rate () const {
                return 48000;
        }
 
@@ -119,7 +115,7 @@ shared_ptr<TestAudioDecoder> decoder;
 static shared_ptr<ContentAudio>
 get (AudioFrame from, AudioFrame length)
 {
-       decoder->seek (ContentTime::from_frames (from, content->output_audio_frame_rate ()), true);
+       decoder->seek (ContentTime::from_frames (from, content->resampled_audio_frame_rate ()), true);
        shared_ptr<ContentAudio> ca = decoder->get_audio (from, length, true);
        BOOST_CHECK_EQUAL (ca->frame, from);
        return ca;
@@ -152,8 +148,8 @@ BOOST_AUTO_TEST_CASE (audio_decoder_get_audio_test)
 
        /* Read off the end */
 
-       AudioFrame const from = content->output_audio_frame_rate() * 61;
-       AudioFrame const length = content->output_audio_frame_rate() * 4;
+       AudioFrame const from = content->resampled_audio_frame_rate() * 61;
+       AudioFrame const length = content->resampled_audio_frame_rate() * 4;
        shared_ptr<ContentAudio> ca = get (from, length);
        
        for (int i = 0; i < content->audio_channels(); ++i) {
index e710b09341e2d53f38ef71399bd0f4236474d908..f2c46396cb36205dffb825ead6fcac1f1cb86bc9 100644 (file)
@@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
        shared_ptr<Film> film = new_test_film ("audio_sampling_rate_test");
        /* Get any piece of content, it doesn't matter what */
        shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
-       film->add_content (content);
+       film->examine_and_add_content (content);
        wait_for_jobs ();
        
        std::list<int> afr;
@@ -253,43 +253,43 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
        content->_video_frame_rate = 24;
        film->set_video_frame_rate (24);
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000);
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 48000);
 
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0)));
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 48000);
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 48000);
 
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 80000, 0)));
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 96000);
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 96000);
 
        content->_video_frame_rate = 23.976;
        film->set_video_frame_rate (24);
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952);
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 47952);
 
        content->_video_frame_rate = 29.97;
        film->set_video_frame_rate (30);
        BOOST_CHECK_EQUAL (film->video_frame_rate (), 30);
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 47952);
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 47952);
 
        content->_video_frame_rate = 25;
        film->set_video_frame_rate (24);
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000);
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 50000);
 
        content->_video_frame_rate = 25;
        film->set_video_frame_rate (24);
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0)));
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), 50000);
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), 50000);
 
        /* Check some out-there conversions (not the best) */
        
        content->_video_frame_rate = 14.99;
        film->set_video_frame_rate (25);
        content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 16000, 0)));
-       /* The FrameRateChange within output_audio_frame_rate should choose to double-up
+       /* The FrameRateChange within resampled_audio_frame_rate should choose to double-up
           the 14.99 fps video to 30 and then run it slow at 25.
        */
-       BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25));
+       BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25));
 }