Can I grab sample audio in Sonic Pi and use it as OSC value?

Can I grab sample audio in Sonic Pi and use it as OSC value?

How I use it

Question

Sonic Pi code

# Question https://youtu.be/kfhpl9ww6ek
# "Can I grab sample audio in Sonic Pi and use it as OSC value"

# How it's used here https://youtu.be/hnKEiXwUTxI


#From https://in-thread.sonic-pi.net/t/how-to-play-several-partterns-in-sequence/866/6

use_osc "localhost", 5510

path ="C:/Users/1234/Documents/Ableton/User Library/Samples/Processed/Crop/4-Audio 2 [2019-03-14 234242].wav"

r1 = (ring 2, 3,7,nil, 2,3)     #ændre her
r2 = (ring 2, 4,nil,5,1)        #ændre her

#use_sample_defaults beat_stretch: 2, num_slices: 8,   cutoff: 100,release: 0.25


live_loop :loop1 do
  my_start= (knit 0.2,32, 0.5,32, 0.8,32).tick(:asd) #between 0-1  nice 0.2, 0.5, 0.8   #start value
  my_amp = 4
  
  use_sample_defaults beat_stretch: 2, num_slices: 8, cutoff: 100,release: 0.25
  use_bpm 30
  r1.each do |x|
    #sample  :loop_amen, slice: x, pan: -1       #min tilføjelse
    sample path, slice: x, start: my_start, amp: my_amp     #original
    osc "/vars/spA", (range 0,10,1).tick
    #osc "/vars/spA", r1.look  #fail
    sleep 0.25
  end
  r2.each do |x|
    #sample  :loop_amen, slice: x, pan: 1        #min tilføjelse
    sample path, slice: x, start: my_start, amp: my_amp     #original
    osc "/vars/spB", (range 0,10,1).tick
    #osc "/vars/spB", r2.look
    sleep 0.25
  end
end

Atom/Improviz code

paintOver()
background(0)
t=time/2
scale(0.7) //0.125, 0.25, 0.5, 1

oscA = ext(:spA, 0)
oscB = ext(:spB, 0)
rotate(0,0,t)

move(0,oscA/4,0)
texture(:w13) #inner
rectangle(0.008*oscA,oscA/4,0.01)

move(0,oscB/4,0)
texture(:w17) #outer
rectangle(0.008*oscB,oscB/5,0.01)

AFAIK, there is no simple, standard ‘Sonic Pi’ way to access (other than directly playing back) the data of an audio stream or sample. It would likely require dipping into some custom Ruby code to do so, or communicating with an external program to do it.

1 Like

Also, similar ideas to this are indeed on our wishlist :slightly_smiling_face: