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

Reply via email to