scide: implement selectionLength for openDocument
[supercollider.git] / HelpSource / Classes / FreqShift.schelp
blob985d072df4dc9f544d2dfe4051a0488c972fcf18
1 class:: FreqShift
2 summary:: Frequency Shifter.
3 related:: Classes/Hilbert, Classes/HilbertFIR
4 categories::  UGens>Filters>Nonlinear, UGens>Filters>Pitch
7 Description::
9 FreqShift implements single sideband amplitude modulation, also known as
10 frequency shifting, but not to be confused with pitch shifting. Frequency
11 shifting moves all the components of a signal by a fixed amount but does
12 not preserve the original harmonic relationships.
15 classmethods::
17 method::ar
19 argument::in
20 The input signal.
22 argument::freq
23 Amount of shift in cycles per second.
25 argument::phase
26 Phase of the frequency shift (0..2pi).
28 argument::mul
30 argument::add
33 Examples::
35 code::
36 // shifting a 100Hz tone by 1 Hz rising to 500Hz
37 {FreqShift.ar(SinOsc.ar(100),XLine.kr(1,500,5),0,[0.1,0.1])}.play(s);
39 // shifting a complex tone by 1 Hz rising to 500Hz
40 {FreqShift.ar(Klang.ar(`[[101,303,606,808]]),XLine.kr(1,500,10),0,[0.1,0.1])}.play(s);
42 // modulating shift and phase
43 {FreqShift.ar(SinOsc.ar(10),LFNoise2.ar(0.3,1500),SinOsc.ar(500).range(0,2pi),[0.1,0.1])}.play(s);
45 // the ubiquitous houston example
47 b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
48 {FreqShift.ar(PlayBuf.ar(1,b.bufnum,BufRateScale.kr(b.bufnum),loop:1),LFNoise0.kr(0.45,1000),0,[1,1])}.play(s);
51 // shifting bandpassed noise
52 {FreqShift.ar(BPF.ar(WhiteNoise.ar(0.2),1000,0.001),LFNoise0.kr(5.5,1000),0,[32,32])}.play(s);
55 subsection:: More Examples
56 send a SynthDef, run the routine then send a different SynthDef
58 code::
59 (// simple detune & pitchmod via FreqShift
60 SynthDef("frqShift1",{arg frq,detune=1.5;
61         var e1,left,right;
62         e1 = EnvGen.ar(Env.new([0,0.1,0],[1,2.3]),1,doneAction:2);
63         left = SinOsc.ar(frq,0,e1); // original tone
64         left = left + FreqShift.ar(left,frq*detune); // shift and add back to original
65         right = FreqShift.ar(left,SinOsc.kr(3.23,0,5));
66         Out.ar(0, [left,right] * 0.1);
67 }).add;
70 (// the routine
71 r = Routine({
72         var table,pitch;
73         table = [0,2,4,5,7,9,11,12];
74         inf.do{
75                 pitch = (48+(12*2.rand) + table.choose).midicps;
76                 Synth.grain(\frqShift1, [\frq, pitch]);
77                 3.wait;
78                 };
79         };
80 ).play;
83 (// shift pulse wave in opposite directions
84 SynthDef("frqShift1",{arg frq,detune=0.15;
85         var e1,snd,left,right;
86         e1 = EnvGen.ar(Env.new([0,1,0],[0.02,3.2]),1,doneAction:2);
87         snd = Pulse.ar(frq,SinOsc.kr(2.3).range(0.2,0.8),e1); // original tone
88         left = FreqShift.ar(snd,XLine.kr(-0.1,-200,2)); // shift and add back to original
89         right = FreqShift.ar(snd,XLine.kr(0.1,200,2));
90         Out.ar(0, [left,right] * 0.1);
91 }).add
94 (// FreqShift >> feedback >>> FreqShiftc
95 SynthDef("frqShift1",{arg frq;
96         var e1,snd,snd2,in;
97         in = FreqShift.ar(InFeedback.ar(0,1)*3.2,XLine.ar(0.01,frq*1.5,1)); // shift the feedback
98         e1 = Env.new([0,0.1,0],[0.02,2.98]);
99         snd = SinOsc.ar(frq,0,EnvGen.ar(e1,1,doneAction:2));
100         snd2 = FreqShift.ar(snd+in,SinOsc.ar(4.24,0.5,3),0,0.5); // subtle modulating shift
101         OffsetOut.ar([0,1], Limiter.ar(snd2+snd * 0.5,1,0.005));
102 }).add;
106 (// ssllooww columbia tuned shift detune
107 r.stop; // stop old routine
108 Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav", bufnum:99);
110 SynthDef("frqShift1",{arg frq, bufnum;
111         var e1,snd,left,right;
112         e1 = Env.new([0,1,0],[3,1],-4);
113         snd = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum) * 0.01, loop:1);
114         left = FreqShift.ar(snd,frq*2,0,EnvGen.ar(e1,1,doneAction:2)); // subtle shift of the output
115         right = FreqShift.ar(snd,frq*3,0,EnvGen.ar(e1,1,doneAction:2));
116         Out.ar(0, [left,right] * 3);
117 }).add;
119 (// the routine
120 r = Routine({
121         var table,pitch;
122         table = [0,2,4,5,7,9,11,12];
123         inf.do{
124                 pitch = (48+(12*2.rand) + table.choose).midicps;
125                 s.sendMsg("s_new","frqShift1",-1,1,1, "frq", pitch, "bufnum", 99);
126                 3.wait;
127                 };
128         };
129 ).play;