This GitLab instance reached the end of its service life. It won't be possible to create new users or projects.

Please read the deprecation notice for more information concerning the deprecation timeline

Visit migration.git.tu-berlin.de to import your old projects to the new GitLab platform 📥

Commit bc1cf69a by Henrik von Coler

Added grain_player.dsp!

parent 66222a26
// grain_player.dsp
//
// Play a wave file in grains.
//
// - four grains
// - glitches when changing grain position
//
// Henrik von Coler
// 2020-05-28
import("stdfaust.lib");
// read a set of wav files
s = soundfile("label[url:{'../WAV/chips.wav'; '../WAV/my_model.wav'; '../WAV/sine.wav'}]", 1);
// a slider for selecting a sound file:
file_idx = hslider("file_idx",0,0,2,1);
// a slider for controlling the playback speed of the grains:
speed = hslider("speed",1,-10,10,0.01);
// start point for grain playback
start = hslider("start",0,0,1,0.01);
// a slider for the grain length:
length = hslider("length",1000,1000,40000,1): si.smoo;
// control the sample density (or the clock speed)
density = hslider("density", 0.1,0.01,20,0.01);
// the ramp is used for scrolling through the indices
ramp(f, t) = delta : (+ : select2(t,_,delta<0) : max(0)) ~ _ : raz
with {
// keep below 1:
raz(x) = select2 (x > 1, x, 0);
delta = sh(f,t)/ma.SR;
// sample and hold
sh(x,t) = ba.sAndH(t,x);
};
// 4 impulse trains with 1/4 period phase shifts
quad_clock(d) = os.lf_imptrain(d) <: _ , ( _ : @(0.25*(1/d) * ma.SR)) , ( _ : @(0.5*(1/d) * ma.SR)), ( _ : @(0.75*(1/d) * ma.SR)) ;
// function for a single grain
grain(s, part, start, l,tt) = (part, pos) : outs(s) : _* win_gain
with {
// ramp from 0 to 1
r = ramp(speed,tt);
// the playback position derived from the ramp
pos = r*l + (start*length(s));
// a simple sine window
win_gain = sin(r*3.14159);
// get recent file's properties
length(s) = part,0 : s : _,si.block(outputs(s)-1);
srate(s) = part,0 : s : !,_,si.block(outputs(s)-2);
// play sample
outs(s) = s : si.block(2), si.bus(outputs(s)-2);
};
// four parallel grain players triggered by the quad-clock
process = quad_clock(density) : par(i,4,grain(s, file_idx, start, length)) :> _,_;// :> _ <: _,_;
......@@ -31,8 +31,8 @@ loop(s, idx) = (idx, reader(s)) : outs(s)
length(s) = idx,0 : s : _,si.block(outputs(s)-1);
srate(s) = idx,0 : s : !,_,si.block(outputs(s)-2);
// the playback position (a recursive counter)
reader(s) = (speed * float(srate(s)))/ma.SR : (+,length(s):fmod)~ _ : wrap(length(s)) : int;
// the playback position (a recursive counter)
reader(s) = (speed * float(srate(s)))/ma.SR : (+,length(s):fmod)~ _ : wrap(length(s)) : int;
// read from sample
outs(s) = s : si.block(2), si.bus(outputs(s)-2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment