Ardour  8.12
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 #ifndef __ardour_surround_return_h__
21 #define __ardour_surround_return_h__
22 
23 #ifdef HAVE_LV2_1_18_6
24 #include <lv2/atom/atom.h>
25 #include <lv2/atom/forge.h>
26 #else
27 #include <lv2/lv2plug.in/ns/ext/atom/atom.h>
28 #include <lv2/lv2plug.in/ns/ext/atom/forge.h>
29 #endif
30 
31 #ifdef __APPLE__
32 #include <CoreServices/CoreServices.h>
33 #include <CoreAudio/CoreAudio.h>
34 #include <AudioUnit/AudioUnit.h>
35 #endif
36 
37 #include "ardour/chan_mapping.h"
38 #include "ardour/fixed_delay.h"
39 #include "ardour/lufs_meter.h"
41 #include "ardour/processor.h"
42 
43 namespace ARDOUR
44 {
45 class Amp;
46 class Session;
47 class SurroundSend;
48 class SurroundPannable;
49 class LV2Plugin;
50 
52 {
53 public:
55  virtual ~SurroundReturn ();
56 
58  void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool);
60  void flush ();
62  bool display_to_user () const { return false; }
63 
64  void setup_export (std::string const&, samplepos_t, samplepos_t);
65  void finalize_export ();
66 
67  size_t n_channels () const {
68  return _current_n_channels;
69  }
70 
71  size_t total_n_channels (bool with_beds = true) const {
72  return _total_n_channels - (with_beds ? 0 : 10);
73  }
74 
75  std::shared_ptr<LV2Plugin> surround_processor () const {
76  return _surround_processor;
77  }
78 
79  bool have_au_renderer () const {
80  return _have_au_renderer;
81  }
82 
83  bool load_au_preset (size_t);
84  bool set_au_param (size_t, float);
85 
86  std::shared_ptr<PBD::Controllable> binaural_render_controllable () const {
87  return _binaural_render_control;
88  }
89 
91  OUTPUT_FORMAT_5_1 = 2,
92  OUTPUT_FORMAT_7_1_4 = 6
93  };
94 
96  return _current_output_format;
97  }
98 
99  std::shared_ptr<PBD::Controllable> output_format_controllable () const {
100  return _output_format_control;
101  }
102 
103  /* a value <= -200 indicates that no data is available */
104  float integrated_loudness () const;
105  float max_momentary () const;
106  float momentary () const;
107  float max_dbtp () const;
108 
110 
111  /* XXX this is only for testing */
112  void set_bed_mix (bool on, std::string const& ref, int* cmap = NULL);
113  void set_sync_and_align (bool on);
114  void set_ffoa (float);
116 
117  int set_state (XMLNode const&, int version);
118 
119 protected:
120  XMLNode& state () const;
121 
122 private:
123  static const size_t max_object_id = 128; // happens to be the same as a constant in a well known surround system
124  static const size_t num_pan_parameters = 8; // X, Y, Z, Size, Snap [ElevEn, Ramp, Zones]
125 
126  void forge_int_msg (uint32_t obj_id, uint32_t key, int val, uint32_t key2 = 0, int val2 = 0);
127  void maybe_send_metadata (size_t id, pframes_t frame, pan_t const v[num_pan_parameters], bool force = false);
128  void evaluate (size_t id, std::shared_ptr<SurroundPannable> const&, timepos_t const& , pframes_t, bool force = false);
129 
132 
133  std::shared_ptr<LV2Plugin> _surround_processor;
134 
136 
137  std::shared_ptr<Amp> _trim;
138 
139  class OutputFormatControl : public MPControl<bool>
140  {
141  public:
142  OutputFormatControl (bool v, std::string const& n, PBD::Controllable::Flag f);
143  virtual std::string get_user_string () const;
144  };
145 
146  std::shared_ptr<OutputFormatControl> _output_format_control;
147 
148  class BinauralRenderControl : public MPControl<bool>
149  {
150  public:
151  BinauralRenderControl (bool v, std::string const& n, PBD::Controllable::Flag f);
152  virtual std::string get_user_string () const;
153  };
154 
155  std::shared_ptr<BinauralRenderControl> _binaural_render_control;
156 
157 #ifdef __APPLE__
158  ::AudioUnit _au;
159  AudioBufferList* _au_buffers;
160  samplecnt_t _au_samples_processed;
161  float* _au_data[12];
162 
163  struct LIBARDOUR_API AUParameter {
164  AudioUnitParameterID id;
165  AudioUnitScope scope;
166  AudioUnitElement element;
167  std::string label;
168  float lower, upper, normal;
169  };
170 
171  std::vector<AUParameter> _au_params;
172  std::vector<AUPreset> _au_presets;
173 
174  static OSStatus _render_callback(void*, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList*);
175  OSStatus render_callback(AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList*);
176 #endif
177 
179  LV2_Atom_Forge _forge;
180  uint8_t _atom_buf[8192];
181  pan_t _current_value[max_object_id][num_pan_parameters];
182  int _current_render_mode[max_object_id];
183  size_t _channel_id_map[max_object_id];
193  bool _rolling;
194  bool _with_bed;
198  float _ffoa;
199  std::string _export_reference;
201  std::atomic<int> _flush;
202 };
203 
204 } // namespace ARDOUR
205 
206 #endif /* __ardour_surround_return_h__ */
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:25
Temporal::samplepos_t samplepos_t