Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current best practice for the type of audio data in callback function? #185

Open
Dicklessgreat opened this issue Mar 31, 2024 · 0 comments

Comments

@Dicklessgreat
Copy link
Contributor

Hi! So nice to post here first time.
I want to ask current best practice for the signature of an audio callback function with dasp.

I'm currently working on embedded system with ADDA connected with stm32H7 via SAI.
Now I'm making a synthesizer and it doesn't know how much audio block length is, and how much channels are.
But my BSP crate provide me an audio callback like that.

fn bsp_audio_callback<const CHAN: usize, const LEN: usize>(block: [[f32: CHAN]; LEN]) {
    call_my_impl_func(block);
}

If I implement synthesizer's callback function as generics, should I implement like that?

impl<T: dasp_sample::FloatSample> Synth<T> {
    fn synth_block<U: dasp_frame::Frame>(&mut self, block: &mut [U]) 
    where
    <U as Frame>::Sample: dasp_sample::FromSample<T>,
    {
        let tick = ...;
        for frame in block {
            for mut chan in frame.channels_mut() {
                let v: T = self.oscillator.sin(tick);
                *chan = <U as bare_synth::dasp_frame::Frame>::Sample::from_sample(
                    v.to_sample(),
                );
            }
        }
    }
}

Or, should I use dasp_slice trait for the block?
Any comment, suggestion, example, or snippet much appreciated.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant