bastibe/PySoundCard

Playing a lot of short sounds in short periods of time

Opened this issue · 2 comments

This is not an issue actually, but more of a question.
I'm trying to develop a metronome app. Thus I need it to play a lot of short sounds (metronome division/beat clicks) with a short delay between them (say, in a tempo of 250 bpm, the delay between the closest division clicks should be 60 ms, not counting the length of click sound itself).
Here's the problem I'm having: if I open the stream and just write to it, I'm getting "Output underflowed" between each pair of clicks, which is understandable as they're just a few milliseconds long. If I close/reopen the stream after/before each write, I'm facing a performance impact, and the playback gets all glitchy. The only workaround I came with so far is to add just a perfect amount of silence to each click sound sample, but I don't like it as it's really a hack, as the needed amount depends on tempo and sample length, and I'm not sure it'll work perfectly. My understanding of how underlying things work is too thin to come up with something beautiful, unfortunately.
Is there a chance you could recommend something?

I would recommend, for a metronome, you'd better synthesise the sounds in a continuous callback.

I think playing a click and some silence is the way to go. This is the only way to ensure perfect-length silence.