i’m trying to setup automatic looping of multiple samples loaded into the same buffer with the following code (using bundled samples in the example below):
local samples = {
first = {
path = _path.audio .. "/tehn/drumilk.wav",
duration = nil,
start = nil,
},
second = {
path = _path.audio .. "/tehn/drumilk.wav",
duration = nil,
start = nil,
},
}
local voices = {
second = 1,
first = 2,
}
local function load_samples()
local start = 0
for key, sample in pairs(samples) do
local channels, frames, samplerate = audio.file_info(sample.path)
softcut.buffer_read_mono(sample.path, 0, start, -1, 1, 1)
sample.duration = frames / samplerate
sample.start = start
print('loaded', key, 'at', start, 'duration', sample.duration)
start = start + util.round_up(sample.duration)
end
end
local function setup_voices()
for key in pairs(voices) do
local voice = voices[key]
local sample = samples[key]
softcut.enable(voice, 1)
softcut.buffer(voice, 1)
softcut.level(voice, 1)
softcut.play(voice, 1)
softcut.loop(voice, 1)
softcut.loop_start(voice, sample.start)
softcut.loop_end(voice, sample.start + sample.duration)
print('setting voice', key, 'loop', 'to', sample.start, sample.start + sample.duration)
softcut.position(voice, sample.start)
softcut.level_slew_time(voice, 0)
softcut.rate_slew_time(voice, 0)
softcut.level(voice, 0.25)
end
softcut.level(voices.first, 0)
end
local function phase(voice, phase)
if voice == voices.first then
-- print('phase', voice, phase)
end
end
function init()
load_samples()
setup_voices()
softcut.event_phase(phase)
softcut.phase_quant(voices.first, 1/10)
softcut.poll_start_phase()
end
function redraw()
screen.clear()
screen.update()
end
the following output is produced in maiden, which seems correct (with the exception that util.round_up rounds 4.8 up to 6 for some reason).
loaded first at 0 duration 4.8
loaded second at 6 duration 4.8
setting voice first loop to 0 4.8
setting voice second loop to 6 10.8
but i hear audible pause just before the sample is looped. am i doing something the wrong way here?
UPD: nvm, figured it out. I’ve been using 44.1kHz samples in my tests and after trying to resample them to 48kHz i got nice seamless playback. this doesn’t seem to be a documented point, though.