RustAudio / cpal

Cross-platform audio I/O library in pure Rust
Apache License 2.0
2.55k stars 344 forks source link

`cpal` blocking window rendering of `ggez` #781

Open arminveres opened 1 year ago

arminveres commented 1 year ago

I am currently working on an algorithm visualization tool, asking to this for a university project, hence why the repo is private at the moment. My goal is to output a tone between a certain range when sorting a bar.

I integrated the bleep example into my logic and while it works for very low frame rates, say 1-5 fps, it blocks the drawing of the window otherwise. I am assuming this is caused by std::thread::sleep.

Is there an other non blocking way to output a tone, as if I remove the sleep duration, no tone is output at all. i am calling run mutliple times in each frame.

If necessary, I can make the repository public.

If relevant: OS: Fedora Workstation 38

dheijl commented 1 year ago

Did you try running the tone generating code in another thread than the gui code?

arminveres commented 1 year ago

I haven't managed to put it into another thread yet, although I would prefer to keep it single threaded for the moment, if possible. EDIT: I.e., I would like for it to be synchronous, whereas with separate threads I am sure that it would not be. I made an implementation with message passing, which works, but it's completely asynchronous. I'd really appreciate, if someone could point me in the right direction.