summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-05-04 18:01:19 +0100
committerCarl Hetherington <cth@carlh.net>2013-05-04 18:01:19 +0100
commit9bb87e91c0930f16cf615cfc374089912440e5e0 (patch)
treead25f85cd9616d46a3af1aadbfb772a802af8319 /src/lib
parent8a1042b767e2604b0af4850dd69fd6a848fd6ffe (diff)
Add primitive description of what the playlist is doing. Add missing de-interleave of multi-channel audio sources.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/film.cc6
-rw-r--r--src/lib/film.h2
-rw-r--r--src/lib/playlist.cc51
-rw-r--r--src/lib/playlist.h2
-rw-r--r--src/lib/sndfile_decoder.cc29
-rw-r--r--src/lib/sndfile_decoder.h1
6 files changed, 89 insertions, 2 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 7d1985d08..2dc97c1b3 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -1160,6 +1160,12 @@ Film::has_subtitles () const
return _playlist->has_subtitles ();
}
+string
+Film::playlist_description () const
+{
+ return _playlist->description ();
+}
+
void
Film::set_audio_mapping (AudioMapping m)
{
diff --git a/src/lib/film.h b/src/lib/film.h
index 48b0d16c5..8748e18f5 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -121,6 +121,8 @@ public:
ContentVideoFrame content_length () const;
+ std::string playlist_description () const;
+
void set_loop (int);
int loop () const;
diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc
index 63b44f9d6..6913874b9 100644
--- a/src/lib/playlist.cc
+++ b/src/lib/playlist.cc
@@ -30,12 +30,15 @@
#include "imagemagick_content.h"
#include "job.h"
+#include "i18n.h"
+
using std::list;
using std::cout;
using std::vector;
using std::min;
using std::max;
using std::string;
+using std::stringstream;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::dynamic_pointer_cast;
@@ -427,3 +430,51 @@ Playlist::has_subtitles () const
return !fc->subtitle_streams().empty();
}
+
+string
+Playlist::description () const
+{
+ stringstream s;
+
+ if (_video.empty ()) {
+ s << _("There is no video.") << "\n";
+ } else {
+ s << _("Video will come from ");
+ list<shared_ptr<const VideoContent> >::const_iterator i = _video.begin();
+ while (i != _video.end ()) {
+ s << (*i)->file().filename().string();
+ ++i;
+ if (i != _video.end ()) {
+ s << ", ";
+ }
+ }
+ if (_video.size() > 1) {
+ s << " " << _("in sequence.");
+ }
+ s << "\n";
+ }
+
+ if (_audio.empty ()) {
+ s << _("There is no audio.") << "\n";
+ } else {
+ if (_audio_from == AUDIO_FFMPEG) {
+ s << _("Audio will come from the video files.") << "\n";
+ } else {
+ s << _("Audio will come from ");
+ list<shared_ptr<const AudioContent> >::const_iterator i = _audio.begin();
+ while (i != _audio.end ()) {
+ s << (*i)->file().filename().string();
+ ++i;
+ if (i != _audio.end ()) {
+ s << ", ";
+ }
+ }
+ if (_audio.size() > 1) {
+ s << _(" run simultaneously.");
+ }
+ s << "\n";
+ }
+ }
+
+ return s.str ();
+}
diff --git a/src/lib/playlist.h b/src/lib/playlist.h
index e6acff694..cea41ab32 100644
--- a/src/lib/playlist.h
+++ b/src/lib/playlist.h
@@ -88,6 +88,8 @@ public:
return _content;
}
+ std::string description () const;
+
boost::shared_ptr<FFmpegContent> ffmpeg () const;
std::list<boost::shared_ptr<const VideoContent> > video () const {
diff --git a/src/lib/sndfile_decoder.cc b/src/lib/sndfile_decoder.cc
index 9ba972e56..dd9e654c7 100644
--- a/src/lib/sndfile_decoder.cc
+++ b/src/lib/sndfile_decoder.cc
@@ -36,6 +36,7 @@ SndfileDecoder::SndfileDecoder (shared_ptr<const Film> f, shared_ptr<const Sndfi
: Decoder (f)
, AudioDecoder (f)
, _sndfile_content (c)
+ , _deinterleave_buffer (0)
{
_sndfile = sf_open (_sndfile_content->file().string().c_str(), SFM_READ, &_info);
if (!_sndfile) {
@@ -49,6 +50,7 @@ SndfileDecoder::SndfileDecoder (shared_ptr<const Film> f, shared_ptr<const Sndfi
SndfileDecoder::~SndfileDecoder ()
{
sf_close (_sndfile);
+ delete[] _deinterleave_buffer;
}
bool
@@ -59,9 +61,32 @@ SndfileDecoder::pass ()
*/
sf_count_t const block = _sndfile_content->audio_frame_rate() / 2;
sf_count_t const this_time = min (block, _remaining);
+
+ int const channels = _sndfile_content->audio_channels ();
- shared_ptr<AudioBuffers> audio (new AudioBuffers (_sndfile_content->audio_channels(), this_time));
- sf_read_float (_sndfile, audio->data(0), this_time);
+ shared_ptr<AudioBuffers> audio (new AudioBuffers (channels, this_time));
+
+ if (_sndfile_content->audio_channels() == 1) {
+ /* No de-interleaving required */
+ sf_read_float (_sndfile, audio->data(0), this_time);
+ } else {
+ /* Deinterleave */
+ if (!_deinterleave_buffer) {
+ _deinterleave_buffer = new float[block * channels];
+ }
+ sf_readf_float (_sndfile, _deinterleave_buffer, this_time);
+ vector<float*> out_ptr (channels);
+ for (int i = 0; i < channels; ++i) {
+ out_ptr[i] = audio->data(i);
+ }
+ float* in_ptr = _deinterleave_buffer;
+ for (int i = 0; i < this_time; ++i) {
+ for (int j = 0; j < channels; ++j) {
+ *out_ptr[j]++ = *in_ptr++;
+ }
+ }
+ }
+
audio->set_frames (this_time);
Audio (audio, double(_done) / audio_frame_rate());
_done += this_time;
diff --git a/src/lib/sndfile_decoder.h b/src/lib/sndfile_decoder.h
index 1d212cc9b..64bd2f7f5 100644
--- a/src/lib/sndfile_decoder.h
+++ b/src/lib/sndfile_decoder.h
@@ -41,4 +41,5 @@ private:
SF_INFO _info;
ContentAudioFrame _done;
ContentAudioFrame _remaining;
+ float* _deinterleave_buffer;
};