-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTGrains_Example.scd
executable file
·117 lines (86 loc) · 2.8 KB
/
TGrains_Example.scd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//////////////////////
// GRANULAR SYNTHESIS
//////////////////////
// **************************
// FIRST STEP
//
// Copy the sound file of a song into /Music/SuperCollider/.
// Important: it has to be a mono wave file.
// If you have a stereo file, use Audacity to convert it to mono.
// **************************
// SECOND STEP
//
// Load the sound file into a buffer in memory:
(
Buffer.freeAll;
~mybuffer = Buffer.read(
server: s,
path: "~/Music/SuperCollider/wheels-mono.wav".standardizePath,
bufnum: 55); // just an arbitrary number I chose for this buffer
)
// You can retrieve some info from the buffer just to double check:
~mybuffer.numChannels; // how many channels are stored in the buffer
~mybuffer.numFrames/44100; // duration of buffer in seconds (= duration of sound file)
~mybuffer.bufnum; // buffer number
// You can also simply play back the sound that was loaded into the buffer:
{PlayBuf.ar(1, 55)}.play;
// **************************
// THIRD STEP
//
// Granulate it!
(
{
var buffer = ~mybuffer.bufnum;
var bufdur = BufDur.kr(buffer);
TGrains.ar(
numChannels: 2,
trigger: Impulse.ar(1),
bufnum: buffer,
rate: 1,
centerPos: 3,
dur: 0.5,
amp: 1)
}.play;
)
// Play around with the various grain parameters.
/*
Explanation of the important parameters:
TRIGGER is how many grains to play per second;
BUFNUM is what buffer to granulate;
RATE is transposition factor ("playback rate"): 1 is normal, 2 is octave above, 0.5 is octave below, etc.
CENTERPOS stands for "center position". It is the time location in the sound to pick a grain from.
DUR is duration of a grain.
AMP is amplitude of a grain.
Instead of having fixed numbers for these parameters, you can try using other functions, like random number generators or mouse control. For example:
MouseX.kr(0, bufdur) // control centerPos with the horizontal movement of mouse
LFNoise0.kr(1).range(0, bufdur) // control centerPos randomly
Impulse.ar(MouseY.kr(0.1, 0.5)) // control number of grains per second with mouse
etc...
*/
/////////////////////////////////////
// The structure below will let you change the values and re-evaluate in real time, without having to stop the sounds and start again. It will cross fade between each evaluation.
Ndef(\a).play; // start;
Ndef(\a).fadeTime = 1; // fadeTime (crossfade between changes)
// Evaluate the grains,
// Change them as you like,
// Evaluate again,
// etc
(
Ndef(\a,
{
var buffer = ~mybuffer.bufnum;
var bufdur = BufDur.kr(buffer);
Mix(TGrains.ar(
numChannels: 2,
trigger: Impulse.ar(MouseX.kr(1/4,10)), // change these numbers
bufnum: buffer,
rate: MouseX.kr(1,2), // change these numbers
centerPos: 3, // LFNoise0.kr(1).range(0,5),
dur: MouseY.kr(0.5,5),
amp: 0.5))
})
)
// Try any of these:
// LFNoise0.kr(a).range(b, c),
// MouseX.kr(a, b),
// MouseY.kr(a, b),