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

Improve scheduling accuracy #144

Closed
refi64 opened this issue Nov 8, 2015 · 5 comments
Closed

Improve scheduling accuracy #144

refi64 opened this issue Nov 8, 2015 · 5 comments

Comments

@refi64
Copy link

refi64 commented Nov 8, 2015

I noticed alda.sound.midi.play-note! uses Thread/sleep...

...which worries me...

As the link shows, Thread.sleep isn't guaranteed to be reliable. Has anyone tried Alda at faster tempos?

@daveyarwood
Copy link
Member

Timing has generally been pretty good for me, even at fast tempos. That being said, you have a good point about Thread.sleep not being reliable. Alda's timing/scheduling system could definitely be improved.

One thing to note is that we're currently using overtone/at-at for note-scheduling*, which uses a ScheduledThreadPoolExecutor to schedule events. This is probably a little better than just using Thread.sleep, but it looks like it still may not be the most solid way to schedule events. I think that what we want, ideally, is an event-scheduling system based on the system's audio clock -- real-time audio processing, in other words. That would be the only way to get truly accurate timing. After some googling, I haven't found any existing Clojure libraries that do real-time audio processing, but it's certainly possible with Java. JSyn in particular looks highly promising, and as a bonus, we could also use it to create waveform synthesis instruments (#100).

*though I just realized that we're only using at-at to schedule the start of notes, but then using plain ol' Thread.sleep to wait for the duration of the note before stopping it. We should fix that, if nothing else.

@daveyarwood daveyarwood changed the title Potential issues with playing notes at high tempos? Improve scheduling accuracy Nov 8, 2015
@ghoger
Copy link

ghoger commented Nov 11, 2015

@daveyarwood I'm glad to find this issue/discussion. I've experienced timing anomalies during playback, too. I dug into the code a bit and found the use of ScheduledThreadPoolExecutor and suspected that that is at least part of the problem. I agree that moving to a more real-time note scheduling mechanism is the way to go.

@refi64
Copy link
Author

refi64 commented Nov 11, 2015

Honestly, I think you should use a library compatible with MIDI to make exporting easier. To me, that's the primary thing keeping me from using Alda more: my use case depends heavily on MIDI exporting.

@daveyarwood
Copy link
Member

Using a MIDI library would help for exporting MIDI, but we still need a system in place for reliable scheduling of generic audio events (MIDI or otherwise). Once we have waveform synthesis instruments, etc., it will be possible to write scores that have both MIDI and non-MIDI instruments alongside each other.

BTW @kirbyfan64, I've been thinking about the MIDI export story a little bit, and I think probably what we'll do is make that an alternate mode of use for Alda -- i.e. rather than "playing" a score, you'll be able to "export" it to MIDI, which will give you a .mid file.

@daveyarwood
Copy link
Member

Alda 1.0.0-rc2 (out soon) will use JSyn to schedule events in realtime, which ought to be a lot more precise.

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

No branches or pull requests

3 participants