From 77687519b69f39aaa2354f4c9945958fc1c630fe Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 15 Jul 2016 17:03:07 +0200 Subject: Refactor TmpFile into an abstract base class This allows a TmpFile pointer to be either a Sync or Async (Threaded) writer. As result we must be able to handle both RT and non RT processing. Still, post-processing (normalization and encoding) should always happen faster than realtime (freewheeling). Since jack does not allow a client to change to freewheeling from within the process-callback, the async-writer disk-thread FileFlushed is used to initiate post-processing. --- libs/ardour/export_graph_builder.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'libs/ardour/export_graph_builder.cc') diff --git a/libs/ardour/export_graph_builder.cc b/libs/ardour/export_graph_builder.cc index 2e9972b47d..9065aea130 100644 --- a/libs/ardour/export_graph_builder.cc +++ b/libs/ardour/export_graph_builder.cc @@ -37,6 +37,7 @@ #include "audiographer/general/threader.h" #include "audiographer/sndfile/tmp_file.h" #include "audiographer/sndfile/tmp_file_rt.h" +#include "audiographer/sndfile/tmp_file_sync.h" #include "audiographer/sndfile/sndfile_writer.h" #include "ardour/audioengine.h" @@ -434,8 +435,10 @@ ExportGraphBuilder::Normalizer::Normalizer (ExportGraphBuilder & parent, FileSpe normalizer->add_output (threader); int format = ExportFormatBase::F_RAW | ExportFormatBase::SF_Float; - tmp_file.reset (new TmpFile (&tmpfile_path_buf[0], format, channels, config.format->sample_rate())); + tmp_file.reset (new TmpFileSync (&tmpfile_path_buf[0], format, channels, config.format->sample_rate())); tmp_file->FileWritten.connect_same_thread (post_processing_connection, + boost::bind (&Normalizer::prepare_post_processing, this)); + tmp_file->FileFlushed.connect_same_thread (post_processing_connection, boost::bind (&Normalizer::start_post_processing, this)); add_child (new_config); @@ -509,8 +512,9 @@ ExportGraphBuilder::Normalizer::process() } void -ExportGraphBuilder::Normalizer::start_post_processing() +ExportGraphBuilder::Normalizer::prepare_post_processing() { + // called in sync rt-context float gain; if (use_loudness) { gain = normalizer->set_peak (loudness_reader->get_peak (config.format->normalize_lufs (), config.format->normalize_dbtp ())); @@ -520,11 +524,20 @@ ExportGraphBuilder::Normalizer::start_post_processing() for (boost::ptr_list::iterator i = children.begin(); i != children.end(); ++i) { (*i).set_peak (gain); } - tmp_file->seek (0, SEEK_SET); tmp_file->add_output (normalizer); parent.normalizers.push_back (this); } +void +ExportGraphBuilder::Normalizer::start_post_processing() +{ + // called in disk-thread (when exporting in realtime) + tmp_file->seek (0, SEEK_SET); + if (!AudioEngine::instance()->freewheeling ()) { + AudioEngine::instance()->freewheel (true); + } +} + /* SRC */ ExportGraphBuilder::SRC::SRC (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames) -- cgit v1.2.3