tidalcycles / Dirt

Experimental sample playback
GNU General Public License v3.0
85 stars 24 forks source link

Asynchronous sample loading #25

Closed munshkr closed 9 years ago

munshkr commented 9 years ago

This is an improved version of PR #21 which solve two issues the original implementaion had:

  1. When a sample needed to be loaded, their playback was delayed until the second time they were triggered. Now after loading a sample, the thread triggers it again as soon as possible by calling audio_play again with its original play arguments (called late trigger).
  2. A thread was created (and destroyed) for each new sample file. Now there is a fixed-size thread pool and a queue of file-reading jobs, avoiding the overhead of thread management.

Late triggering is enabled by default, because it usually doesn't take too much time to load samples, but just in case, it can be disabled with the command line option --no-late-trigger. The thread pool size can also be defined with --workers or -w. By default it is 4.

Also, to make it easier to pass around the audio_play parameters (and avoid a lot of duplicated code) for late triggering, I extracted all of them into a struct called play_args_t.

yaxu commented 9 years ago

Thanks!