Saving from :sound_in to samples

I would like to experiment with sonic pi for “live looping” (the other kind of live loop), that is recording audio input into samples and playing them back.

I believe the live looping tools are usually pretty fancy in allowing some sequencing (and effects of course) on recorded clips and it’s a pretty cool way of starting making fun sounds without requiring a lot of resources.

WDYT?

A couple examples worth looking at:

The second example does not do live audio looping, but is good to learn from and could be adapted to handle live audio.

1 Like

Very cool, thanks for the references! They definitely helped with figuring out how to use record and buffer objects together! The language reference could use an example or two, I think :slight_smile:

Based on the examples, I was trying something like this:

if not defined?($takes) then
  $takes = {}
end

# Record or play a buffer from sound input
# Params:
# - n: name of the `buffer` to use
# - l: length (in beats) of the `buffer` to use
# - t: take number -> re-recorded if greater than the last recorded take
def brp(n, l, t)
  k = [n, l]
  b = buffer n, l
  if t == 0 then
    # Just audition, don't play the last take, don't record
    synth :sound_in, sustain: l
    sleep l
  elsif ($takes[k] or 0) >= t then
    # Play the last recorded take
    sample b
    sleep l
  else
    # Record another take (while playing it back)
    $takes[k] = t
    with_fx :record, buffer: b do
      synth :sound_in, sustain: l
      sleep l
    end
  end
end

live_loop :baseline do
  sync :tock
  with_fx :octaver do
    brp :baseline, 4, 4
  end
end

live_loop :melody do
  sync :tock
  brp :melody, 8, 4
end

I didn’t really have time to play with it much (it’s late already), but this interface feels promising to me. The idea being that the brp can be chucked in anywhere sample or synth could and it keeps on repeating the last take until you increment the take number for one of them to re-record it.

1 Like