fixed buffer size
This commit is contained in:
parent
df1ec7c08b
commit
6ec01630c0
1 changed files with 11 additions and 1 deletions
|
@ -6,6 +6,7 @@ use futures::executor;
|
|||
use gb_emu_lib::connect::{AudioOutput, DownsampleType};
|
||||
|
||||
const BUFFERS_PER_FRAME: usize = 5;
|
||||
const DEFAULT_BUFFER_SIZE: u32 = 64;
|
||||
const DOWNSAMPLE_TYPE: DownsampleType = DownsampleType::ZeroOrderHold;
|
||||
|
||||
pub fn create_output(muted: bool) -> (AudioOutput, Stream) {
|
||||
|
@ -21,12 +22,20 @@ pub fn create_output(muted: bool) -> (AudioOutput, Stream) {
|
|||
|
||||
let sample_rate = config.sample_rate().0;
|
||||
|
||||
let mut stream_config = config.config();
|
||||
|
||||
if let cpal::SupportedBufferSize::Range { min, max } = config.buffer_size() {
|
||||
stream_config.buffer_size =
|
||||
cpal::BufferSize::Fixed(DEFAULT_BUFFER_SIZE.min(*max).max(*min));
|
||||
}
|
||||
println!("got buffer size {:#?}", stream_config.buffer_size);
|
||||
|
||||
let (output, mut rx) = AudioOutput::new(sample_rate as f32, BUFFERS_PER_FRAME, DOWNSAMPLE_TYPE);
|
||||
|
||||
let stream = if muted {
|
||||
device
|
||||
.build_output_stream(
|
||||
&config.config(),
|
||||
&stream_config,
|
||||
move |data: &mut [f32], _info: &cpal::OutputCallbackInfo| {
|
||||
for _ in data.chunks_exact_mut(2) {
|
||||
match executor::block_on(rx.pop()) {
|
||||
|
@ -60,6 +69,7 @@ pub fn create_output(muted: bool) -> (AudioOutput, Stream) {
|
|||
)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
stream.play().unwrap();
|
||||
|
||||
(output, stream)
|
||||
|
|
Loading…
Add table
Reference in a new issue