2 Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "sndfile_content.h"
21 #include "sndfile_decoder.h"
22 #include "sndfile_examiner.h"
23 #include "audio_content.h"
25 #include "compose.hpp"
28 #include "safe_stringstream.h"
29 #include "raw_convert.h"
30 #include <libcxml/cxml.h>
31 #include <libxml++/libxml++.h>
39 using boost::shared_ptr;
41 SndfileContent::SndfileContent (shared_ptr<const Film> film, boost::filesystem::path p)
44 audio.reset (new AudioContent (this, film));
47 SndfileContent::SndfileContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
48 : Content (film, node)
49 , _audio_length (node->number_child<Frame> ("AudioLength"))
51 audio.reset (new AudioContent (this, film, node));
54 new AudioStream (node->number_child<int> ("AudioFrameRate"), AudioMapping (node->node_child ("AudioMapping"), version)))
59 SndfileContent::as_xml (xmlpp::Node* node) const
61 node->add_child("Type")->add_child_text ("Sndfile");
62 Content::as_xml (node);
64 node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio->stream()->frame_rate ()));
65 audio->stream()->mapping().as_xml (node->add_child("AudioMapping"));
66 node->add_child("AudioLength")->add_child_text (raw_convert<string> (audio_length ()));
71 SndfileContent::summary () const
73 /* Get the string() here so that the name does not have quotes around it */
74 return String::compose (_("%1 [audio]"), path_summary ());
78 SndfileContent::technical_summary () const
80 return Content::technical_summary() + " - "
81 + audio->technical_summary ()
86 SndfileContent::valid_file (boost::filesystem::path f)
88 /* XXX: more extensions */
89 string ext = f.extension().string();
90 transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
91 return (ext == ".wav" || ext == ".w64" || ext == ".flac" || ext == ".aif" || ext == ".aiff");
95 SndfileContent::examine (shared_ptr<Job> job)
97 job->set_progress_unknown ();
98 Content::examine (job);
99 shared_ptr<AudioExaminer> ex (new SndfileExaminer (shared_from_this ()));
102 boost::mutex::scoped_lock lm (_mutex);
103 AudioStreamPtr as (new AudioStream (ex->audio_frame_rate(), ex->audio_channels ()));
104 audio->set_stream (as);
105 AudioMapping m = as->mapping ();
106 film()->make_audio_mapping_default (m);
108 _audio_length = ex->audio_length ();
111 signal_changed (AudioContentProperty::STREAMS);
115 SndfileContent::full_length () const
117 FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
118 return DCPTime::from_frames (audio_length() / frc.speed_up, audio->stream()->frame_rate ());