Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added fix for output buffers only from alex
  • Loading branch information
piedoom committed Jan 12, 2018
1 parent 63cc767 commit 810e9f4
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/lib.rs
Expand Up @@ -23,9 +23,8 @@ impl Plugin for Whisper {
// Used by hosts to differentiate between plugins.
unique_id: 1337,

// We don't need inputs, but we're putting one in anyways because of a weird
// thing with `zip`.
inputs: 2,
// We don't need inputs
inputs: 0,

// We do need two outputs though. This is default, but let's be
// explicit anyways.
Expand Down Expand Up @@ -71,28 +70,30 @@ impl Plugin for Whisper {
}

fn process(&mut self, buffer: &mut AudioBuffer<f32>) {

// We only want to process *anything* if a note is
// being held. Else, we can return early and skip
// processing anything!
if self.notes == 0 { return }

// We loop through all buffers. We specified that we will have
// 2 inputs, and we'll have 2 outputs. `buffer.zip()` makes sure
// we loop through everything.
for (input_buffer, output_buffer) in buffer.zip() {

// Now, we loop through each individual sample in each buffer.
// We use an underscore `_` for the first value in our tuple, as
// it will contain input samples (which don't exist). The underscore
// lets us use our conventional `zip` method while still showing we
// don't want to use the variable.
for (_, output_sample) in input_buffer.iter().zip(output_buffer) {

// if our notes incrementer is greater than 0, that means a note is currently being pressed.
if self.notes > 0 {

// Finally, we change the value of each individual sample if a note is on
*output_sample = (random::<f32>() - 0.5f32) * 2f32;
}
// `buffer.split()` gives us a tuple containing the
// input and output buffers. We only care about the
// output, so we can ignore the input by using `_`.
let (_, output_buffer) = buffer.split();

// Now, we want to loop over our output channels. This
// includes our left and right channels (or more, if you
// are working with surround sound).
for output_channel in output_buffer.into_iter() {
// Let's iterate over every sample in our channel.
for output_sample in output_channel {
// For every sample, we want to add a random value from
// -1.0 to 1.0.
*output_sample = (random::<f32>() - 0.5f32) * 2f32;
}
}
}
}

plugin_main!(Whisper);
plugin_main!(Whisper);

0 comments on commit 810e9f4

Please sign in to comment.