Output sound_out to files

Once again, forgive my newbie questions here and if they exist already, I haven’t been able to find much but assume it’s been asked before:

Is there a way to save mono or stereo individual stems of audio out directly to files for later mixing? Obviously you can send out to one of the 16 channels and then record in a DAW, but think that the resources and setup that this takes could be mitigated by allowing path parameters to directly save at least some amount to the file system directly. Then you could run and record using only Sonic Pi, and load those stems into a DAW later for mixing.

I feel like I may be missing something. Maybe some of the Jack tools on Linux can do this (I run it both on Mac and Linux) but thought I’d ask for help in this regard.

Is your question is how to send to a special ouput ?

i come to a question : how to send a sample to the out_5 into sonic pi ? is is possible ?

Hi Isaac,

in addition to @nlb 's answer, here is an old post of mine which might give additional insight how to route output … but I am not aware of any option to use SP’s record feature (which I understand you would like to use) in a way that you route specific channels to the recording output.

But I might just not be up to date.

ah nice :slight_smile: Thanks @Martin

the tip is to use the fx, :sound_out

live_loop :to_out5 do
  
  with_fx :sound_out, output: 5 do
    
    sample :drum_bass_soft
    sleep 0.25
  end
end

Thanks @nlb & @Martin!

That part I know. I’ve done this on my Mac, but not on Linux yet. I think @Martin understands what I was wondering about. Instead of routing audio to an output (that ends up in a DAW or another way), is there a way to just write out audio files directly to the drive? Seems like not, other than things I may not know about Jack on Linux for direct channel to file output.

I’m just trying to get around setting up both Sonic Pi and my DAW(s) to record any given sound_out or sound_out_stereo to tracks. I wrote post about using OSC with Ableton Live on the Mac to do this (plus other stuff). Works sort of fine, but would be way easier when just trying to stem out audio of various instruments to have the ability to send sound_out_stereo to a file instead of a channel if possible.

I’m also aware that what I’m doing isn’t technically part of ‘Live Coding’. Well it sort of is. If I make a performance in Sonic Pi, maybe the best thing ever :-), but want to mix it later, It would be way easier to have some way to set up some live_loop or with_fx file saves where I choose rather than one flattened record file.

Did a quick googling: Maybe this is what you can use…

Perfect! Thanks @Martin!

I’m still putting a feature request in for direct sound_out to file - just in case it is someday feasible. Would make setup for this very minimal if it were possible. Until then though - that solution may be exactly what I’m looking for (sorry to make you google things for me).

2 Likes

and using fx record ?

Hey @Hypostatic,

Here is a (highly contrived) example of recording different sounds to separate files:

in_thread do
  with_fx :record, buffer: :recordtest1 do
    8.times do
      play 60
      sleep 0.5
    end
  end
end

with_fx :record, buffer: :recordtest2 do
  8.times do
    play 72
    sleep 0.5
  end
end

This results in two separate wav files, recordtest1.wav and recordtest2.wav, that end up in an area for cached samples in your .sonic-pi folder. (On my windows computer, this ends up at: C:\Users\Ethan\.sonic-pi\store\default\cached_samples.

2 Likes

Hi @nlb and @ethancrawford,

I did not remember this option although I have used this already myself; I hope this is not a matter of age-related forgetfulness :wink: .

Thanks Ethan for the example!

1 Like

Okay, I have seen :record - but what I didn’t know is you could get to the files. I think this would work for me! I’ll give it a shot. Thanks all!

2 Likes

@ethancrawford - So this appears to work with with non-restarts, which makes sense. I guess what might be very cool is to have this as another FX (effect), or a file parameter of sound_out_stereo, some sort of file path. If you did a live performance say, and didn’t want to set up something else to record each sound_out, maybe you are restarting all the time to trigger and stop sounds, you wouldn’t want just the last re-start cache, you’d want the entire performance, but to stemmed output.

With every Meta-R the cache files seem to go back to 0 bytes.

There’s probably a (non-Sonic Pi idiomatic) way of achieving what you want - you could give the name of the buffer to record to as a string which has the current time interpolated into it. (Formatted in such a way to avoid any file name issues if that might happen). That might get you part way to what you want.
Can provide an example a little later if desired but don’t have time just yet… Something like this:

in_thread do
  with_fx :record, buffer: "recordtest-#{Time.now.strftime("%F-%H%M%S")}" do
    8.times do
      play 60
      sleep 0.5
    end
  end
end

with_fx :record, buffer: "recordtest2-#{Time.now.strftime("%F-%H%M%S")}" do
  8.times do
    play 72
    sleep 0.5
  end
end

Which produced, in a test on my machine:

recordtest-2020-06-10-082418.wav
recordtest2-2020-06-10-082418.wav

and then, on a second run:

recordtest-2020-06-10-082546.wav
recordtest2-2020-06-10-082546.wav

Not exactly pretty, (though you could probably extract the interpolation of the buffer name into a simple function to save typing) but it might do what you want for now? :man_shrugging:
(I agree it would be nicer to handle this in a simpler way in a potential feature improvement at some point :slight_smile: )

1 Like

Thanks @ethancrawford - yeah, this should work! Of course, like you’ve said, it’d be a nice feature, sort of the opposite of loading external samples. And of course I can just output to a daw, it isn’t so hard - but it does take some resources to have both SP and the DAW multi-track recording (unless I do one at a time - but again, not actually capturing stemmed live performance). So, it would be pretty nifty to only work in Sonic Pi, but have a way to output multiple files. What you showed above would sort of work, though I think I’d have a lot of files if I keep pressing Meta-R. I’ll see what happens. Thanks again!

1 Like