mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
perf: remove allocation from sampler callback
This commit is contained in:
parent
2a96c19069
commit
4204ac4462
1 changed files with 5 additions and 9 deletions
|
|
@ -68,14 +68,8 @@ impl Sampler {
|
||||||
}
|
}
|
||||||
// Emit next chunk of each currently playing voice,
|
// Emit next chunk of each currently playing voice,
|
||||||
// dropping voices that have reached their ends.
|
// dropping voices that have reached their ends.
|
||||||
let mut voices = vec![];
|
|
||||||
std::mem::swap(&mut voices, &mut self.voices);
|
|
||||||
let gain = 0.5;
|
let gain = 0.5;
|
||||||
loop {
|
self.voices.retain_mut(|voice|{
|
||||||
if voices.len() < 1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
let mut voice = voices.swap_remove(0);
|
|
||||||
if let Some(chunk) = voice.chunk(scope.n_frames() as usize) {
|
if let Some(chunk) = voice.chunk(scope.n_frames() as usize) {
|
||||||
for (i, channel) in chunk.iter().enumerate() {
|
for (i, channel) in chunk.iter().enumerate() {
|
||||||
let buffer = &mut mixed[i % channel_count];
|
let buffer = &mut mixed[i % channel_count];
|
||||||
|
|
@ -83,9 +77,11 @@ impl Sampler {
|
||||||
buffer[i] += sample * gain;
|
buffer[i] += sample * gain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.voices.push(voice);
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
// Write output buffer to output ports.
|
// Write output buffer to output ports.
|
||||||
for (i, port) in self.ports.audio_outs.values_mut().enumerate() {
|
for (i, port) in self.ports.audio_outs.values_mut().enumerate() {
|
||||||
let buffer = &mixed[i];
|
let buffer = &mixed[i];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue