1
0
Fork 0

Document the CPAL buffer size handling

This commit is contained in:
Robbert van der Helm 2024-05-05 22:36:21 +02:00
parent a5abe896ed
commit 916dfc16a2
2 changed files with 19 additions and 3 deletions

View file

@ -10,6 +10,14 @@ Since there is no stable release yet, the changes are organized per day in
reverse chronological order. The main purpose of this document in its current
state is to list breaking changes.
## [2024-05-05]
### Fixed
- The CPAL backend now correctly handles situations where it receives fewer
samples than configured.
- Fixed the handling of multichannel audio in the CPAL backend.
## [2024-05-04]
### Fixed

View file

@ -702,6 +702,8 @@ impl CpalMidir {
.main_input_channels
.map(NonZeroU32::get)
.unwrap_or(0) as usize;
// This may contain excess unused space at the end if we get fewer samples than configured
// from CPAL
let mut main_io_storage = vec![vec![0.0f32; buffer_size]; num_output_channels];
// This backend does not support auxiliary inputs and outputs, so in order to have the same
@ -824,10 +826,16 @@ impl CpalMidir {
}
{
let sample_count = data.len() / num_output_channels;
assert!(sample_count <= buffer_size);
// Even though we told CPAL that we wanted `buffer_size` samples, it may still give
// us fewer. If we receive more than what we configured, then this will panic.
let actual_sample_count = data.len() / num_output_channels;
assert!(
actual_sample_count <= buffer_size,
"Received {actual_sample_count} samples, while the configured buffer size is \
{buffer_size}"
);
let buffers = unsafe {
buffer_manager.create_buffers(0, sample_count, |buffer_sources| {
buffer_manager.create_buffers(0, actual_sample_count, |buffer_sources| {
*buffer_sources.main_output_channel_pointers = Some(ChannelPointers {
ptrs: NonNull::new(main_io_channel_pointers.get().as_mut_ptr())
.unwrap(),