Skip to content

Commit

Permalink
Pre-prepare some buffers for output buffer analysis on detection thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchmindtree committed May 7, 2018
1 parent 3b8e647 commit b47325c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/audio/detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ fn run(
model.sound_buffer_tx.push(buffer);
}

// Pre-prepare some output buffers.
const OUTPUT_BUFFERS_TO_PREPARE: usize = 3;
for _ in 0..OUTPUT_BUFFERS_TO_PREPARE {
let buffer = Vec::with_capacity(FRAMES_PER_BUFFER * MAX_CHANNELS);
let info = Default::default();
model.output_buffer_tx.push((buffer, info));
}

// Begin the loop.
loop {
let msg = match rx.try_pop() {
Expand All @@ -367,6 +375,7 @@ fn run(
match msg {
// Insert the new sound into the map.
Message::AddSound(sound_id, channels) => {

let sound = new_sound(channels);
model.sounds.insert(sound_id, sound);

Expand Down Expand Up @@ -489,7 +498,6 @@ fn run(

// For each speaker, feed its amplitude into its detectors.
for (&id, speaker) in &speaker_infos {

// Skip speakers that are out of range of the buffer.
if channels <= speaker.channel {
continue;
Expand Down

0 comments on commit b47325c

Please sign in to comment.