-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
proc_audio_buffers.rs
624 lines (581 loc) · 26.8 KB
/
proc_audio_buffers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
use std::fmt::DebugStruct;
use super::buffer_layout::{
CurrentMainLayout, MonoIn64Res, MonoInOut64Res, MonoInPlace32Res, MonoInPlace64Res,
MonoInStereOut64Res, MonoOut64Res, StereoIn64Res, StereoInMonoOut64Res, StereoInOut64Res,
StereoInPlace32Res, StereoInPlace64Res, StereoOut64Res,
};
use super::{AudioPortBuffer, ProcInfo};
/// The audio port buffers sent to the plugin's `process()` method.
pub struct ProcAudioBuffers {
/// The audio buffers for the main audio ports.
pub main: ProcMainBuffers,
/// The audio buffers for any extra audio ports (**NOT** including the
/// main ports).
pub extra: ProcExtraBuffers,
}
pub struct ProcMainBuffers {
in_f32: Option<AudioPortBuffer<f32>>,
in_f64: Option<AudioPortBuffer<f64>>,
out_f32: Option<AudioPortBuffer<f32>>,
out_f64: Option<AudioPortBuffer<f64>>,
layout: CurrentMainLayout,
}
impl ProcMainBuffers {
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoIn`. This will always return `None`
/// otherwise.
pub fn stereo_in(&self, proc_info: &ProcInfo) -> Option<(&[f32], &[f32])> {
if let CurrentMainLayout::StereoIn32 = self.layout {
let (left, right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
Some((left, right))
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoInPrefers64`. This will always return `None`
/// otherwise.
pub fn stereo_in_prefers_64<'a>(&'a self, proc_info: &ProcInfo) -> Option<StereoIn64Res<'a>> {
if let CurrentMainLayout::StereoIn64 = self.layout {
let (left, right) =
unsafe { self.in_f64.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
Some(StereoIn64Res::F64 { left, right })
} else if let CurrentMainLayout::StereoIn32 = self.layout {
let (left, right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
Some(StereoIn64Res::F32 { left, right })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoOut`. This will always return `None`
/// otherwise.
pub fn stereo_out(&mut self, proc_info: &ProcInfo) -> Option<(&mut [f32], &mut [f32])> {
if let CurrentMainLayout::StereoOut32 = self.layout {
let (left, right) =
unsafe { self.in_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some((left, right))
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoOutPrefers64`. This will always return `None`
/// otherwise.
pub fn stereo_out_prefers_64<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<StereoOut64Res<'a>> {
if let CurrentMainLayout::StereoOut64 = self.layout {
let (left, right) =
unsafe { self.in_f64.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoOut64Res::F64 { left, right })
} else if let CurrentMainLayout::StereoOut32 = self.layout {
let (left, right) =
unsafe { self.in_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoOut64Res::F32 { left, right })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoIn`. This will always return `None`
/// otherwise.
pub fn mono_in(&self, proc_info: &ProcInfo) -> Option<&[f32]> {
if let CurrentMainLayout::MonoIn32 = self.layout {
let b = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
Some(b)
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoInPrefers64`. This will always return `None`
/// otherwise.
pub fn mono_in_prefers_64<'a>(&'a self, proc_info: &ProcInfo) -> Option<MonoIn64Res<'a>> {
if let CurrentMainLayout::MonoIn64 = self.layout {
let b = unsafe { self.in_f64.as_ref().unwrap_unchecked().mono(proc_info) };
Some(MonoIn64Res::F64(b))
} else if let CurrentMainLayout::MonoIn32 = self.layout {
let b = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
Some(MonoIn64Res::F32(b))
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoOut`. This will always return `None`
/// otherwise.
pub fn mono_out(&mut self, proc_info: &ProcInfo) -> Option<&mut [f32]> {
if let CurrentMainLayout::MonoOut32 = self.layout {
let b = unsafe { self.in_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(b)
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoOutPrefers64`. This will always return `None`
/// otherwise.
pub fn mono_out_prefers_64<'a>(&'a mut self, proc_info: &ProcInfo) -> Option<MonoOut64Res<'a>> {
if let CurrentMainLayout::MonoOut64 = self.layout {
let b = unsafe { self.in_f64.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoOut64Res::F64(b))
} else if let CurrentMainLayout::MonoOut32 = self.layout {
let b = unsafe { self.in_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoOut64Res::F32(b))
} else {
None
}
}
/// If the plugin uses the default for the `AudioPortsExtension`, then this will
/// always return `Some`.
///
/// If the plugin does not use the default for the `AudioPortsExtension` and it
/// does not use `MainPortsLayout::StereoInPlace`, then this will return `None`.
pub fn stereo_in_place<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<StereoInPlace32Res<'a>> {
if let CurrentMainLayout::StereoInPlace32 = self.layout {
let (left, right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInPlace32Res::InPlace { left, right })
} else if let CurrentMainLayout::StereoInOut32 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInPlace32Res::Separate { in_left, in_right, out_left, out_right })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoInPlacePrefersF64`. This will always return
/// `None` otherwise.
pub fn stereo_in_place_prefers_64<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<StereoInPlace64Res<'a>> {
if let CurrentMainLayout::StereoInPlace64 = self.layout {
let (left, right) =
unsafe { self.out_f64.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInPlace64Res::InPlace64 { left, right })
} else if let CurrentMainLayout::StereoInOut64 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f64.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f64.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInPlace64Res::Separate64 { in_left, in_right, out_left, out_right })
} else if let CurrentMainLayout::StereoInPlace32 = self.layout {
let (left, right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInPlace64Res::InPlace32 { left, right })
} else if let CurrentMainLayout::StereoInOut32 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInPlace64Res::Separate32 { in_left, in_right, out_left, out_right })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoInOut`. This will always return `None`
/// otherwise.
pub fn stereo_in_out(
&mut self,
proc_info: &ProcInfo,
) -> Option<(&[f32], &[f32], &mut [f32], &mut [f32])> {
if let CurrentMainLayout::StereoInOut32 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some((in_left, in_right, out_left, out_right))
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoInOutPrefers64`. This will always return `None`
/// otherwise.
pub fn stereo_in_out_prefers_64<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<StereoInOut64Res<'a>> {
if let CurrentMainLayout::StereoInOut64 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f64.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f64.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInOut64Res::F64 { in_left, in_right, out_left, out_right })
} else if let CurrentMainLayout::StereoInOut32 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(StereoInOut64Res::F32 { in_left, in_right, out_left, out_right })
} else {
None
}
}
/// If the plugin uses the default for the `AudioPortsExtension`, then this will
/// always return `Some`.
///
/// If the plugin does not use the default for the `AudioPortsExtension` and it
/// does not use `MainPortsLayout::MonoInPlace`, then this will return `None`.
pub fn mono_in_place<'a>(&'a mut self, proc_info: &ProcInfo) -> Option<MonoInPlace32Res<'a>> {
if let CurrentMainLayout::MonoInPlace32 = self.layout {
let b = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInPlace32Res::InPlace(b))
} else if let CurrentMainLayout::MonoInOut32 = self.layout {
let input = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
let output = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInPlace32Res::Separate { input, output })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoInPlacePrefersF64`. This will always return
/// `None` otherwise.
pub fn mono_in_place_prefers_64<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<MonoInPlace64Res<'a>> {
if let CurrentMainLayout::MonoInPlace64 = self.layout {
let b = unsafe { self.out_f64.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInPlace64Res::InPlace64(b))
} else if let CurrentMainLayout::MonoInOut64 = self.layout {
let input = unsafe { self.in_f64.as_ref().unwrap_unchecked().mono(proc_info) };
let output = unsafe { self.out_f64.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInPlace64Res::Separate64 { input, output })
} else if let CurrentMainLayout::MonoInPlace32 = self.layout {
let b = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInPlace64Res::InPlace32(b))
} else if let CurrentMainLayout::MonoInOut32 = self.layout {
let input = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
let output = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInPlace64Res::Separate32 { input, output })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoInOut`. This will always return `None`
/// otherwise.
pub fn mono_in_out(&mut self, proc_info: &ProcInfo) -> Option<(&[f32], &mut [f32])> {
if let CurrentMainLayout::MonoInOut32 = self.layout {
let input = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
let output = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some((input, output))
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoInOutPrefers64`. This will always return `None`
/// otherwise.
pub fn mono_in_out_prefers_64<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<MonoInOut64Res<'a>> {
if let CurrentMainLayout::MonoInOut64 = self.layout {
let input = unsafe { self.in_f64.as_ref().unwrap_unchecked().mono(proc_info) };
let output = unsafe { self.out_f64.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInOut64Res::F64 { input, output })
} else if let CurrentMainLayout::MonoInOut32 = self.layout {
let input = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
let output = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(MonoInOut64Res::F32 { input, output })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoInStereoOut`. This will always return `None`
/// otherwise.
pub fn mono_in_stereo_out(
&mut self,
proc_info: &ProcInfo,
) -> Option<(&[f32], &mut [f32], &mut [f32])> {
if let CurrentMainLayout::MonoInStereoOut32 = self.layout {
let input = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some((input, out_left, out_right))
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::MonoInStereoOutPrefers64`. This will always return `None`
/// otherwise.
pub fn mono_in_stereo_out_prefers_64<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<MonoInStereOut64Res<'a>> {
if let CurrentMainLayout::MonoInStereoOut64 = self.layout {
let input = unsafe { self.in_f64.as_ref().unwrap_unchecked().mono(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f64.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(MonoInStereOut64Res::F64 { input, out_left, out_right })
} else if let CurrentMainLayout::MonoInStereoOut32 = self.layout {
let input = unsafe { self.in_f32.as_ref().unwrap_unchecked().mono(proc_info) };
let (out_left, out_right) =
unsafe { self.out_f32.as_mut().unwrap_unchecked().stereo_unchecked_mut(proc_info) };
Some(MonoInStereOut64Res::F32 { input, out_left, out_right })
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoInMonoOut`. This will always return `None`
/// otherwise.
pub fn stereo_in_mono_out(
&mut self,
proc_info: &ProcInfo,
) -> Option<(&[f32], &[f32], &mut [f32])> {
if let CurrentMainLayout::StereoInMonoOut32 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let output = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some((in_left, in_right, output))
} else {
None
}
}
/// This will always return `Some` if the plugin uses the `AudioPortsExtension`
/// and uses `MainPortsLayout::StereoInMonoOutPrefers64`. This will always return `None`
/// otherwise.
pub fn stereo_in_mono_out_prefers_64<'a>(
&'a mut self,
proc_info: &ProcInfo,
) -> Option<StereoInMonoOut64Res> {
if let CurrentMainLayout::StereoInMonoOut64 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f64.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let output = unsafe { self.out_f64.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(StereoInMonoOut64Res::F64 { in_left, in_right, output })
} else if let CurrentMainLayout::StereoInMonoOut32 = self.layout {
let (in_left, in_right) =
unsafe { self.in_f32.as_ref().unwrap_unchecked().stereo_unchecked(proc_info) };
let output = unsafe { self.out_f32.as_mut().unwrap_unchecked().mono_mut(proc_info) };
Some(StereoInMonoOut64Res::F32 { in_left, in_right, output })
} else {
None
}
}
/// Get the raw buffers.
///
/// Use this if the plugin uses the `AudioPortsExtension` and uses
/// `MainPortsLayout::Custom`.
pub fn raw<'a>(&'a mut self) -> RawMainBuffers<'a> {
RawMainBuffers {
in_f32: &self.in_f32,
in_f64: &self.in_f64,
out_f32: &mut self.out_f32,
out_f64: &mut self.out_f64,
}
}
/// NOT IMPLEMENTED YET
///
/// Returns `true` if the main audio input buffer exists and is silent (all zeros),
/// false otherwise.
pub fn in_port_is_silent(&self) -> bool {
false
}
}
pub struct ProcExtraBuffers {
in_f32: Vec<Option<AudioPortBuffer<f32>>>,
in_f64: Vec<Option<AudioPortBuffer<f64>>>,
out_f32: Vec<Option<AudioPortBuffer<f32>>>,
out_f64: Vec<Option<AudioPortBuffer<f64>>>,
}
impl ProcExtraBuffers {
pub fn raw<'a>(&'a mut self) -> RawExtraBuffers<'a> {
RawExtraBuffers {
in_f32: &self.in_f32,
in_f64: &self.in_f64,
out_f32: &mut self.out_f32,
out_f64: &mut self.out_f64,
}
}
/// NOT IMPLEMENTED YET
///
/// Returns `true` if the extra audio input buffer exists and is silent (all zeros),
/// false otherwise.
pub fn in_port_is_silent(&self, port_index: usize) -> bool {
false
}
}
/// The raw audio buffers for the main audio ports.
pub struct RawMainBuffers<'a> {
/// The `f32` audio buffer for the main audio input port.
///
/// This can be `None` because of any of these conditions:
///
/// * This plugin has no main input port.
/// * This input port has requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, and the host has decided to give this port 64 bit
/// buffers. In that case the buffer will exist in `in_f64` instead.
/// * This input port is in an "in_place_pair" with the main output port, and
/// the host has decided to give a single buffer for both the main input and
/// output ports. In this case the buffer will exist in `out_f32` or `out_f64`
/// instead.
pub in_f32: &'a Option<AudioPortBuffer<f32>>,
/// The `f64` audio buffer for the main audio input port.
///
/// This can be `None` because of any of these conditions:
///
/// * This plugin has no main input port.
/// * This input port has requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, but the host has decided to give this port 32 bit
/// buffers. In that case the buffer will exist in `in_f32` instead.
/// * This input port is in an "in_place_pair" with the main output port, and
/// the host has decided to give a single buffer for both the main input and
/// output ports. In this case the buffer will exist in `out_f32` or `out_f64`
/// instead.
pub in_f64: &'a Option<AudioPortBuffer<f64>>,
/// The `f32` audio buffer for the main audio output port.
///
/// This can be `None` because of any of these conditions:
///
/// * This plugin has no main output port.
/// * This output port has requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, and the host has decided to give this port 64 bit
/// buffers. In that case the buffer will exist in `out_f64` instead.
///
/// # SAFETY
///
/// Undefined behavior may occur if you change any `None` to `Some` or
/// vice versa. So please don't do that.
pub out_f32: &'a mut Option<AudioPortBuffer<f32>>,
/// The `f64` audio buffer for the main audio output port.
///
/// This can be `None` because of any of these conditions:
///
/// * This plugin has no main output port.
/// * This output port has requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, but the host has decided to give this port 32 bit
/// buffers. In that case the buffer will exist in `out_f32` instead.
///
/// # SAFETY
///
/// Undefined behavior may occur if you change any `None` to `Some` or
/// vice versa. So please don't do that.
pub out_f64: &'a mut Option<AudioPortBuffer<f64>>,
}
/// The raw audio buffers for the extra audio ports (**NOT** including
/// the main ports).
pub struct RawExtraBuffers<'a> {
/// The `f32` audio buffers for each extra audio input port (**NOT** including
/// the main port), in order.
///
/// A buffer can be `None` because of any of these conditions:
///
/// * This input port has requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, and the host has decided to give this port 64 bit
/// buffers. In that case the buffer will exist in `in_f64` instead.
pub in_f32: &'a [Option<AudioPortBuffer<f32>>],
/// The `f64` audio buffers for each extra audio input port (**NOT** including
/// the main port), in order.
///
/// A buffer can be `None` because of any of these conditions:
///
/// * This input port has not requested to use 64 bit buffers in
/// `AudioPortInfo::flags` (if this plugin does not use the
/// `PluginAudioPortsExtension` then it does not request 64 bit buffers
/// by default). In this case this will always be `None`.
/// * This input port *has* requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, but the host has decided to give this port 32
/// bit buffers anyway. In that case the buffer will exist in `in_f32`
/// instead.
pub in_f64: &'a [Option<AudioPortBuffer<f64>>],
/// The `f32` audio buffers for each extra audio output port (**NOT** including
/// the main port), in order.
///
/// A buffer can be `None` because in this condition:
///
/// * This output port has requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, and the host has decided to give this port 64 bit
/// buffers. In that case the buffer will exist in `out_f64` instead.
///
/// # SAFETY
///
/// Undefined behavior may occur if you change any `None` to `Some` or
/// vice versa. So please don't do that.
pub out_f32: &'a mut [Option<AudioPortBuffer<f32>>],
/// The `f64` audio buffers for each extra audio output port (**NOT** including
/// the main port), in order.
///
/// A buffer can be `None` because of any of these conditions:
///
/// * This output port has not requested to use 64 bit buffers in
/// `AudioPortInfo::flags` (if this plugin does not use the
/// `PluginAudioPortsExtension` then it does not request 64 bit buffers
/// by default). In this case this will always be `None`.
/// * This output port *has* requested to use 64 bit buffers in
/// `AudioPortInfo::flags`, but the host has decided to give this port 32
/// bit buffers anyway. In that case the buffer will exist in `out_f32`
/// instead.
///
/// # SAFETY
///
/// Undefined behavior may occur if you change any `None` to `Some` or
/// vice versa. So please don't do that.
pub out_f64: &'a mut [Option<AudioPortBuffer<f64>>],
}
impl ProcAudioBuffers {
pub(crate) fn debug_fields(&self, f: &mut DebugStruct) {
f.field("main_layout", &self.main.layout);
if let Some(main_in_f32) = &self.main.in_f32 {
f.field("main_in_f32: {:?}", main_in_f32);
}
if let Some(main_in_f64) = &self.main.in_f64 {
f.field("main_in_f64: {:?}", main_in_f64);
}
if let Some(main_out_f32) = &self.main.out_f32 {
f.field("main_out_f32: {:?}", main_out_f32);
}
if let Some(main_out_f64) = &self.main.out_f64 {
f.field("main_out_f64: {:?}", main_out_f64);
}
if !self.extra.in_f32.is_empty() {
f.field("extra_in_f32: {}", &self.extra.in_f32);
}
if !self.extra.in_f64.is_empty() {
f.field("extra_in_f64: {}", &self.extra.in_f64);
}
if !self.extra.out_f32.is_empty() {
f.field("extra_out_f32: {}", &self.extra.out_f32);
}
if !self.extra.out_f64.is_empty() {
f.field("extra_out_f64: {}", &self.extra.out_f64);
}
}
/// Clear all of the output buffers to `0.0`.
pub fn clear_all_outputs(&mut self, proc_info: &ProcInfo) {
if let Some(b) = &mut self.main.out_f32 {
b.clear(proc_info);
}
if let Some(b) = &mut self.main.out_f64 {
b.clear(proc_info);
}
for b in self.extra.out_f32.iter_mut() {
if let Some(b) = b.as_mut() {
b.clear(proc_info);
}
}
for b in self.extra.out_f64.iter_mut() {
if let Some(b) = b.as_mut() {
b.clear(proc_info);
}
}
}
}