MIDI & latency: use_real_time has no effect

Hi there,
when i try the basic MIDI-in example in the help-section (see below), there is a significant latency of about 0.5 seconds, it even makes no difference if there is a “use_real_time” call or not. Same behaviour also under Raspbian + Windows. Did i miss something?
Thanks in advance!
code_artist

live_loop :midi_piano do
  use_real_time
  note, velocity = sync "/path/to/my/keyboard/0/1/note_on"
  synth :piano, note: note, amp: velocity / 127.0
end 

Hi there, which specific version(s) and platform(s) are you seeing this latency?

Also, what is the exact code you’re using that’s not working for you?

Another thing to test - if you run the following code, do you also hear the same amount of latency from when you hit run to hearing the sound:

use_real_time
play 70, release: 0.1

Hi Sam,
thanks for your reply.

  • Windows 10 / 3.0.1 and 3.1
  • Raspbian (november 2017) / 3.0.1

one of them, tried different controllers both under windows and rapbian:

live_loop :midi_piano do
  use_real_time
  note, velocity = sync "/midi/usb_midi_keyboard_midi_1/1/1/note_on"
  synth :piano, note: note, amp: velocity / 127.0
end

[quote]if you run the following code, do you also hear the same amount of latency from when you hit run to hearing the sound:

Copy Code
use_real_time
play 70, release: 0.1

[/quote]
Uhm hard to tell, but roundabout: yes.

Unfortunately it sounds like you’re running against the inherent audio-driver latencies on Windows and Raspbian. This isn’t something Sonic Pi has any control over sadly.

To fix this, you need to either tune your audio driver settings, or select different audio drivers.

On Linux/Raspbian this is achieved by configuring Jack correctly. This depends on your sound card and specifics of your audio setup and is unfortunately potentially quite different on each setup, so it’s hard to offer generic advice.

On Windows this is typically achieved by never using the default drivers (these have huge latencies). You’ll have much better luck with either Direct X or ASIO drivers. Unfortunately, the audio driver selection mechanism on Windows isn’t something I’ve completely mastered. It seems that instead of having a nice global setting (as there is on macOS) each audio app has to manage its own settings and manually select which audio driver to use. This is something I’m yet to implement for Sonic Pi. It should be just the case of editing scsynthexternal.rb and adding the correct flags for scsynth, but this is currently left as an exercise for the reader until I have time to address it directly myself.

I should also add that on macOS there is no obvious latencies with the default audio drivers :slight_smile:

Hi Sam, many thanks for your detailed answer! I will let you know if i made any progress with that issue…

Sounds cool. I also have one MacBook which is running system 10.8 and Sonic Pi very well, but unfortunately Sonic Pi does not detect any Midi-Gear. I will describe this issue in another topic :smiley:

Please do - is this with the latest v3.1 Release Candidate or v3.0.1?

Looking into this, I’m afraid we’re going to have to drop support for at least 10.8, and probably higher.