Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

audio_processor.h 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * travesty, pure C VST3-compatible interface
  3. * Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include "base.h"
  18. #include "events.h"
  19. #include "align_push.h"
  20. /**
  21. * speakers
  22. */
  23. typedef uint64_t v3_speaker_arrangement;
  24. enum {
  25. V3_SPEAKER_L = 1 << 0,
  26. V3_SPEAKER_R = 1 << 1,
  27. V3_SPEAKER_M = 1 << 19
  28. };
  29. /**
  30. * process setup
  31. */
  32. enum v3_process_mode {
  33. V3_REALTIME,
  34. V3_PREFETCH,
  35. V3_OFFLINE
  36. };
  37. static inline
  38. const char* v3_process_mode_str(int32_t d)
  39. {
  40. switch (d)
  41. {
  42. case V3_REALTIME:
  43. return "V3_REALTIME";
  44. case V3_PREFETCH:
  45. return "V3_PREFETCH";
  46. case V3_OFFLINE:
  47. return "V3_OFFLINE";
  48. default:
  49. return "[unknown]";
  50. }
  51. }
  52. enum {
  53. V3_SAMPLE_32,
  54. V3_SAMPLE_64
  55. };
  56. static inline
  57. const char* v3_sample_size_str(int32_t d)
  58. {
  59. switch (d)
  60. {
  61. case V3_SAMPLE_32:
  62. return "V3_SAMPLE_32";
  63. case V3_SAMPLE_64:
  64. return "V3_SAMPLE_64";
  65. default:
  66. return "[unknown]";
  67. }
  68. }
  69. struct v3_process_setup {
  70. int32_t process_mode;
  71. int32_t symbolic_sample_size;
  72. int32_t max_block_size;
  73. double sample_rate;
  74. };
  75. /**
  76. * param changes
  77. */
  78. struct v3_param_value_queue {
  79. struct v3_funknown;
  80. v3_param_id (V3_API* get_param_id)(void* self);
  81. int32_t (V3_API* get_point_count)(void* self);
  82. v3_result (V3_API* get_point)(void* self, int32_t idx, int32_t* sample_offset, double* value);
  83. v3_result (V3_API* add_point)(void* self, int32_t sample_offset, double value, int32_t* idx);
  84. };
  85. static constexpr const v3_tuid v3_param_value_queue_iid =
  86. V3_ID(0x01263A18, 0xED074F6F, 0x98C9D356, 0x4686F9BA);
  87. struct v3_param_changes {
  88. struct v3_funknown;
  89. int32_t (V3_API* get_param_count)(void* self);
  90. struct v3_param_value_queue** (V3_API* get_param_data)(void* self, int32_t idx);
  91. struct v3_param_value_queue** (V3_API* add_param_data)(void* self, v3_param_id* id, int32_t* index);
  92. };
  93. static constexpr const v3_tuid v3_param_changes_iid =
  94. V3_ID(0xA4779663, 0x0BB64A56, 0xB44384A8, 0x466FEB9D);
  95. /**
  96. * process context
  97. */
  98. struct v3_frame_rate {
  99. uint32_t fps;
  100. uint32_t flags;
  101. };
  102. struct v3_chord {
  103. uint8_t key_note;
  104. uint8_t root_note;
  105. int16_t chord_mask;
  106. };
  107. enum {
  108. V3_PROCESS_CTX_PLAYING = 1 << 1,
  109. V3_PROCESS_CTX_CYCLE_ACTIVE = 1 << 2,
  110. V3_PROCESS_CTX_RECORDING = 1 << 3,
  111. V3_PROCESS_CTX_SYSTEM_TIME_VALID = 1 << 8,
  112. V3_PROCESS_CTX_PROJECT_TIME_VALID = 1 << 9,
  113. V3_PROCESS_CTX_TEMPO_VALID = 1 << 10,
  114. V3_PROCESS_CTX_BAR_POSITION_VALID = 1 << 11,
  115. V3_PROCESS_CTX_CYCLE_VALID = 1 << 12,
  116. V3_PROCESS_CTX_TIME_SIG_VALID = 1 << 13,
  117. V3_PROCESS_CTX_SMPTE_VALID = 1 << 14,
  118. V3_PROCESS_CTX_NEXT_CLOCK_VALID = 1 << 15,
  119. V3_PROCESS_CTX_CONT_TIME_VALID = 1 << 17,
  120. V3_PROCESS_CTX_CHORD_VALID = 1 << 18
  121. };
  122. struct v3_process_context {
  123. uint32_t state;
  124. double sample_rate;
  125. int64_t project_time_in_samples; // with loop
  126. int64_t system_time_ns;
  127. int64_t continuous_time_in_samples; // without loop
  128. double project_time_quarters;
  129. double bar_position_quarters;
  130. double cycle_start_quarters;
  131. double cycle_end_quarters;
  132. double bpm;
  133. int32_t time_sig_numerator;
  134. int32_t time_sig_denom;
  135. struct v3_chord chord;
  136. int32_t smpte_offset_subframes;
  137. struct v3_frame_rate frame_rate;
  138. int32_t samples_to_next_clock;
  139. };
  140. /**
  141. * process context requirements
  142. */
  143. enum {
  144. V3_PROCESS_CTX_NEED_SYSTEM_TIME = 1 << 0,
  145. V3_PROCESS_CTX_NEED_CONTINUOUS_TIME = 1 << 1,
  146. V3_PROCESS_CTX_NEED_PROJECT_TIME = 1 << 2,
  147. V3_PROCESS_CTX_NEED_BAR_POSITION = 1 << 3,
  148. V3_PROCESS_CTX_NEED_CYCLE = 1 << 4,
  149. V3_PROCESS_CTX_NEED_NEXT_CLOCK = 1 << 5,
  150. V3_PROCESS_CTX_NEED_TEMPO = 1 << 6,
  151. V3_PROCESS_CTX_NEED_TIME_SIG = 1 << 7,
  152. V3_PROCESS_CTX_NEED_CHORD = 1 << 8,
  153. V3_PROCESS_CTX_NEED_FRAME_RATE = 1 << 9,
  154. V3_PROCESS_CTX_NEED_TRANSPORT_STATE = 1 << 10
  155. };
  156. struct v3_process_context_requirements {
  157. struct v3_funknown;
  158. uint32_t (V3_API* get_process_context_requirements)(void* self);
  159. };
  160. static constexpr const v3_tuid v3_process_context_requirements_iid =
  161. V3_ID(0x2A654303, 0xEF764E3D, 0x95B5FE83, 0x730EF6D0);
  162. /**
  163. * process data and context
  164. */
  165. struct v3_audio_bus_buffers {
  166. int32_t num_channels;
  167. uint64_t channel_silence_bitset;
  168. union {
  169. float** channel_buffers_32;
  170. double** channel_buffers_64;
  171. };
  172. };
  173. struct v3_process_data {
  174. int32_t process_mode;
  175. int32_t symbolic_sample_size;
  176. int32_t nframes;
  177. int32_t num_input_buses;
  178. int32_t num_output_buses;
  179. struct v3_audio_bus_buffers* inputs;
  180. struct v3_audio_bus_buffers* outputs;
  181. struct v3_param_changes** input_params;
  182. struct v3_param_changes** output_params;
  183. struct v3_event_list** input_events;
  184. struct v3_event_list** output_events;
  185. struct v3_process_context* ctx;
  186. };
  187. /**
  188. * audio processor
  189. */
  190. struct v3_audio_processor {
  191. struct v3_funknown;
  192. v3_result (V3_API* set_bus_arrangements)(void* self, v3_speaker_arrangement* inputs, int32_t num_inputs,
  193. v3_speaker_arrangement* outputs, int32_t num_outputs);
  194. v3_result (V3_API* get_bus_arrangement)(void* self, int32_t bus_direction, int32_t idx, v3_speaker_arrangement*);
  195. v3_result (V3_API* can_process_sample_size)(void* self, int32_t symbolic_sample_size);
  196. uint32_t (V3_API* get_latency_samples)(void* self);
  197. v3_result (V3_API* setup_processing)(void* self, struct v3_process_setup* setup);
  198. v3_result (V3_API* set_processing)(void* self, v3_bool state);
  199. v3_result (V3_API* process)(void* self, struct v3_process_data* data);
  200. uint32_t (V3_API* get_tail_samples)(void* self);
  201. };
  202. static constexpr const v3_tuid v3_audio_processor_iid =
  203. V3_ID(0x42043F99, 0xB7DA453C, 0xA569E79D, 0x9AAEC33D);
  204. #ifdef __cplusplus
  205. /**
  206. * C++ variants
  207. */
  208. struct v3_param_value_queue_cpp : v3_funknown {
  209. v3_param_value_queue queue;
  210. };
  211. struct v3_param_changes_cpp : v3_funknown {
  212. v3_param_changes changes;
  213. };
  214. struct v3_process_context_requirements_cpp : v3_funknown {
  215. v3_process_context_requirements req;
  216. };
  217. struct v3_audio_processor_cpp : v3_funknown {
  218. v3_audio_processor proc;
  219. };
  220. #endif
  221. #include "align_pop.h"