Expand the tablesize with silence

Hello, i have a question:

Using the flooper2 opcode, i have this sample that i like.
But, sometimes i’d like, while flooper2 is looping, to add some silence (so: zeroes) at the end of the sample before it loops. That will add some space in the repetitions.
It would be great if this was possible at k rate, but first i was investigating at i rate.

I’ve tried to get this working inside a UDO:

opcode samplesilence,i,S

Sfile xin
itable chnget Sfile
ilen tableng itable
ilen *= 20
itable ftgen 0, 0, 0, 1, Sfile, 0, 0, 0
chnset itable, Sfile
xout itable

but I get all clicks and stutters.
What could be a solution for this?

PS. probably the easiest wouls be to add a second of silence to all samples…?

ilen is not being used? But is the idea to set the table to be larger than the number of samples in the waveform? If you put this into a UDO and read from the table using any one of the table reading opcodes, it would be quite simple.

opcode PlayWithSilence, a, ik
    iTable, kSilence xin ;table number, silence in seconds..
    kCanPlay init 1
    iLen ftlen iTable
    kIndex init 0
    setksmps 1

    if kCanPlay == 1 then
        aSig tab kIndex, iTable
        kIndex = (kIndex < iLen ? kIndex+1 : 0) 
        aSig = 0

    if(kIndex == iLen-1) then
        kCanPlay = sr*kSilence 
        kIndex = 0

    kCanPlay = (kCanPlay > 1 ? kCanPlay-1 : 1)
    xout aSig

Thanks, Rory, your solution is not exactly what i need, but it helps me thinking.
What i need is an ftable number or name for flooper2 to read. And sometimes i want this ftable to be bigger and then filled with zeroes.

I’d like to ponder on this some more, because the output now is aSig and not an itable. For sure the same technique can be applied, but this area is definitely not my forte…if i can’t wrap my head around it in a few days, i’d like to ask you once to the rescue…

This is a diy solution, I just added some zeros after the file length. You can adjust the silence length at your pleasure by changing isilence variable.

instr Tbl
	Sound = "pm_test.wav" //name of your file here
	ifileLen_smpls = filelen(Sound)*sr
	isilence = sr*1.5 //1.5 secs of silence
	itabLen = ifileLen_smpls+isilence
	itbl ftgen 0,0,itabLen,1,Sound,0,0,0
;adding silence
ksmpl = ifileLen_smpls+1
while ksmpl<itabLen do
	tablew 0,ksmpl,itbl
	ksmpl += 1

aIdx = phasor(1/p3)
aSig = table3:a(aIdx,itbl,1)

	outs aSig, aSig