Ardour  9.0-pre0-582-g084a23a80d
surround_return.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2023 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #ifdef HAVE_LV2_1_18_6
23 #include <lv2/atom/atom.h>
24 #include <lv2/atom/forge.h>
25 #else
26 #include <lv2/lv2plug.in/ns/ext/atom/atom.h>
27 #include <lv2/lv2plug.in/ns/ext/atom/forge.h>
28 #endif
29 
30 #ifdef __APPLE__
31 #include <CoreServices/CoreServices.h>
32 #include <CoreAudio/CoreAudio.h>
33 #include <AudioUnit/AudioUnit.h>
34 #endif
35 
36 #include "ardour/chan_mapping.h"
37 #include "ardour/fixed_delay.h"
38 #include "ardour/lufs_meter.h"
40 #include "ardour/processor.h"
41 
42 namespace ARDOUR
43 {
44 class Amp;
45 class Session;
46 class SurroundSend;
47 class SurroundPannable;
48 class LV2Plugin;
49 
51 {
52 public:
54  virtual ~SurroundReturn ();
55 
57  void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool);
59  void flush ();
61  bool display_to_user () const { return false; }
62 
63  void setup_export (std::string const&, samplepos_t, samplepos_t);
64  void finalize_export ();
65 
66  size_t n_channels () const {
67  return _current_n_channels;
68  }
69 
70  size_t total_n_channels (bool with_beds = true) const {
71  return _total_n_channels - (with_beds ? 0 : 10);
72  }
73 
74  std::shared_ptr<LV2Plugin> surround_processor () const {
75  return _surround_processor;
76  }
77 
78  bool have_au_renderer () const {
79  return _have_au_renderer;
80  }
81 
82  bool load_au_preset (size_t);
83  bool set_au_param (size_t, float);
84 
85  std::shared_ptr<PBD::Controllable> binaural_render_controllable () const {
86  return _binaural_render_control;
87  }
88 
90  OUTPUT_FORMAT_5_1 = 2,
91  OUTPUT_FORMAT_7_1_4 = 6
92  };
93 
95  return _current_output_format;
96  }
97 
98  std::shared_ptr<PBD::Controllable> output_format_controllable () const {
99  return _output_format_control;
100  }
101 
102  /* a value <= -200 indicates that no data is available */
103  float integrated_loudness () const;
104  float max_momentary () const;
105  float momentary () const;
106  float max_dbtp () const;
107 
109 
110  /* XXX this is only for testing */
111  void set_bed_mix (bool on, std::string const& ref, int* cmap = NULL);
112  void set_sync_and_align (bool on);
113  void set_ffoa (float);
115 
116  int set_state (XMLNode const&, int version);
117 
118 protected:
119  XMLNode& state () const;
120 
121 private:
122  static const size_t max_object_id = 128; // happens to be the same as a constant in a well known surround system
123  static const size_t num_pan_parameters = 8; // X, Y, Z, Size, Snap [ElevEn, Ramp, Zones]
124 
125  void forge_int_msg (uint32_t obj_id, uint32_t key, int val, uint32_t key2 = 0, int val2 = 0);
126  void maybe_send_metadata (size_t id, pframes_t frame, pan_t const v[num_pan_parameters], bool force = false);
127  void evaluate (size_t id, std::shared_ptr<SurroundPannable> const&, timepos_t const& , pframes_t, bool force = false);
128 
131 
132  std::shared_ptr<LV2Plugin> _surround_processor;
133 
135 
136  std::shared_ptr<Amp> _trim;
137 
138  class OutputFormatControl : public MPControl<bool>
139  {
140  public:
141  OutputFormatControl (bool v, std::string const& n, PBD::Controllable::Flag f);
142  virtual std::string get_user_string () const;
143  };
144 
145  std::shared_ptr<OutputFormatControl> _output_format_control;
146 
147  class BinauralRenderControl : public MPControl<bool>
148  {
149  public:
150  BinauralRenderControl (bool v, std::string const& n, PBD::Controllable::Flag f);
151  virtual std::string get_user_string () const;
152  };
153 
154  std::shared_ptr<BinauralRenderControl> _binaural_render_control;
155 
156 #ifdef __APPLE__
157  ::AudioUnit _au;
158  AudioBufferList* _au_buffers;
159  samplecnt_t _au_samples_processed;
160  float* _au_data[12];
161 
162  struct LIBARDOUR_API AUParameter {
163  AudioUnitParameterID id;
164  AudioUnitScope scope;
165  AudioUnitElement element;
166  std::string label;
167  float lower, upper, normal;
168  };
169 
170  std::vector<AUParameter> _au_params;
171  std::vector<AUPreset> _au_presets;
172 
173  static OSStatus _render_callback(void*, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList*);
174  OSStatus render_callback(AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList*);
175 #endif
176 
178  LV2_Atom_Forge _forge;
179  uint8_t _atom_buf[8192];
180  pan_t _current_value[max_object_id][num_pan_parameters];
181  int _current_render_mode[max_object_id];
182  size_t _channel_id_map[max_object_id];
192  bool _rolling;
193  bool _with_bed;
197  float _ffoa;
198  std::string _export_reference;
200  std::atomic<int> _flush;
201 };
202 
203 } // namespace ARDOUR
204 
BinauralRenderControl(bool v, std::string const &n, PBD::Controllable::Flag f)
virtual std::string get_user_string() const
virtual std::string get_user_string() const
OutputFormatControl(bool v, std::string const &n, PBD::Controllable::Flag f)
float max_dbtp() const
SurroundReturn(Session &, Route *)
int set_block_size(pframes_t)
XMLNode & state() const
int set_state(XMLNode const &, int version)
std::shared_ptr< PBD::Controllable > binaural_render_controllable() const
void forge_int_msg(uint32_t obj_id, uint32_t key, int val, uint32_t key2=0, int val2=0)
MainOutputFormat _current_output_format
size_t total_n_channels(bool with_beds=true) const
void maybe_send_metadata(size_t id, pframes_t frame, pan_t const v[num_pan_parameters], bool force=false)
void set_with_all_metadata(bool)
void set_sync_and_align(bool on)
std::shared_ptr< OutputFormatControl > _output_format_control
std::shared_ptr< LV2Plugin > _surround_processor
void run(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool)
std::shared_ptr< PBD::Controllable > output_format_controllable() const
size_t n_channels() const
samplecnt_t signal_latency() const
bool can_support_io_configuration(const ChanCount &in, ChanCount &out)
bool have_au_renderer() const
bool set_au_param(size_t, float)
std::shared_ptr< Amp > _trim
bool load_au_preset(size_t)
std::shared_ptr< BinauralRenderControl > _binaural_render_control
std::atomic< int > _flush
std::shared_ptr< LV2Plugin > surround_processor() const
void setup_export(std::string const &, samplepos_t, samplepos_t)
float momentary() const
void set_bed_mix(bool on, std::string const &ref, int *cmap=NULL)
MainOutputFormat output_format() const
void set_playback_offset(samplecnt_t cnt)
bool display_to_user() const
float integrated_loudness() const
float max_momentary() const
void evaluate(size_t id, std::shared_ptr< SurroundPannable > const &, timepos_t const &, pframes_t, bool force=false)
Definition: xml++.h:114
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
@ AudioUnit
Definition: plugin_types.h:24
Temporal::samplepos_t samplepos_t