By the way, with it.frwtable, the read index doesn't need to be an int. Ciao, Dr Dario Sanfilippo http://dariosanfilippo.com
On Thu, 16 Dec 2021 at 00:44, Dario Sanfilippo <sanfilippo.da...@gmail.com> wrote: > Hi, Daniele. > > I would go with something like this: > > import("stdfaust.lib"); > speed = hslider("Speed", 1, .25, 4.0, .001); > size = 48000; > rec = button("Record"); > play = button("Play"); > wPtr = ba.if(rec, (+(rec) : %(size)) ~ _, size + 1); > rPtr = ba.if(play, (+(t * speed) : min(size)) ~ *(t), size) > with { > t = play; > }; > process(x) = it.frwtable(5, size + 2, .0, int(wPtr), x, int(rPtr)); > > We use a buffer of size+2 samples so that position size can be used for > the reading pointer when it is off to output 0, and position size+1 can be > used to always write in a position that is never used when recording is > off, not to overwrite what we already have in the buffer. A new recording > starts from the last recording position, whereas a new playback shot always > starts from the beginning. > > I'd say that it is not necessary to exit the recursion for the reading > pointer as the function will always output some value, so clipping it to a > safe ceil seemed reasonable; besides, if the clipper is inside the > recursion, there is no fear for the function to overflow. > > The way that I make the read pointer start from zero is to reset both the > input and the state. > > I hope that it helps. > > Dr Dario Sanfilippo > http://dariosanfilippo.com > > > On Wed, 15 Dec 2021 at 17:40, daniele.pagli...@gmail.com < > daniele.pagli...@gmail.com> wrote: > >> Hello all, >> >> I'm stuck in the task to create a "one shot sampler", mainly because >> functional programming is sometime "magic" to me and I have very little >> knowledge of it... :-( >> >> Anyway, here is the code that I wrote so far: >> >> ----------------------------------------- >> >> import("stdfaust.lib"); >> >> map(x, in_min, in_max, out_min, out_max) = (x - in_min) * (out_max - >> out_min) / (in_max - in_min) + out_min; >> >> // size of the table >> sampleRate = 48000; >> maxTime = 1; >> maxSamples = sampleRate * maxTime; >> >> // PARAMETERS >> num = 1; >> readSpeed = map(hslider("[0]pitch_%num[style:knob]", 64, 0, 127, 1) : >> si.smoo, 0, 127, 0, 3); >> loopLength = map(hslider("[1]length_%num[style:knob]", 127, 0, 127, 1) : >> si.smoo, 0, 127, 0, 1); >> volume = map(hslider("[2]volume_%num[style:knob]", 127, 0, 127, 1) : >> si.smoo, 0, 127, 0, 1); >> btnRecording = button("[4]rec_%num"); >> btnPlay = button("[5]gate_%num"); >> >> sample(playTrigger, recordTrigger, readSpeed, loopLength) = out >> with { >> play = playTrigger; >> record = recordTrigger; >> >> readIndex = 0, ((+(1 * readSpeed) : %(maxSamples * loopLength)) ~_ : >> int) : ba.selectn(2, play) : hbargraph("read_index", 0, maxSamples); >> recIndex = (+(1) : %(maxSamples)) ~ *(record) : int : >> hbargraph("write_index", 0, maxSamples); >> out = rwtable(maxSamples,0.0,recIndex,_,readIndex); >> }; >> >> process = _ : sample(btnPlay, btnRecording, readSpeed, loopLength) * >> volume <: _,_ ; >> >> -------------------------- >> >> The problems I cannot figure out a solution are: >> 1. I cannot restart from 0 the readIndex every time it receives a >> playtrigger >> 2. I cannot "exit" the recursion when the readIndex reaches maxSamples * >> loopLength >> 3. also I need the same for recording, but if I understand the syntax >> for playing I can solve it by myself >> >> Any help will be very appreciated. >> >> Thanks a lot! >> >> Daniele >> >> >> >> >> >> >> _______________________________________________ >> Faudiostream-users mailing list >> Faudiostream-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/faudiostream-users >> >
_______________________________________________ Faudiostream-users mailing list Faudiostream-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/faudiostream-users