This commit is contained in:
tux
2026-11-03 22:13:16 +01:00
parent 158e115242
commit 8012e912ec
19 changed files with 975 additions and 208 deletions
+25
View File
@@ -275,6 +275,31 @@ pub trait Drive {
begin: i64,
sectors: i64,
) -> Result<usize, ReadError>;
/// Read audio directly into a host-endian `i16` buffer.
///
/// This is a byte-view over the same memory; it lets the paranoia engine
/// read straight into the `CBlock` vector without an intermediate
/// `Vec<u8>` plus `bytes_to_samples()` copy. Implementations of
/// `read_audio()` already promise host endian PCM data.
fn read_audio_samples(
&mut self,
buffer: &mut [i16],
begin: i64,
sectors: i64,
) -> Result<usize, ReadError> {
// SAFETY: `i16` has no padding and the byte view covers exactly the
// initialized elements of `buffer`. The view lives only for this
// call, and all bytes are written by the backend before it returns.
let bytes = unsafe {
std::slice::from_raw_parts_mut(
buffer.as_mut_ptr().cast::<u8>(),
std::mem::size_of_val(buffer),
)
};
self.read_audio(Some(bytes), begin, sectors)
}
/// Low-level read without host-endian conversion, matching the original
/// `cdrom_drive::read_audio` function pointer.
fn read_audio_raw(