1 /* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
4 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
6 This program 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 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <libcxml/cxml.h>
23 #include "sndfile_content.h"
24 #include "sndfile_decoder.h"
25 #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)
48 , AudioContent (f, node)
50 _audio_channels = node->number_child<int> ("AudioChannels");
51 _audio_length = node->number_child<ContentAudioFrame> ("AudioLength");
52 _audio_frame_rate = node->number_child<int> ("AudioFrameRate");
56 SndfileContent::summary () const
58 return String::compose (_("Sound file: %1"), file().filename().string());
62 SndfileContent::information () const
64 if (_audio_frame_rate == 0) {
70 s << String::compose (
71 _("%1 channels, %2kHz, %3 samples"),
73 content_audio_frame_rate() / 1000.0,
81 SndfileContent::valid_file (boost::filesystem::path f)
83 /* XXX: more extensions */
84 string ext = f.extension().string();
85 transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
86 return (ext == ".wav" || ext == ".aif" || ext == ".aiff");
90 SndfileContent::clone () const
92 return shared_ptr<Content> (new SndfileContent (*this));
96 SndfileContent::examine (shared_ptr<Job> job)
98 job->set_progress_unknown ();
99 Content::examine (job);
101 shared_ptr<const Film> film = _film.lock ();
104 SndfileDecoder dec (film, shared_from_this());
107 boost::mutex::scoped_lock lm (_mutex);
108 _audio_channels = dec.audio_channels ();
109 _audio_length = dec.audio_length ();
110 _audio_frame_rate = dec.audio_frame_rate ();
113 signal_changed (AudioContentProperty::AUDIO_CHANNELS);
114 signal_changed (AudioContentProperty::AUDIO_LENGTH);
115 signal_changed (AudioContentProperty::AUDIO_FRAME_RATE);
119 SndfileContent::as_xml (xmlpp::Node* node) const
121 node->add_child("Type")->add_child_text ("Sndfile");
122 Content::as_xml (node);
123 node->add_child("AudioChannels")->add_child_text (lexical_cast<string> (_audio_channels));
124 node->add_child("AudioLength")->add_child_text (lexical_cast<string> (_audio_length));
125 node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (_audio_frame_rate));
129 SndfileContent::length () const
131 shared_ptr<const Film> film = _film.lock ();
134 return film->audio_frames_to_time (audio_length ());
138 SndfileContent::output_audio_frame_rate () const
140 shared_ptr<const Film> film = _film.lock ();
143 return film->dcp_audio_frame_rate ();