2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file src/lib/audio_content.h
23 * @brief AudioContent and AudioContentProperty classes.
27 #ifndef DCPOMATIC_AUDIO_CONTENT_H
28 #define DCPOMATIC_AUDIO_CONTENT_H
31 #include "audio_mapping.h"
32 #include "audio_stream.h"
33 #include "content_part.h"
34 #include "named_channel.h"
37 /** @class AudioContentProperty
38 * @brief Names for properties of AudioContent.
40 class AudioContentProperty
43 static int const STREAMS;
44 static int const GAIN;
45 static int const DELAY;
46 static int const FADE_IN;
47 static int const FADE_OUT;
48 static int const USE_SAME_FADES_AS_VIDEO;
52 class AudioContent : public ContentPart
55 explicit AudioContent (Content* parent);
56 AudioContent (Content* parent, std::vector<std::shared_ptr<Content>>);
57 AudioContent (Content* parent, cxml::ConstNodePtr);
59 void as_xml (xmlpp::Node *) const;
60 std::string technical_summary () const;
61 void take_settings_from (std::shared_ptr<const AudioContent> c);
63 AudioMapping mapping () const;
64 void set_mapping (AudioMapping);
65 int resampled_frame_rate (std::shared_ptr<const Film> film) const;
66 std::vector<NamedChannel> channel_names () const;
69 void set_gain (double);
70 /** Set delay in milliseconds (positive moves audio later) */
73 double gain () const {
74 boost::mutex::scoped_lock lm (_mutex);
79 boost::mutex::scoped_lock lm (_mutex);
83 dcpomatic::ContentTime fade_in () const;
84 dcpomatic::ContentTime fade_out () const;
86 void set_fade_in (dcpomatic::ContentTime time);
87 void set_fade_out (dcpomatic::ContentTime time);
88 void set_use_same_fades_as_video (bool s);
90 std::string processing_description (std::shared_ptr<const Film> film) const;
92 std::vector<AudioStreamPtr> streams () const {
93 boost::mutex::scoped_lock lm (_mutex);
97 void add_stream (AudioStreamPtr stream);
98 void set_stream (AudioStreamPtr stream);
99 AudioStreamPtr stream () const;
101 void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty> &) const;
103 void modify_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
104 void modify_trim_start(std::shared_ptr<const Film> film, dcpomatic::ContentTime& pos) const;
106 /** @param frame frame within the whole (untrimmed) content.
107 * @param frame_rate The frame rate of the audio (it may have been resampled).
108 * @return a fade coefficient for @ref length samples starting at an offset @frame within
109 * the content, or an empty vector if the given section has no fade.
111 std::vector<float> fade (AudioStreamPtr stream, Frame frame, Frame length, int frame_rate) const;
113 static std::shared_ptr<AudioContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
117 /** Gain to apply to audio in dB */
119 /** Delay to apply to audio (positive moves audio later) in milliseconds */
121 dcpomatic::ContentTime _fade_in;
122 dcpomatic::ContentTime _fade_out;
123 bool _use_same_fades_as_video = false;
124 std::vector<AudioStreamPtr> _streams;