Cleanup: extract pass_audio().
authorCarl Hetherington <cth@carlh.net>
Mon, 13 Feb 2023 22:20:51 +0000 (23:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 Feb 2023 22:20:51 +0000 (23:20 +0100)
src/lib/dcp_decoder.cc
src/lib/dcp_decoder.h

index 3bcb52902534bf68882411ae10076ac74f2dd8c4..1dc37d38492b73a9c20d7ad146f2ae15940b71ec 100644 (file)
@@ -183,6 +183,28 @@ DCPDecoder::pass_video(Frame frame, dcp::Size size)
 }
 
 
+void
+DCPDecoder::pass_audio(Frame frame, double video_frame_rate)
+{
+       auto const entry_point = (*_reel)->main_sound()->entry_point().get_value_or(0);
+       auto sf = _sound_reader->get_frame (entry_point + frame);
+       auto from = sf->data ();
+
+       int const channels = _dcp_content->audio->stream()->channels ();
+       int const frames = sf->size() / (3 * channels);
+       auto data = make_shared<AudioBuffers>(channels, frames);
+       auto data_data = data->data();
+       for (int i = 0; i < frames; ++i) {
+               for (int j = 0; j < channels; ++j) {
+                       data_data[j][i] = static_cast<int> ((from[0] << 8) | (from[1] << 16) | (from[2] << 24)) / static_cast<float> (INT_MAX - 256);
+                       from += 3;
+               }
+       }
+
+       audio->emit(film(), _dcp_content->audio->stream(), data, ContentTime::from_frames(_offset, video_frame_rate) + _next);
+}
+
+
 Decoder::PassResult
 DCPDecoder::pass ()
 {
@@ -215,22 +237,7 @@ DCPDecoder::pass ()
        }
 
        if (_sound_reader && (_decode_referenced || !_dcp_content->reference_audio())) {
-               auto const entry_point = (*_reel)->main_sound()->entry_point().get_value_or(0);
-               auto sf = _sound_reader->get_frame (entry_point + frame);
-               auto from = sf->data ();
-
-               int const channels = _dcp_content->audio->stream()->channels ();
-               int const frames = sf->size() / (3 * channels);
-               auto data = make_shared<AudioBuffers>(channels, frames);
-               auto data_data = data->data();
-               for (int i = 0; i < frames; ++i) {
-                       for (int j = 0; j < channels; ++j) {
-                               data_data[j][i] = static_cast<int> ((from[0] << 8) | (from[1] << 16) | (from[2] << 24)) / static_cast<float> (INT_MAX - 256);
-                               from += 3;
-                       }
-               }
-
-               audio->emit (film(), _dcp_content->audio->stream(), data, ContentTime::from_frames (_offset, vfr) + _next);
+               pass_audio(frame, vfr);
        }
 
        if (_atmos_reader) {
index 3dc3d323cd282a95725cf293eace70eed93b1e51..dfe941eb0e7aeacba3c560ef1cc3c40799793f43 100644 (file)
@@ -74,6 +74,7 @@ private:
        void next_reel ();
        void get_readers ();
        void pass_video(Frame frame, dcp::Size size);
+       void pass_audio(Frame frame, double video_frame_rate);
        void pass_texts (dcpomatic::ContentTime next, dcp::Size size);
        void pass_texts (
                dcpomatic::ContentTime next,