try to fix audio play noise;improve audio performance

This commit is contained in:
csf
2022-02-22 20:45:49 +08:00
parent 4a03c60ac1
commit 82d5924401
5 changed files with 45 additions and 19 deletions

View File

@@ -607,9 +607,12 @@ impl AudioHandler {
config,
move |data: &mut [T], _: &_| {
let mut lock = audio_buffer.lock().unwrap();
let mut n = data.len();
let n = data.len();
if lock.len() < n {
n = lock.len();
// [data] -- the audio data consumer,size around 2500 in 48000/f32 (50ms),
// [audio_buffer] -- the audio data provider,must bigger than the consumer to avoid audio clipping noise
// the audio_buffer may have empty data when idle,there will always ZERO AUDIO DATA
return;
}
let mut input = lock.drain(0..n);
for sample in data.iter_mut() {