2 Copyright (C) 2013-2014 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 <libcxml/cxml.h>
21 #include "sndfile_content.h"
22 #include "sndfile_decoder.h"
24 #include "compose.hpp"
31 using std::stringstream;
33 using boost::shared_ptr;
34 using boost::lexical_cast;
36 SndfileContent::SndfileContent (shared_ptr<const Film> f, boost::filesystem::path p)
41 , _audio_frame_rate (0)
46 SndfileContent::SndfileContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node, int version)
48 , AudioContent (f, node)
49 , _audio_mapping (node->node_child ("AudioMapping"), version)
51 _audio_channels = node->number_child<int> ("AudioChannels");
52 _audio_length = ContentTime (node->number_child<int64_t> ("AudioLength"));
53 _audio_frame_rate = node->number_child<int> ("AudioFrameRate");
57 SndfileContent::summary () const
59 /* Get the string() here so that the name does not have quotes around it */
60 return String::compose (_("%1 [audio]"), path_summary ());
64 SndfileContent::technical_summary () const
66 return Content::technical_summary() + " - "
67 + AudioContent::technical_summary ()
72 SndfileContent::information () const
74 if (_audio_frame_rate == 0) {
80 s << String::compose (
81 _("%1 channels, %2kHz, %3 samples"),
83 content_audio_frame_rate() / 1000.0,
84 audio_length().frames (content_audio_frame_rate ())
91 SndfileContent::valid_file (boost::filesystem::path f)
93 /* XXX: more extensions */
94 string ext = f.extension().string();
95 transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
96 return (ext == ".wav" || ext == ".aif" || ext == ".aiff");
100 SndfileContent::examine (shared_ptr<Job> job)
102 job->set_progress_unknown ();
103 Content::examine (job);
105 SndfileDecoder dec (shared_from_this());
108 boost::mutex::scoped_lock lm (_mutex);
109 _audio_channels = dec.audio_channels ();
110 _audio_length = dec.audio_length ();
111 _audio_frame_rate = dec.audio_frame_rate ();
114 signal_changed (AudioContentProperty::AUDIO_CHANNELS);
115 signal_changed (AudioContentProperty::AUDIO_LENGTH);
116 signal_changed (AudioContentProperty::AUDIO_FRAME_RATE);
119 boost::mutex::scoped_lock lm (_mutex);
120 /* XXX: do this in signal_changed...? */
121 _audio_mapping = AudioMapping (_audio_channels);
122 _audio_mapping.make_default ();
125 signal_changed (AudioContentProperty::AUDIO_MAPPING);
129 SndfileContent::as_xml (xmlpp::Node* node) const
131 node->add_child("Type")->add_child_text ("Sndfile");
132 Content::as_xml (node);
133 AudioContent::as_xml (node);
135 node->add_child("AudioChannels")->add_child_text (lexical_cast<string> (audio_channels ()));
136 node->add_child("AudioLength")->add_child_text (lexical_cast<string> (audio_length().get ()));
137 node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (content_audio_frame_rate ()));
138 _audio_mapping.as_xml (node->add_child("AudioMapping"));
142 SndfileContent::full_length () const
144 shared_ptr<const Film> film = _film.lock ();
146 return DCPTime (audio_length(), film->active_frame_rate_change (position ()));
150 SndfileContent::output_audio_frame_rate () const
152 shared_ptr<const Film> film = _film.lock ();
155 return film->audio_frame_rate ();
159 SndfileContent::set_audio_mapping (AudioMapping m)
162 boost::mutex::scoped_lock lm (_mutex);
166 signal_changed (AudioContentProperty::AUDIO_MAPPING);