int process (framecnt_t frames, bool last_cycle);
bool process_normalize (); // returns true when finished
- bool will_normalize() { return !normalizers.empty(); }
+ bool will_normalize() const { return !normalizers.empty(); }
+ bool realtime() const { return _realtime; }
unsigned get_normalize_cycle_count() const;
void reset ();
void cleanup (bool remove_out_files = false);
void set_current_timespan (boost::shared_ptr<ExportTimespan> span);
- void add_config (FileSpec const & config);
+ void add_config (FileSpec const & config, bool rt);
void get_analysis_results (AnalysisResults& results);
private:
FileSpec config;
framecnt_t max_frames_out;
bool use_loudness;
+ bool use_peak;
BufferPtr buffer;
PeakReaderPtr peak_reader;
TmpFilePtr tmp_file;
AnalysisMap analysis_map;
+ bool _realtime;
+
Glib::ThreadPool thread_pool;
};
channels.clear ();
normalizers.clear ();
analysis_map.clear();
+ _realtime = false;
}
void
}
void
-ExportGraphBuilder::add_config (FileSpec const & config)
+ExportGraphBuilder::add_config (FileSpec const & config, bool rt)
{
ExportChannelConfiguration::ChannelList const & channels =
config.channel_config->get_channels();
(*it)->set_max_buffer_size(process_buffer_frames);
}
+ _realtime = rt;
+
// If the sample rate is "session rate", change it to the real value.
// However, we need to copy it to not change the config which is saved...
FileSpec new_config (config);
ExportGraphBuilder::Normalizer::Normalizer (ExportGraphBuilder & parent, FileSpec const & new_config, framecnt_t max_frames)
: parent (parent)
, use_loudness (false)
+ , use_peak (false)
{
std::string tmpfile_path = parent.session.session_directory().export_path();
tmpfile_path = Glib::build_filename(tmpfile_path, "XXXXXX");
uint32_t const channels = config.channel_config->get_n_chans();
max_frames_out = 4086 - (4086 % channels); // TODO good chunk size
use_loudness = config.format->normalize_loudness ();
+ use_peak = config.format->normalize ();
buffer.reset (new AllocatingProcessContext<Sample> (max_frames_out, channels));
- peak_reader.reset (new PeakReader ());
- loudness_reader.reset (new LoudnessReader (config.format->sample_rate(), channels, max_frames));
+
+ if (use_peak) {
+ peak_reader.reset (new PeakReader ());
+ }
+ if (use_loudness) {
+ loudness_reader.reset (new LoudnessReader (config.format->sample_rate(), channels, max_frames));
+ }
+
normalizer.reset (new AudioGrapher::Normalizer (use_loudness ? 0.0 : config.format->normalize_dbfs()));
threader.reset (new Threader<Sample> (parent.thread_pool));
-
normalizer->alloc_buffer (max_frames_out);
normalizer->add_output (threader);
int format = ExportFormatBase::F_RAW | ExportFormatBase::SF_Float;
- tmp_file.reset (new TmpFileSync<float> (&tmpfile_path_buf[0], format, channels, config.format->sample_rate()));
+
+ if (parent._realtime) {
+ tmp_file.reset (new TmpFileRt<float> (&tmpfile_path_buf[0], format, channels, config.format->sample_rate()));
+ } else {
+ 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,
if (use_loudness) {
loudness_reader->add_output (tmp_file);
- } else {
+ } else if (use_peak) {
peak_reader->add_output (tmp_file);
}
}
{
if (use_loudness) {
return loudness_reader;
+ } else if (use_peak) {
+ return peak_reader;
}
- return peak_reader;
+ return tmp_file;
}
void
float gain;
if (use_loudness) {
gain = normalizer->set_peak (loudness_reader->get_peak (config.format->normalize_lufs (), config.format->normalize_dbtp ()));
- } else {
+ } else if (use_peak) {
gain = normalizer->set_peak (peak_reader->get_peak());
+ } else {
+ gain = normalizer->set_peak (0.0);
}
- for (boost::ptr_list<SFC>::iterator i = children.begin(); i != children.end(); ++i) {
- (*i).set_peak (gain);
+ if (use_loudness || use_peak) {
+ // push info to analyzers
+ for (boost::ptr_list<SFC>::iterator i = children.begin(); i != children.end(); ++i) {
+ (*i).set_peak (gain);
+ }
}
tmp_file->add_output (normalizer);
parent.normalizers.push_back (this);
void
ExportGraphBuilder::SRC::add_child (FileSpec const & new_config)
{
- if (new_config.format->normalize()) {
+ if (new_config.format->normalize() || parent._realtime) {
add_child_to_list (new_config, normalized_children);
} else {
add_child_to_list (new_config, children);
graph_builder->reset ();
graph_builder->set_current_timespan (current_timespan);
handle_duplicate_format_extensions();
+ bool realtime = current_timespan->realtime ();
for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
// Filenames can be shared across timespans
FileSpec & spec = it->second;
spec.filename->set_timespan (it->first);
- graph_builder->add_config (spec);
+ graph_builder->add_config (spec, realtime);
}
/* start export */
normalizing = false;
session.ProcessExport.connect_same_thread (process_connection, boost::bind (&ExportHandler::process, this, _1));
process_position = current_timespan->get_start();
- session.start_audio_export (process_position);
+ session.start_audio_export (process_position, realtime);
}
void
/* Start normalizing if necessary */
if (last_cycle) {
- normalizing = graph_builder->will_normalize();
+ normalizing = graph_builder->will_normalize ();
if (normalizing) {
export_status->total_normalize_cycles = graph_builder->get_normalize_cycle_count();
export_status->current_normalize_cycle = 0;
finish_timespan ();
export_status->active_job = ExportStatus::Exporting;
} else {
- export_status->active_job = ExportStatus::Normalizing;
+ if (graph_builder->realtime ()) {
+ export_status->active_job = ExportStatus::Encoding;
+ } else {
+ export_status->active_job = ExportStatus::Normalizing;
+ }
}
export_status->current_normalize_cycle++;