Problem with recorded buffer[:rec1, 8] when changing bpm

Hi
Maybe this is a bug?
After recording a buffer the following live_loop is playing. When I change bpm the buffer won’t play.
I fixed this with a simple workaround:

use_bpm 100
live_loop :clock do
  sample :bd_haus, amp: 1
  sleep 1
end
define :live_sample do |name, duration|
  sync :clock
  4.times do
    sample :perc_snap
    sleep 1
  end
  with_fx :record, buffer: buffer[name, duration] do
    live_audio :input, amp: 2, input: 1
    sleep duration
  end
  live_audio :input, :stop
end
live_sample :rec1, 8
recording1 = "~/.sonic-pi/store/default/cached_samples/rec6.wav"
live_loop :audio1, sync: :clock do
  sample recording1, amp: 1,
    slice: tick,
    num_slices: 32,
    rpitch: (knit 0, 16, -2, 16).tick(:audio1)
  sleep 0.5
end

Yes I’ve noticed this too. I think it is because when you change the bpm the time allocation for the buffer necessarily changes too, eg [:buf,8] at bpm 60 needs to become [:buf,4] effectively in terms of time as opposed to beats at bpm 120, so it allocates a fresh “space” for the buffer, essentially wiping it, whereas a recorded sample wav file can be played faster or slower, but is not altered in the process.

Thank you Robin! So this is gonna be the solution :wink:

recordedSample = “~/.sonic-pi/store/default/cached_samples/#{bufferName}.wav”

Yes that should work, It may be I am talking poppycock and it is a bug, but @samaaron will no doubt let us know.