From b9842263a402b5ce1d2f85a1346ca11a419f816e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 11 Sep 2015 22:29:28 +0100 Subject: [PATCH] Fix assertion failure when processors return fewer channels than the DCP has. --- ChangeLog | 5 ++++ src/lib/analyse_audio_job.h | 1 + src/lib/audio_point.h | 5 ++++ src/lib/audio_processor.h | 4 +-- src/lib/mid_side_decoder.cc | 21 ++++++++++---- src/lib/mid_side_decoder.h | 2 +- src/lib/player.cc | 2 +- src/lib/upmixer_a.cc | 35 ++++++++++++++---------- src/lib/upmixer_a.h | 2 +- test/audio_processor_test.cc | 53 ++++++++++++++++++++++++++++++++++++ test/data | 2 +- test/wscript | 1 + 12 files changed, 107 insertions(+), 26 deletions(-) create mode 100644 test/audio_processor_test.cc diff --git a/ChangeLog b/ChangeLog index cbf031be8..fe02e2508 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-09-11 Carl Hetherington + + * Fix assertion failure when creating 6-channel DCPs + using the mid-side processor. + 2015-09-10 Carl Hetherington * Version 2.1.62 released. diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h index 4273c19ed..d484bff2c 100644 --- a/src/lib/analyse_audio_job.h +++ b/src/lib/analyse_audio_job.h @@ -22,6 +22,7 @@ */ #include "job.h" +#include "audio_point.h" #include "types.h" class AudioBuffers; diff --git a/src/lib/audio_point.h b/src/lib/audio_point.h index f699233cb..de8538ebe 100644 --- a/src/lib/audio_point.h +++ b/src/lib/audio_point.h @@ -17,6 +17,9 @@ */ +#ifndef DCPOMATIC_AUDIO_POINT_H +#define DCPOMATIC_AUDIO_POINT_H + #include namespace xmlpp { @@ -46,3 +49,5 @@ public: private: float _data[COUNT]; }; + +#endif diff --git a/src/lib/audio_processor.h b/src/lib/audio_processor.h index 114756f91..2c66d5b07 100644 --- a/src/lib/audio_processor.h +++ b/src/lib/audio_processor.h @@ -54,8 +54,8 @@ public: virtual int out_channels () const = 0; /** @return A clone of this AudioProcessor for operation at the specified sampling rate */ virtual boost::shared_ptr clone (int sampling_rate) const = 0; - /** Process some data, returning the processed result */ - virtual boost::shared_ptr run (boost::shared_ptr) = 0; + /** Process some data, returning the processed result truncated or padded to `channels' */ + virtual boost::shared_ptr run (boost::shared_ptr, int channels) = 0; virtual void flush () {} /** Make the supplied audio mapping into a sensible default for this processor */ virtual void make_audio_mapping_default (AudioMapping& mapping) const = 0; diff --git a/src/lib/mid_side_decoder.cc b/src/lib/mid_side_decoder.cc index 842d5c8ee..4f619ad57 100644 --- a/src/lib/mid_side_decoder.cc +++ b/src/lib/mid_side_decoder.cc @@ -59,16 +59,27 @@ MidSideDecoder::clone (int) const } shared_ptr -MidSideDecoder::run (shared_ptr in) +MidSideDecoder::run (shared_ptr in, int channels) { - shared_ptr out (new AudioBuffers (3, in->frames ())); + int const N = min (channels, 3); + shared_ptr out (new AudioBuffers (channels, in->frames ())); for (int i = 0; i < in->frames(); ++i) { float const left = in->data()[0][i]; float const right = in->data()[1][i]; float const mid = (left + right) / 2; - out->data()[0][i] = left - mid; - out->data()[1][i] = right - mid; - out->data()[2][i] = mid; + if (N > 0) { + out->data()[0][i] = left - mid; + } + if (N > 1) { + out->data()[1][i] = right - mid; + } + if (N > 2) { + out->data()[2][i] = mid; + } + } + + for (int i = N; i < channels; ++i) { + out->make_silent (i); } return out; diff --git a/src/lib/mid_side_decoder.h b/src/lib/mid_side_decoder.h index 197c7b33b..13e5ca360 100644 --- a/src/lib/mid_side_decoder.h +++ b/src/lib/mid_side_decoder.h @@ -27,7 +27,7 @@ public: ChannelCount in_channels () const; int out_channels () const; boost::shared_ptr clone (int) const; - boost::shared_ptr run (boost::shared_ptr); + boost::shared_ptr run (boost::shared_ptr, int channels); void make_audio_mapping_default (AudioMapping& mapping) const; std::vector input_names () const; }; diff --git a/src/lib/player.cc b/src/lib/player.cc index 302ab161c..acf977def 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -508,7 +508,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate) } if (_audio_processor) { - dcp_mapped = _audio_processor->run (dcp_mapped); + dcp_mapped = _audio_processor->run (dcp_mapped, _film->audio_channels ()); } all.audio = dcp_mapped; diff --git a/src/lib/upmixer_a.cc b/src/lib/upmixer_a.cc index 1edc0104d..e6ec09c6a 100644 --- a/src/lib/upmixer_a.cc +++ b/src/lib/upmixer_a.cc @@ -71,7 +71,7 @@ UpmixerA::clone (int sampling_rate) const } shared_ptr -UpmixerA::run (shared_ptr in) +UpmixerA::run (shared_ptr in, int channels) { /* Input L and R */ shared_ptr in_L = in->channel (0); @@ -83,20 +83,25 @@ UpmixerA::run (shared_ptr in) in_LR->apply_gain (0.5); /* Run filters */ - shared_ptr L = _left.run (in_L); - shared_ptr R = _right.run (in_R); - shared_ptr C = _centre.run (in_LR); - shared_ptr Lfe = _lfe.run (in_LR); - shared_ptr Ls = _ls.run (in_L); - shared_ptr Rs = _rs.run (in_R); - - shared_ptr out (new AudioBuffers (6, in->frames ())); - out->copy_channel_from (L.get(), 0, 0); - out->copy_channel_from (R.get(), 0, 1); - out->copy_channel_from (C.get(), 0, 2); - out->copy_channel_from (Lfe.get(), 0, 3); - out->copy_channel_from (Ls.get(), 0, 4); - out->copy_channel_from (Rs.get(), 0, 5); + vector > all_out; + all_out.push_back (_left.run (in_L)); + all_out.push_back (_right.run (in_R)); + all_out.push_back (_centre.run (in_LR)); + all_out.push_back (_lfe.run (in_LR)); + all_out.push_back (_ls.run (in_L)); + all_out.push_back (_rs.run (in_R)); + + shared_ptr out (new AudioBuffers (channels, in->frames ())); + int const N = min (channels, 6); + + for (int i = 0; i < N; ++i) { + out->copy_channel_from (all_out[i].get(), 0, i); + } + + for (int i = N; i < channels; ++i) { + out->make_silent (i); + } + return out; } diff --git a/src/lib/upmixer_a.h b/src/lib/upmixer_a.h index 389d52d25..a25c3a329 100644 --- a/src/lib/upmixer_a.h +++ b/src/lib/upmixer_a.h @@ -37,7 +37,7 @@ public: ChannelCount in_channels () const; int out_channels () const; boost::shared_ptr clone (int) const; - boost::shared_ptr run (boost::shared_ptr); + boost::shared_ptr run (boost::shared_ptr, int channels); void flush (); void make_audio_mapping_default (AudioMapping& mapping) const; std::vector input_names () const; diff --git a/test/audio_processor_test.cc b/test/audio_processor_test.cc new file mode 100644 index 000000000..a668a7e09 --- /dev/null +++ b/test/audio_processor_test.cc @@ -0,0 +1,53 @@ +/* + Copyright (C) 2015 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "lib/audio_processor.h" +#include "lib/analyse_audio_job.h" +#include "lib/dcp_content_type.h" +#include "lib/job_manager.h" +#include "lib/sndfile_content.h" +#include "lib/film.h" +#include "test.h" +#include + +using boost::shared_ptr; + +/** Test the mid-side decoder for analysis and DCP-making */ +BOOST_AUTO_TEST_CASE (audio_processor_test) +{ + shared_ptr film = new_test_film ("audio_processor_test"); + film->set_name ("audio_processor_test"); + shared_ptr c (new SndfileContent (film, "test/data/white.wav")); + film->examine_and_add_content (c); + wait_for_jobs (); + + film->set_audio_channels (6); + film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + film->set_audio_processor (AudioProcessor::from_id ("mid-side-decoder")); + + /* Analyse the audio and check it doesn't crash */ + shared_ptr job (new AnalyseAudioJob (film, film->playlist ())); + JobManager::instance()->add (job); + wait_for_jobs (); + + /* Make a DCP and check it */ + film->make_dcp (); + wait_for_jobs (); + check_dcp ("test/data/audio_processor_test", film->dir (film->dcp_name ())); +} diff --git a/test/data b/test/data index 8d1220d25..2af14aa5d 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 8d1220d25c278d0a9678ccb0d0a07196a8f1331d +Subproject commit 2af14aa5d93b321455e946af9b278ffd11db71b3 diff --git a/test/wscript b/test/wscript index f46d3dc84..8707c1562 100644 --- a/test/wscript +++ b/test/wscript @@ -43,6 +43,7 @@ def build(bld): audio_decoder_test.cc audio_filter_test.cc audio_mapping_test.cc + audio_processor_test.cc black_fill_test.cc client_server_test.cc colour_conversion_test.cc -- 2.30.2