summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-07-15 17:03:07 +0200
committerRobin Gareus <robin@gareus.org>2016-07-16 02:14:13 +0200
commit77687519b69f39aaa2354f4c9945958fc1c630fe (patch)
tree36ed0f367bc81cccaba0ed01d837c56ff2fea072 /libs/ardour
parent6626723880e6d464bf8d59178120d191a8423c93 (diff)
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.
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/export_graph_builder.h7
-rw-r--r--libs/ardour/export_graph_builder.cc19
-rw-r--r--libs/ardour/export_handler.cc8
-rw-r--r--libs/ardour/session_export.cc34
4 files changed, 46 insertions, 22 deletions
diff --git a/libs/ardour/ardour/export_graph_builder.h b/libs/ardour/ardour/export_graph_builder.h
index 68eb927513..cee98ed7be 100644
--- a/libs/ardour/ardour/export_graph_builder.h
+++ b/libs/ardour/ardour/export_graph_builder.h
@@ -41,7 +41,6 @@ namespace AudioGrapher {
template <typename T> class SndfileWriter;
template <typename T> class SilenceTrimmer;
template <typename T> class TmpFile;
- template <typename T> class TmpFileRt;
template <typename T> class Threader;
template <typename T> class AllocatingProcessContext;
}
@@ -165,11 +164,11 @@ class LIBARDOUR_API ExportGraphBuilder
typedef boost::shared_ptr<AudioGrapher::LoudnessReader> LoudnessReaderPtr;
typedef boost::shared_ptr<AudioGrapher::Normalizer> NormalizerPtr;
typedef boost::shared_ptr<AudioGrapher::TmpFile<Sample> > TmpFilePtr;
- typedef boost::shared_ptr<AudioGrapher::TmpFileRt<Sample> > TmpFileRtPtr;
typedef boost::shared_ptr<AudioGrapher::Threader<Sample> > ThreaderPtr;
typedef boost::shared_ptr<AudioGrapher::AllocatingProcessContext<Sample> > BufferPtr;
- void start_post_processing();
+ void prepare_post_processing ();
+ void start_post_processing ();
ExportGraphBuilder & parent;
@@ -184,7 +183,7 @@ class LIBARDOUR_API ExportGraphBuilder
LoudnessReaderPtr loudness_reader;
boost::ptr_list<SFC> children;
- PBD::ScopedConnection post_processing_connection;
+ PBD::ScopedConnectionList post_processing_connection;
};
// sample rate converter
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<float> (&tmpfile_path_buf[0], format, channels, config.format->sample_rate()));
+ tmp_file.reset (new TmpFileSync<float> (&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<SFC>::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)
diff --git a/libs/ardour/export_handler.cc b/libs/ardour/export_handler.cc
index 8ca73788dd..d83e2beebb 100644
--- a/libs/ardour/export_handler.cc
+++ b/libs/ardour/export_handler.cc
@@ -26,6 +26,7 @@
#include "pbd/convert.h"
+#include "ardour/audioengine.h"
#include "ardour/audiofile_tagger.h"
#include "ardour/debug.h"
#include "ardour/export_graph_builder.h"
@@ -232,7 +233,12 @@ ExportHandler::process (framecnt_t frames)
return 0;
} else if (normalizing) {
Glib::Threads::Mutex::Lock l (export_status->lock());
- return process_normalize ();
+ if (AudioEngine::instance()->freewheeling ()) {
+ return process_normalize ();
+ } else {
+ // wait until we're freewheeling
+ return 0;
+ }
} else {
Glib::Threads::Mutex::Lock l (export_status->lock());
return process_timespan (frames);
diff --git a/libs/ardour/session_export.cc b/libs/ardour/session_export.cc
index 7234411ce4..463f504411 100644
--- a/libs/ardour/session_export.cc
+++ b/libs/ardour/session_export.cc
@@ -177,13 +177,14 @@ Session::start_audio_export (framepos_t position, bool realtime)
return -1;
}
+ _engine.Freewheel.connect_same_thread (export_freewheel_connection, boost::bind (&Session::process_export_fw, this, _1));
+
if (_realtime_export) {
Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
_export_rolling = true;
process_function = &Session::process_export_fw;
return 0;
} else {
- _engine.Freewheel.connect_same_thread (export_freewheel_connection, boost::bind (&Session::process_export_fw, this, _1));
_export_rolling = true;
return _engine.freewheel (true);
}
@@ -197,14 +198,18 @@ Session::process_export (pframes_t nframes)
}
if (_export_rolling) {
- /* make sure we've caught up with disk i/o, since
- we're running faster than realtime c/o JACK.
- */
- _butler->wait_until_finished ();
+ if (!_realtime_export) {
+ /* make sure we've caught up with disk i/o, since
+ * we're running faster than realtime c/o JACK.
+ */
+ _butler->wait_until_finished ();
+ }
/* do the usual stuff */
process_without_events (nframes);
+ } else if (_realtime_export) {
+ fail_roll (nframes); // somehow we need to silence _ALL_ output buffers
}
try {
@@ -221,13 +226,14 @@ Session::process_export (pframes_t nframes)
void
Session::process_export_fw (pframes_t nframes)
{
+ const bool need_buffers = _engine.freewheeling ();
if (_export_preroll > 0) {
- if (!_realtime_export) {
+ if (need_buffers) {
_engine.main_thread()->get_buffers ();
}
fail_roll (nframes);
- if (!_realtime_export) {
+ if (need_buffers) {
_engine.main_thread()->drop_buffers ();
}
@@ -249,11 +255,11 @@ Session::process_export_fw (pframes_t nframes)
if (_export_latency > 0) {
framepos_t remain = std::min ((framepos_t)nframes, _export_latency);
- if (!_realtime_export) {
+ if (need_buffers) {
_engine.main_thread()->get_buffers ();
}
process_without_events (remain);
- if (!_realtime_export) {
+ if (need_buffers) {
_engine.main_thread()->drop_buffers ();
}
@@ -264,11 +270,12 @@ Session::process_export_fw (pframes_t nframes)
return;
}
}
- if (!_realtime_export) {
+
+ if (need_buffers) {
_engine.main_thread()->get_buffers ();
}
process_export (nframes);
- if (!_realtime_export) {
+ if (need_buffers) {
_engine.main_thread()->drop_buffers ();
}
@@ -304,10 +311,9 @@ Session::finalize_audio_export ()
if (_realtime_export) {
Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
process_function = &Session::process_with_events;
- } else {
- _engine.freewheel (false);
- export_freewheel_connection.disconnect();
}
+ _engine.freewheel (false);
+ export_freewheel_connection.disconnect();
_mmc->enable_send (_pre_export_mmc_enabled);