pub struct AudioBufferMut<'a> { /* private fields */ }
Expand description
Writable audio buffer.
Implementations§
Source§impl<'a> AudioBufferMut<'a>
impl<'a> AudioBufferMut<'a>
Sourcepub const unsafe fn new_unchecked(
process: &'a mut Process,
clap_audio_buffer: NonNull<clap_audio_buffer>,
) -> Self
pub const unsafe fn new_unchecked( process: &'a mut Process, clap_audio_buffer: NonNull<clap_audio_buffer>, ) -> Self
§Safety
clap_audio_buffer
must be a writable buffer that belongs to Process.
Sourcepub const fn data32(&mut self, channel: u32) -> &mut [f32]
pub const fn data32(&mut self, channel: u32) -> &mut [f32]
§Panic
This function will panic if channel
is greater or equal to
self.channel.count()
.
Examples found in repository?
examples/plugin_template.rs (line 102)
89 fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
90 // The `Process` API is almost entirely `const`.
91 // The methods are cheap to call in a loop on the audio thread.
92 for i in 0..process.frames_count() as usize {
93 // Get the input signal from the main input port.
94 let in_l = process.audio_inputs(0).data32(0)[i];
95 let in_r = process.audio_inputs(0).data32(1)[i];
96
97 // Process samples. Here we simply swap left and right channels.
98 let out_l = in_r;
99 let out_r = in_l;
100
101 // Write the audio signal to the main output port.
102 process.audio_outputs(0).data32(0)[i] = out_l;
103 process.audio_outputs(0).data32(1)[i] = out_r;
104 }
105 Ok(clap::Continue)
106 }
More examples
examples/gain.rs (line 167)
121 fn process(&mut self, process: &mut clap::Process) -> Result<clap::Status, clap::Error> {
122 let mut gain = f64::from_bits(self.gain.load(Ordering::Relaxed));
123
124 let nframes = process.frames_count();
125 let nev = process.in_events().size();
126 let mut ev_index = 0;
127 let mut next_ev_frame = if nev > 0 { 0 } else { nframes };
128
129 let mut i = 0;
130 while i < nframes {
131 while ev_index < nev && next_ev_frame == i {
132 {
133 let in_events = process.in_events();
134 let header = in_events.get(ev_index);
135 if header.time() != i {
136 next_ev_frame = header.time();
137 break;
138 }
139
140 if let Ok(param_value) = header.param_value() {
141 gain = param_value.value();
142 self.gain.store(gain.to_bits(), Ordering::Release);
143 }
144 }
145
146 ev_index += 1;
147
148 if ev_index == nev {
149 next_ev_frame = nframes;
150 break;
151 }
152 }
153
154 {
155 let i = i as usize;
156 let gain = gain as f32;
157
158 // Get the input signal from the main input port.
159 let in_l = process.audio_inputs(0).data32(0)[i];
160 let in_r = process.audio_inputs(0).data32(1)[i];
161
162 let smoothed = self.smoothed.tick(gain);
163 let out_l = in_l * smoothed;
164 let out_r = in_r * smoothed;
165
166 // Write the audio signal to the main output port.
167 process.audio_outputs(0).data32(0)[i] = out_l;
168 process.audio_outputs(0).data32(1)[i] = out_r;
169 }
170
171 i += 1;
172 }
173 Ok(clap::Continue)
174 }
Sourcepub const fn data64(&mut self, channel: u32) -> &mut [f64]
pub const fn data64(&mut self, channel: u32) -> &mut [f64]
§Panic
This function will panic if channel
is greater or equal to
self.channel.count()
.
pub const fn channel_count(&self) -> u32
pub const fn latency(&self) -> u32
pub const fn constant_mask(&self) -> u64
Auto Trait Implementations§
impl<'a> Freeze for AudioBufferMut<'a>
impl<'a> RefUnwindSafe for AudioBufferMut<'a>
impl<'a> !Send for AudioBufferMut<'a>
impl<'a> !Sync for AudioBufferMut<'a>
impl<'a> Unpin for AudioBufferMut<'a>
impl<'a> !UnwindSafe for AudioBufferMut<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more