Cross-fade two samples

My first little snippet, wanted to create a cross-fade effect to be used in a Pubquiz (using two songs as separate samples, cross-fade in between them and people need to guess the second song ;)).

Hope you guys like it and can do something with it. If not, that’s also ok. Feedback is welcome!


sample1= :ambi_lunar_land
sample2= :ambi_dark_woosh


#Reference duration is the smallest duration of the two samples, to make sure
#the samples end at the same time, so we have a correct cross-fade
if duration_sample1 > duration_sample2
  reference_duration = duration_sample2

#Lets alter the speed by a factor
loop do
  #Cross-fade happens here, pretty self-explanatory I would say
  sample sample1,beat_stretch: reference_duration, release: reference_duration
  sample sample2,beat_stretch: reference_duration, attack: reference_duration
  sleep reference_duration

Thanks for this - nice use of the built-in samples.

One thing to look at next (if you don’t mind a bit of a tip) is to check out live_loop. It’s actually pretty rare to find loop in typical Sonic Pi code these days as live_loop is actually a lot more useful (and fun!).

Have fun on your live coding journey!