2 Copyright (C) 2013-2016 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/>.
21 #include "sndfile_content.h"
22 #include "sndfile_decoder.h"
23 #include "sndfile_examiner.h"
24 #include "audio_content.h"
26 #include "compose.hpp"
29 #include "safe_stringstream.h"
30 #include "raw_convert.h"
31 #include <libcxml/cxml.h>
32 #include <libxml++/libxml++.h>
40 using boost::shared_ptr;
42 SndfileContent::SndfileContent (shared_ptr<const Film> film, boost::filesystem::path p)
45 audio.reset (new AudioContent (this));
48 SndfileContent::SndfileContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
49 : Content (film, node)
51 audio = AudioContent::from_xml (this, node);
57 node->number_child<int> ("AudioFrameRate"),
58 node->number_child<Frame> ("AudioLength"),
59 AudioMapping (node->node_child ("AudioMapping"), version)
67 SndfileContent::as_xml (xmlpp::Node* node) const
69 node->add_child("Type")->add_child_text ("Sndfile");
71 Content::as_xml (node);
75 node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio->stream()->frame_rate ()));
76 node->add_child("AudioLength")->add_child_text (raw_convert<string> (audio->stream()->length ()));
77 audio->stream()->mapping().as_xml (node->add_child("AudioMapping"));
83 SndfileContent::summary () const
85 /* Get the string() here so that the name does not have quotes around it */
86 return String::compose (_("%1 [audio]"), path_summary ());
90 SndfileContent::technical_summary () const
92 return Content::technical_summary() + " - "
93 + audio->technical_summary ()
98 SndfileContent::valid_file (boost::filesystem::path f)
100 /* XXX: more extensions */
101 string ext = f.extension().string();
102 transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
103 return (ext == ".wav" || ext == ".w64" || ext == ".flac" || ext == ".aif" || ext == ".aiff");
107 SndfileContent::examine (shared_ptr<Job> job)
109 job->set_progress_unknown ();
110 Content::examine (job);
111 shared_ptr<AudioExaminer> ex (new SndfileExaminer (shared_from_this ()));
114 boost::mutex::scoped_lock lm (_mutex);
115 AudioStreamPtr as (new AudioStream (ex->audio_frame_rate(), ex->audio_length(), ex->audio_channels ()));
116 audio->set_stream (as);
117 AudioMapping m = as->mapping ();
118 film()->make_audio_mapping_default (m);
122 signal_changed (AudioContentProperty::STREAMS);
126 SndfileContent::full_length () const
128 FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
129 return DCPTime::from_frames (audio->stream()->length() / frc.speed_up, audio->stream()->frame_rate ());