From 1e7207f9ec5ae58c827d5ca4a983423507df3ccd Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 4 Jun 2020 19:53:30 +0200 Subject: [PATCH] Add export spec support for watermark/demo-noise --- .../ardour/export_format_specification.h | 12 +++++++++ libs/ardour/ardour/export_graph_builder.h | 3 +++ libs/ardour/export_format_specification.cc | 20 +++++++++++++++ libs/ardour/export_graph_builder.cc | 25 ++++++++++++++++--- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/export_format_specification.h b/libs/ardour/ardour/export_format_specification.h index f48113b476..7fc19c4500 100644 --- a/libs/ardour/ardour/export_format_specification.h +++ b/libs/ardour/ardour/export_format_specification.h @@ -99,6 +99,10 @@ class LIBARDOUR_API ExportFormatSpecification : public ExportFormatBase { void set_normalize_lufs (float value) { _normalize_lufs = value; } void set_normalize_dbtp (float value) { _normalize_dbtp = value; } + void set_demo_noise_level (float db) { _demo_noise_level = db; } + void set_demo_noise_duration (int msec) { _demo_noise_duration = msec; } + void set_demo_noise_interval (int msec) { _demo_noise_interval = msec; } + void set_tag (bool tag_it) { _tag = tag_it; } void set_with_cue (bool yn) { _with_cue = yn; } void set_with_toc (bool yn) { _with_toc = yn; } @@ -172,6 +176,10 @@ class LIBARDOUR_API ExportFormatSpecification : public ExportFormatBase { bool with_cue() const { return _with_cue; } bool with_mp4chaps() const { return _with_mp4chaps; } + float demo_noise_level () const { return _demo_noise_level; } + int demo_noise_duration () const { return _demo_noise_duration; } + int demo_noise_interval () const { return _demo_noise_interval; } + bool soundcloud_upload() const { return _soundcloud_upload; } std::string command() const { return _command; } bool analyse() const { return _analyse; } @@ -232,6 +240,10 @@ class LIBARDOUR_API ExportFormatSpecification : public ExportFormatBase { bool _with_mp4chaps; bool _soundcloud_upload; + float _demo_noise_level; + int _demo_noise_duration; + int _demo_noise_interval; + std::string _command; bool _analyse; int _codec_quality; diff --git a/libs/ardour/ardour/export_graph_builder.h b/libs/ardour/ardour/export_graph_builder.h index 07a878ae8b..142d8f1e5a 100644 --- a/libs/ardour/ardour/export_graph_builder.h +++ b/libs/ardour/ardour/export_graph_builder.h @@ -36,6 +36,7 @@ namespace AudioGrapher { class LoudnessReader; class Normalizer; class Analyser; + class DemoNoiseAdder; template class Chunker; template class SampleFormatConverter; template class Interleaver; @@ -137,6 +138,7 @@ class LIBARDOUR_API ExportGraphBuilder private: typedef boost::shared_ptr > ChunkerPtr; + typedef boost::shared_ptr DemoNoisePtr; typedef boost::shared_ptr > FloatConverterPtr; typedef boost::shared_ptr > IntConverterPtr; typedef boost::shared_ptr > ShortConverterPtr; @@ -145,6 +147,7 @@ class LIBARDOUR_API ExportGraphBuilder boost::ptr_list children; int data_width; + DemoNoisePtr demo_noise_adder; ChunkerPtr chunker; AnalysisPtr analyser; bool _analyse; diff --git a/libs/ardour/export_format_specification.cc b/libs/ardour/export_format_specification.cc index 67cb55cd59..5aca68245b 100644 --- a/libs/ardour/export_format_specification.cc +++ b/libs/ardour/export_format_specification.cc @@ -157,6 +157,9 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s) , _with_cue (false) , _with_mp4chaps (false) , _soundcloud_upload (false) + , _demo_noise_level (-20) + , _demo_noise_duration (0) + , _demo_noise_interval (0) , _command ("") , _analyse (true) , _codec_quality (0) @@ -193,6 +196,9 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s, XMLNode const , _with_cue (false) , _with_mp4chaps (false) , _soundcloud_upload (false) + , _demo_noise_level (-20) + , _demo_noise_duration (0) + , _demo_noise_interval (0) , _command ("") , _analyse (true) , _codec_quality (0) @@ -212,6 +218,9 @@ ExportFormatSpecification::ExportFormatSpecification (ExportFormatSpecification , _with_cue (other._with_cue) , _with_mp4chaps (other._with_mp4chaps) , _soundcloud_upload (false) + , _demo_noise_level (other._demo_noise_level) + , _demo_noise_duration (other._demo_noise_duration) + , _demo_noise_interval (other._demo_noise_interval) , _command (other._command) , _analyse (other._analyse) , _codec_quality (other._codec_quality) @@ -287,6 +296,11 @@ ExportFormatSpecification::get_state () node = root->add_child ("SRCQuality"); node->set_property ("quality", src_quality()); + node = root->add_child ("Watermark"); + node->set_property ("level", demo_noise_level ()); + node->set_property ("duration", demo_noise_duration ()); + node->set_property ("interval", demo_noise_interval ()); + if (_has_codec_quality) { node = root->add_child ("CodecQuality"); node->set_property ("quality", codec_quality()); @@ -399,6 +413,12 @@ ExportFormatSpecification::set_state (const XMLNode & root) child->get_property ("quality", _src_quality); } + if ((child = root.child ("Watermark"))) { + child->get_property ("level", _demo_noise_level); + child->get_property ("duration", _demo_noise_duration); + child->get_property ("interval", _demo_noise_interval); + } + if ((child = root.child ("CodecQuality"))) { child->get_property ("quality", _codec_quality); _has_codec_quality = true; diff --git a/libs/ardour/export_graph_builder.cc b/libs/ardour/export_graph_builder.cc index ccddc83881..45adce1982 100644 --- a/libs/ardour/export_graph_builder.cc +++ b/libs/ardour/export_graph_builder.cc @@ -34,6 +34,7 @@ #include "audiographer/process_context.h" #include "audiographer/general/chunker.h" #include "audiographer/general/cmdpipe_writer.h" +#include "audiographer/general/demo_noise.h" #include "audiographer/general/interleaver.h" #include "audiographer/general/normalizer.h" #include "audiographer/general/analyser.h" @@ -436,6 +437,8 @@ ExportGraphBuilder::SFC::SFC (ExportGraphBuilder &parent, FileSpec const & new_c data_width = sndfile_data_width (Encoder::get_real_format (config)); unsigned channels = new_config.channel_config->get_n_chans(); _analyse = config.format->analyse(); + + boost::shared_ptr > intermediate; if (_analyse) { samplecnt_t sample_rate = parent.session.nominal_sample_rate(); samplecnt_t sb = config.format->silence_beginning_at (parent.timespan->get_start(), sample_rate); @@ -449,25 +452,37 @@ ExportGraphBuilder::SFC::SFC (ExportGraphBuilder &parent, FileSpec const & new_c config.filename->set_channel_config (config.channel_config); parent.add_analyser (config.filename->get_path (config.format), analyser); + intermediate = analyser; + } + + if (config.format->demo_noise_duration () > 0 && config.format->demo_noise_interval () > 0) { + samplecnt_t sample_rate = parent.session.nominal_sample_rate(); + demo_noise_adder.reset (new DemoNoiseAdder (channels)); + demo_noise_adder->init (max_samples, + sample_rate * config.format->demo_noise_interval (), + sample_rate * config.format->demo_noise_duration (), + config.format->demo_noise_level ()); + if (intermediate) { intermediate->add_output (demo_noise_adder); } + intermediate = demo_noise_adder; } if (data_width == 8 || data_width == 16) { short_converter = ShortConverterPtr (new SampleFormatConverter (channels)); short_converter->init (max_samples, config.format->dither_type(), data_width); add_child (config); - if (_analyse) { analyser->add_output (short_converter); } + if (intermediate) { intermediate->add_output (short_converter); } } else if (data_width == 24 || data_width == 32) { int_converter = IntConverterPtr (new SampleFormatConverter (channels)); int_converter->init (max_samples, config.format->dither_type(), data_width); add_child (config); - if (_analyse) { analyser->add_output (int_converter); } + if (intermediate) { intermediate->add_output (int_converter); } } else { int actual_data_width = 8 * sizeof(Sample); float_converter = FloatConverterPtr (new SampleFormatConverter (channels)); float_converter->init (max_samples, config.format->dither_type(), actual_data_width); add_child (config); - if (_analyse) { analyser->add_output (float_converter); } + if (intermediate) { intermediate->add_output (float_converter); } } } @@ -482,8 +497,10 @@ ExportGraphBuilder::SFC::set_peak (float gain) ExportGraphBuilder::FloatSinkPtr ExportGraphBuilder::SFC::sink () { - if (_analyse) { + if (chunker) { return chunker; + } else if (demo_noise_adder) { + return demo_noise_adder; } else if (data_width == 8 || data_width == 16) { return short_converter; } else if (data_width == 24 || data_width == 32) {