Experimenting with markov chain


a = 0
b = 10
c = 200
d = 3000
e = 40000
f = 500000

# Initialize current onset
current_onset = 0

# Transition matrix for Markov chain (4 onsets)
# Format: transition_matrix[current_onset] = array_of_next_onsets
transition_matrix = {
  a => (ring a, b, c, a, d, e, f, f, e, d),
  b => (ring b, a, c, e, f, e, e, a, b, c),
  c => (ring e, d, c, a, b, d, f, e, c, c),
  d => (ring a, a, b, c, c, d, e, f, a, d),
  e => (ring c, f, e, d, b, a, f, d, d, d),
  f => (ring a, a, b, c, c, d, e, f, a, d)
}

samps2 = "C:/Users/marce/Desktop/1/2.wav"

live_loop :random_sampler do
  
  (ring 24).tick(:t).times do
    # Use Markov chain to decide the next onset
    next_onset = choose(transition_matrix[current_onset])
    
    # Play and sleep
    sample samps2, onset: next_onset
    sleep sample_duration samps2, onset: next_onset
    
    # Update current onset for the next iteration
    current_onset = next_onset
  end
end

1 Like