cmake build system: visiblity support for clang
[supercollider.git] / Help / UGens / Filters / FreqShift.html
blob2b1f8496f8d18b93e2841cd20b825cf1202ff196
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="1038.29">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #902a19}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #091fb1}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #902a19; min-height: 12.0px}
19 span.s1 {color: #091fb1}
20 span.s2 {color: #000000}
21 span.s3 {color: #606060}
22 span.s4 {color: #902a19}
23 span.Apple-tab-span {white-space:pre}
24 </style>
25 </head>
26 <body>
27 <p class="p1"><b>FreqShift<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Frequency Shifter</b></p>
28 <p class="p1">add</p>
29 <p class="p2"><b>FreqShift.ar(input, shift, phase, mul, add)</b></p>
30 <p class="p3"><br></p>
31 <p class="p2">FreqShift implements single sideband amplitude modulation, also known as frequency shifting, but not to be confused with pitch shifting.<span class="Apple-converted-space">  </span>Frequency shifting moves all the components of a signal by a fixed amount but does not preserve the original harmonic relationships.</p>
32 <p class="p3"><br></p>
33 <p class="p2"><b>input</b> - audio input</p>
34 <p class="p2"><b>shift</b> - amount of shift in cycles per second</p>
35 <p class="p2"><b>phase </b>- phase of the frequency shift (0 - 2pi)<b><span class="Apple-converted-space"> </span></b></p>
36 <p class="p3"><br></p>
37 <p class="p3"><br></p>
38 <p class="p2"><b>Examples</b></p>
39 <p class="p3"><br></p>
40 <p class="p4">// shifting a 100Hz tone by 1 Hz rising to 500Hz</p>
41 <p class="p5">{<span class="s1">FreqShift</span>.ar(<span class="s1">SinOsc</span>.ar(100),<span class="s1">XLine</span>.kr(1,500,5),0,[0.5,0.5])}.play(s);</p>
42 <p class="p6"><br></p>
43 <p class="p4">// shifting a complex tone by 1 Hz rising to 500Hz</p>
44 <p class="p5">{<span class="s1">FreqShift</span>.ar(<span class="s1">Klang</span>.ar(`[[101,303,606,808]]),<span class="s1">XLine</span>.kr(1,500,10),0,[0.25,0.25])}.play(s);</p>
45 <p class="p6"><br></p>
46 <p class="p4">// modulating shift and phase</p>
47 <p class="p5">{<span class="s1">FreqShift</span>.ar(<span class="s1">SinOsc</span>.ar(10),<span class="s1">LFNoise2</span>.ar(0.3,1500),<span class="s1">SinOsc</span>.ar(500).range(0,2pi),[0.5,0.5])}.play(s);</p>
48 <p class="p6"><br></p>
49 <p class="p4">// the ubiquitous houston example</p>
50 <p class="p5">(</p>
51 <p class="p7"><span class="s2">b = </span><span class="s1">Buffer</span><span class="s2">.read(s,</span>"sounds/a11wlk01.wav"<span class="s2">);</span></p>
52 <p class="p5">{<span class="s1">FreqShift</span>.ar(<span class="s1">PlayBuf</span>.ar(1,b,<span class="s1">BufRateScale</span>.kr(b),loop:1),<span class="s1">LFNoise0</span>.kr(0.45,1000),0,[1,1])}.play(s);</p>
53 <p class="p5">)</p>
54 <p class="p6"><br></p>
55 <p class="p4">// shifting bandpassed noise</p>
56 <p class="p5">{<span class="s1">FreqShift</span>.ar(<span class="s1">BPF</span>.ar(<span class="s1">WhiteNoise</span>.ar(1),1000,0.001),<span class="s1">LFNoise0</span>.kr(5.5,1000),0,[32,32])}.play(s);</p>
57 <p class="p3"><br></p>
58 <p class="p3"><br></p>
59 <p class="p2"><b>More Examples </b>(send a SynthDef, run the routine then send a different SynthDef)</p>
60 <p class="p3"><br></p>
61 <p class="p4"><span class="s2">(</span>// simple detune &amp; pitchmod via FreqShift</p>
62 <p class="p5"><span class="s1">SynthDef</span>(<span class="s3">"frqShift1"</span>,{<span class="s1">arg</span> frq,detune=1.5;</p>
63 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">var</span> e1,left,right;<span class="Apple-tab-span"> </span></p>
64 <p class="p5"><span class="Apple-tab-span"> </span>e1 = <span class="s1">EnvGen</span>.ar(<span class="s1">Env</span>.new([0,1,0],[1,2.3]),1,doneAction:2);</p>
65 <p class="p5"><span class="Apple-tab-span"> </span>left = <span class="s1">SinOsc</span>.ar(frq,0,e1); <span class="s4">// original tone</span></p>
66 <p class="p5"><span class="Apple-tab-span"> </span>left = left + <span class="s1">FreqShift</span>.ar(left,frq*detune); <span class="s4">// shift and add back to original<span class="Apple-converted-space"> </span></span></p>
67 <p class="p5"><span class="Apple-tab-span"> </span>right = <span class="s1">FreqShift</span>.ar(left,<span class="s1">SinOsc</span>.kr(3.23,0,5));</p>
68 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(0, [left,right] * 0.25);</p>
69 <p class="p5">}).add;</p>
70 <p class="p5">)</p>
71 <p class="p3"><br></p>
72 <p class="p4"><span class="s2">(</span>// the routine</p>
73 <p class="p8"><span class="s2">r = </span>Routine<span class="s2">({</span></p>
74 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">var</span> table,pitch;</p>
75 <p class="p5"><span class="Apple-tab-span"> </span>table = [0,2,4,5,7,9,11,12];</p>
76 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">inf</span>.do{</p>
77 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>pitch = (48+(12*2.rand) + table.choose).midicps;</p>
78 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.sendMsg(<span class="s3">"s_new"</span>,<span class="s3">"frqShift1"</span>,-1,1,1,<span class="s3">"frq"</span>,pitch);</p>
79 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>3.wait;</p>
80 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>};</p>
81 <p class="p5"><span class="Apple-tab-span"> </span>};</p>
82 <p class="p5">).play;</p>
83 <p class="p5">)</p>
84 <p class="p6"><br></p>
85 <p class="p4"><span class="s2">(</span>// shift pulse wave in opposite directions</p>
86 <p class="p5"><span class="s1">SynthDef</span>(<span class="s3">"frqShift1"</span>,{<span class="s1">arg</span> frq,detune=0.15;</p>
87 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">var</span> e1,snd,left,right;<span class="Apple-tab-span"> </span></p>
88 <p class="p5"><span class="Apple-tab-span"> </span>e1 = <span class="s1">EnvGen</span>.ar(<span class="s1">Env</span>.new([0,1,0],[0.02,3.2]),1,doneAction:2);</p>
89 <p class="p5"><span class="Apple-tab-span"> </span>snd = <span class="s1">Pulse</span>.ar(frq,<span class="s1">SinOsc</span>.kr(2.3).range(0.2,0.8),e1); <span class="s4">// original tone</span></p>
90 <p class="p5"><span class="Apple-tab-span"> </span>left = <span class="s1">FreqShift</span>.ar(snd,<span class="s1">XLine</span>.kr(-0.1,-200,2)); <span class="s4">// shift and add back to original<span class="Apple-converted-space"> </span></span></p>
91 <p class="p5"><span class="Apple-tab-span"> </span>right = <span class="s1">FreqShift</span>.ar(snd,<span class="s1">XLine</span>.kr(0.1,200,2));</p>
92 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(0, [left,right] * 0.25);</p>
93 <p class="p5">}).add</p>
94 <p class="p5">)</p>
95 <p class="p6"><br></p>
96 <p class="p4"><span class="s2">(</span>// FreqShift &gt;&gt; feedback &gt;&gt;&gt; FreqShift</p>
97 <p class="p7"><span class="s1">SynthDef</span><span class="s2">(</span>"frqShift1"<span class="s2">,{</span><span class="s1">arg</span><span class="s2"> frq;</span></p>
98 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">var</span> e1,snd,snd2,in;</p>
99 <p class="p5"><span class="Apple-tab-span"> </span>in = <span class="s1">FreqShift</span>.ar(<span class="s1">InFeedback</span>.ar(0,1)*3.2,<span class="s1">XLine</span>.ar(0.01,frq*1.5,1)); <span class="s4">// shift the feedback</span></p>
100 <p class="p5"><span class="Apple-tab-span"> </span>e1 = <span class="s1">Env</span>.new([0,1,0],[0.02,2.98]);</p>
101 <p class="p5"><span class="Apple-tab-span"> </span>snd = <span class="s1">SinOsc</span>.ar(frq,0,<span class="s1">EnvGen</span>.ar(e1,1,doneAction:2));</p>
102 <p class="p5"><span class="Apple-tab-span"> </span>snd2 = <span class="s1">FreqShift</span>.ar(snd+in,<span class="s1">SinOsc</span>.ar(4.24,0.5,3),0,0.5); <span class="s4">// subtle modulating shift</span></p>
103 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">OffsetOut</span>.ar([0,1], <span class="s1">Limiter</span>.ar(snd2+snd * 0.5,1,0.005));</p>
104 <p class="p5">}).add;</p>
105 <p class="p5">)</p>
106 <p class="p6"><br></p>
107 <p class="p4"><span class="s2">r.stop; </span>// stop old routine</p>
108 <p class="p6"><br></p>
109 <p class="p4"><span class="s2">(</span>// ssllooww columbia tuned shift detune</p>
110 <p class="p9"><br></p>
111 <p class="p7"><span class="s1">b = Buffer</span><span class="s2">.read(s,</span>"sounds/a11wlk01.wav"<span class="s2">);</span></p>
112 <p class="p6"><br></p>
113 <p class="p5"><span class="s1">SynthDef</span>(<span class="s3">"frqShift1"</span>,{<span class="s1">arg</span> frq, bufnum;</p>
114 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">var</span> e1,snd,left,right;</p>
115 <p class="p5"><span class="Apple-tab-span"> </span>e1 = <span class="s1">Env</span>.new([0,1,0],[3,1],-4);</p>
116 <p class="p5"><span class="Apple-tab-span"> </span>snd = <span class="s1">PlayBuf</span>.ar(1, bufnum, <span class="s1">BufRateScale</span>.kr(bufnum) * 0.01, loop:1);</p>
117 <p class="p5"><span class="Apple-tab-span"> </span>left = <span class="s1">FreqShift</span>.ar(snd,frq*2,0,<span class="s1">EnvGen</span>.ar(e1,1,doneAction:2)); <span class="s4">// subtle shift of the output</span></p>
118 <p class="p5"><span class="Apple-tab-span"> </span>right = <span class="s1">FreqShift</span>.ar(snd,frq*3,0,<span class="s1">EnvGen</span>.ar(e1,1,doneAction:2));</p>
119 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(0, [left,right] * 3);</p>
120 <p class="p5">}).add;</p>
121 <p class="p4"><span class="s2">(</span>// the routine</p>
122 <p class="p8"><span class="s2">r = </span>Routine<span class="s2">({</span></p>
123 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">var</span> table,pitch;</p>
124 <p class="p5"><span class="Apple-tab-span"> </span>table = [0,2,4,5,7,9,11,12];</p>
125 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">inf</span>.do{</p>
126 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>pitch = (48+(12*2.rand) + table.choose).midicps;</p>
127 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.sendMsg(<span class="s3">"s_new"</span>,<span class="s3">"frqShift1"</span>,-1,1,1, <span class="s3">"frq"</span>, pitch, <span class="s3">"bufnum"</span>, b);</p>
128 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>3.wait;</p>
129 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>};</p>
130 <p class="p5"><span class="Apple-tab-span"> </span>};</p>
131 <p class="p5">).play;</p>
132 <p class="p5">)</p>
133 <p class="p6"><br></p>
134 <p class="p5">)</p>
135 </body>
136 </html>