Add export spec support for watermark/demo-noise

This commit is contained in:
Robin Gareus 2020-06-04 19:53:30 +02:00
parent 820165d238
commit 1e7207f9ec
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
4 changed files with 56 additions and 4 deletions

View File

@ -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;

View File

@ -36,6 +36,7 @@ namespace AudioGrapher {
class LoudnessReader;
class Normalizer;
class Analyser;
class DemoNoiseAdder;
template <typename T> class Chunker;
template <typename T> class SampleFormatConverter;
template <typename T> class Interleaver;
@ -137,6 +138,7 @@ class LIBARDOUR_API ExportGraphBuilder
private:
typedef boost::shared_ptr<AudioGrapher::Chunker<float> > ChunkerPtr;
typedef boost::shared_ptr<AudioGrapher::DemoNoiseAdder> DemoNoisePtr;
typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<Sample> > FloatConverterPtr;
typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<int> > IntConverterPtr;
typedef boost::shared_ptr<AudioGrapher::SampleFormatConverter<short> > ShortConverterPtr;
@ -145,6 +147,7 @@ class LIBARDOUR_API ExportGraphBuilder
boost::ptr_list<Encoder> children;
int data_width;
DemoNoisePtr demo_noise_adder;
ChunkerPtr chunker;
AnalysisPtr analyser;
bool _analyse;

View File

@ -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;

View File

@ -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<AudioGrapher::ListedSource<float> > 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<short> (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<int> (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<Sample> (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) {