Skip to content

Commit

Permalink
more docs wip
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopyl committed Oct 20, 2024
1 parent 431dd13 commit 90fc64d
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 50 deletions.
42 changes: 21 additions & 21 deletions host/src/process/audio_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct AudioPortBuffer<I32, I64> {
pub latency: u32,
}

// bikeshed
// TODO: bikeshed
pub struct AudioPorts {
buffer_lists: Vec<*mut f32>, // Can be f32 or f64, cast on-demand
buffer_configs: Vec<clap_audio_buffer>,
Expand Down Expand Up @@ -207,16 +207,13 @@ impl AudioPorts {
}
}

// SAFETY: TODO
unsafe {
AudioBuffers {
buffers: *(&mut self.buffer_configs[..total] as *mut _ as *mut _),
frames_count: if min_channel_buffer_length == usize::MAX {
None
} else {
Some(min_channel_buffer_length as u32)
},
}
AudioBuffers {
buffers: CelledClapAudioBuffer::from_raw_slice(&mut self.buffer_configs[..total]),
frames_count: if min_channel_buffer_length == usize::MAX {
None
} else {
Some(min_channel_buffer_length as u32)
},
}
}

Expand Down Expand Up @@ -308,16 +305,13 @@ impl AudioPorts {
}
}

// SAFETY: TODO
unsafe {
AudioBuffers {
buffers: *(&mut self.buffer_configs[..total] as *mut _ as *mut _),
frames_count: if min_channel_buffer_length == usize::MAX {
None
} else {
Some(min_channel_buffer_length as u32)
},
}
AudioBuffers {
buffers: CelledClapAudioBuffer::from_raw_slice(&mut self.buffer_configs[..total]),
frames_count: if min_channel_buffer_length == usize::MAX {
None
} else {
Some(min_channel_buffer_length as u32)
},
}
}

Expand Down Expand Up @@ -346,6 +340,12 @@ impl CelledClapAudioBuffer {
pub(crate) fn slice_as_raw_ptr(slice: &[CelledClapAudioBuffer]) -> *mut [clap_audio_buffer] {
slice as *const _ as *const _ as *mut _
}

#[inline]
pub(crate) fn from_raw_slice(slice: &mut [clap_audio_buffer]) -> &[Self] {
// SAFETY: TODO
unsafe { &*(slice as *mut [clap_audio_buffer] as *mut [CelledClapAudioBuffer]) }
}
}

#[derive(Copy, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ impl<'a> Events<'a> {
/// let Some(mut channel_pairs) = port_pair.channels()?.into_f32() else { continue; };
///
/// // Buffers to hold pointers to the left and right channels
/// let mut input_channels: [Option<AudioBuffer<f32>>; 2] = [None, None];
/// let mut output_channels: [Option<AudioBuffer<f32>>; 2] = [None, None];
/// let mut input_channels: [Option<&AudioBuffer<f32>>; 2] = [None, None];
/// let mut output_channels: [Option<&AudioBuffer<f32>>; 2] = [None, None];
///
/// // Before we can process the buffers, we need to check all the necessary channels
/// // are present, in case the host messed up the port configuration.
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/process/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod pair;
mod port;
mod sample_type;

pub use buffer::AudioBuffer;
pub use buffer::*;
pub use error::BufferError;
pub use pair::*;
pub use port::*;
Expand Down
Loading

0 comments on commit 90fc64d

Please sign in to comment.