jonasrmichel / rudiments

A drum machine written in Rust
Apache License 2.0
148 stars 6 forks source link

Question: Curious why you chose to premix the sound files? #4

Open deckarep opened 3 years ago

deckarep commented 3 years ago

Looking through the code, I can see that you wrote some code to premix the files into a single "track". This is cool and it never occurred to me that this approach can work well (which it does clearly!).

I just have a general curiosity/architecture question for you?

Why did you choose to premix in the first place versus playing the individual samples in real time? If they're managed individually you could potentially build a UI/Command-line component where you can view the sequencer and turn on or off each instrument per note?

Really cool lib btw!

-deckarep

jonasrmichel commented 3 years ago

Thanks for the comment and feedback @deckarep!

This is a really great suggestion and warrants more investigation. The reason for premixing was primarily simplicity. However, now that I think about it, there's also the question of synchronization. If a beat's tracks are played independently, they need to be precisely aligned in time. I'm unsure how much control rodio -- which delegates to cpal for playback -- provides over playback timing.

Alternatively, if a user wanted to change a beat on the fly, the beat's source could be remixed in the background and played when ready.

Any interest in investigating? :smiley:

deckarep commented 3 years ago

@jonasrmichel - thanks for taking the time to respond. I’m actually trying to figure this out now in my own project. Basically the notion of how do I build a drum machine with precise timing.

Some of the frameworks I’ve used currently don’t cut it in terms of precision and so I’m having to find a more real-time language/framework to pull it off. Most recently I may have found a framework which would allow me to do it.

It’s also written in Rust and uses cpal under the hood but my solution requires a gui component as well.

I will say this: your solution of premixing the track sounds so incredibly tight compared to anything I’ve built so far!

jonasrmichel commented 3 years ago

Sounds really interesting and fun! Please share a link if you plan to open source it, I'd be interested in taking a look.