RustAudio/rodio

add a simple overdrive effect

setoelkahfi opened this issue · 2 comments

I want to implement a simple overdrive effect for a sink like this example? How do you think I should start?

I have copied the Amplify implementation but cannot make progress implementing the process_samples function from the example link. Something like this:

#[derive(Clone, Debug)]
pub struct Overdrive<I> {
    pub input: I,
    pub bypassing: bool,
    pub factor: f32,
}


impl<I> Iterator for Overdrive<I>
where
    I: Source,
    I::Item: Sample,
{
    type Item = I::Item;

    #[inline]
    fn next(&mut self) -> Option<I::Item> {
        self.input.next().map(|value|  {
            // I think I should modify the samples here but don't know how to get the array of samples.
            process_samples(value) 
        })
    }

    #[inline]
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.input.size_hint()
    }
}

Any pointers?

// I think I should modify the samples here but don't know how to get the array of samples.

You can not get an array of samples directly out of the underlying source but you can always collect a few samples from the underlying source and work on those.

you could add a Vec to you struct. Then when you construct the the Overdrive in Overdrive::new() or something similar fill the Vec with some samples from the underlying Source. Then in next put a new sample in the Vec and process the samples in the Vec.

I am closing this since it seems resolved? feel free to re-open if its not.