Live_audio violin and Sonic Pi Frere Jaques


#1

Just added a pickup to my violin, so thought I’d try it out with live_audio.

program below

#Frere Jaques played by me, Robin Newman and Sonic Pi together
use_bpm 120
sleep 1 #time to get ready!
play 84,release: 0.04
sleep 1
3.times do
  play 72,release: 0.04
  sleep 1
end
4.times do
  b=[:v0,:v1,:v2,:v3].tick
  with_fx :record,buffer: [b,4] do
    with_fx :compressor,amp: 3 do
      live_audio :violin,input: 2
    end
  end
  sleep 4
  live_audio :violin,:stop
  sample buffer[b,4]
  sleep 4
end
4.times do
  p=[-0.9,-0.3,0.3,0.9].tick(:pp) #set pan position
  in_thread do
    4.times do
      b=[:v0,:v1,:v2,:v3].tick #choose buffer
      sample buffer[b,4],pan: p #each buffer played twice
      sleep 4
      sample buffer[b,4],pan: p
      sleep 4
    end
  end
  sleep 8
end

#2

Perfect for all the classroom/education people.

What a neat little 5-min example to show your classes.
Doesn’t even have to be a violin… a mic on a piano
or guitar pickup would work just as well.

Well played Sir, well played.

Eli…


#3

That’s great - my daughter did Frere Jaques at Code Club last week and then piped it out to our external synths:


#4

Hi Robin,

That is just so awesome. My daughter plays harp and sonic pi seems like a great way to get her into coding. Just for kicks I pasted your program into my laptop sonic pi and used the mic in to hum along instead of playing violin. The latency when recording is horrible and I couldn’t achieve the nice results you did. The live_audio goes straight to the speakers with a 200ms delay or more. I was wondering if you could detail your hardware setup or how you deal with latency and monitoring when developing with live_audio?

Thanks again for the video. It’s very motivating.

Regards

Brad


#5

I used an external Steinberg UR22 MkII interface fed into a MacBook Pro which was running Sonic Pi 3.
I also have a (more expensive) Apollo Twin interface from Universal Audio which gives low latency.
This gave a low enough latency to work OK. as my video shows.


#6

Hi Robin,

Thankyou for your feedback.

830 euro for the Apollo Twin
129 euro for the Steinberg UR22 MK2

Was the Steinberg was also “OK” for latency or do you mean you had to use the Apollo to get the latency you required?

Regards

Brad


#7

Hi @bradgonesurfing,

I think the Steinberg should be okay. I have a Focusrite Scarlett (also 129 EUR and as far as I know comparable to the Steinberg) and have a latency (under Linux) of 10 to 15 milliseconds.


#8

Hi Brad, which operating system are you using?


#9

Laptop with headset line in and speaker. Lenovo Miix 510 running windows 10. It was just my first attempt and I was wondering how good the latency can get if I get the correct setup.


#10

The default audio driver that Sonic Pi uses with windows has high compatibility (it works with most setups) but has shocking latency as you’ve observed.

The solution is to use an alternative driver, but that’s not currently possible without hacking the source and is something I’ve not yet polished up enough. It’s likely something like that when I finish will become a Studio-only feature (i.e. be a paid feature).


#11

I guess you mean the ASIO4ALL driver? I installed it and saw that the scsynth program recognised it but I was too busy with other things today to dig deeper. I assume it’s just a matter of telling scythth to use that driver when it is started from SPi. There seems to be other posts on here suggesting that this works though I haven’t found a complete step by step guide yet.


#12

I added a

-H “ASIO4ALL v2”

To scsynthexternal.rb:356

and sonic started with the ASIO4ALL driver. Audio out works but not audio in yet. I’ll post back as I figure out more.


#13

I think the Steinberg worked ok too. Just did a quick test again with a mike input singing along to notes being played by so and it was ok.
I seem to remember having some glitch problems with the steinberg for long recordings though. There are others that would do as well too.


#14

Precisely - although at this point you’re in the dark arts of SuperCollider vs Windows. Please do share if you get things working on your machine!


#15

ASIO4ALL worked properly once I started using it properly. It’s a little bit fiddly to use and I got some help from the maintainer but it’s not rocket science. I now have very very low latency audio in from the microphone array on the laptop.

It fairly simple to setup.

(1) Follow the instructions from ASIO4ALL. ie disable windows sounds and the inputs for your microphone and outputs for your speaker
(2) Add the “-H”, “ASIO4ALL” to scssynthexternal.rb line 356
(3) Start Sonic PI
(4) BEFORE pressing play configure the ASIO4ALL gui which is accessible from windows status icons to set your desired inputs and outputs. If you press play then you are stuck with the configuration that was there before you pressed play untill you close Sonic and restart. Not sure if this is a supercollider or ASIO4ALL or sonic bug.
(5) Go build a live looping beat box tool.

Obviously the microphone array input is still terrible for sound quality even though the latency is good. I’ll try a relatively cheap line in or USB mic to improve the quality to start with and see how it goes.