Debian Codegraph @

examples/effects/pitch-shift.ck

raw
1 //------------------------------------------------------------------------------
2 // name: pitshift.ck
3 // desc: basic demo of the PitShift (pitch shift) UGen
4 //
5 // The PitShift UGen uses delay lines to create a simple pitch shift effect. The
6 // input signal is copied, pitch-shifted, and mixed with the original signal.
7 // The amount of the pitch-shifted signal that is present can be set using .mix()
8 // The amount of pitch shifting for the modified signal can be set using .shift()
9 // When .shift() = 1, the modified signal has the same pitch as the original.
10 // .shift() can be positive or negative.
11 // The example here demonstrates a pitch shifting for two different kinds of signal
12 // The first one uses a sawtooth wave as input signal, sweeping the pitch shift
13 // amount between -2.5 and 2.5.
14 // The second loops a SndBuf (audio file) with random pitch shift amounts.
15 //
16 // author: Alex Han
17 // date: Spring 2023
18 //------------------------------------------------------------------------------
19
20 SawOsc s => PitShift ps => dac; // for example 1
21 SndBuf buf => PitShift ps2 => dac; // for example 2
22
23 s.gain(0);
24 s.freq(440);
25
26 buf.gain(0);
27 "special:dope" => buf.read;
28
29 ps.mix(.5);
30 ps2.mix(1);
31
32 // pitch-shifted sawtooth, sweeping shift amount between -2.5 and 2.5
33 fun void sawShift()
34 {
35 s.gain(.2);
36
37 while(true)
38 {
39 for(-250 => int i; i < 250; i++)
40 {
41 ps.shift(i*.01);
42 chout <= "current pitch shift amount: " <= ps.shift();
43 chout <= IO.newline();
44 50::ms => now;
45 }
46 }
47
48 }
49
50 // pitch shifted audio file playback ("dope!") random shift amount each time
51 fun void dopeShift()
52 {
53 1 => buf.gain;
54
55 while(true)
56 {
57 0 => buf.pos;
58 ps2.shift(Math.random2f(-5.0, 5.0));
59 chout <= "current pitch shift amount: " <= ps2.shift();
60 chout <= IO.newline();
61 buf.length() => now;
62 }
63
64 }
65
66 // uncomment either of these to try
67 spork ~ sawShift();
68 // spork ~ dopeShift();
69
70 // time loop
71 while(true)
72 {
73 1::second => now;
74 }