linux: shared memory interface - link with librt
[supercollider.git] / HelpSource / Classes / FreqShift.schelp
blob2ad330a7d870508ef66a4732cb7f7b6e3fb64f1f
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).
30 Examples::
32 code::
33 // shifting a 100Hz tone by 1 Hz rising to 500Hz
34 {FreqShift.ar(SinOsc.ar(100),XLine.kr(1,500,5),0,[0.1,0.1])}.play(s);
36 // shifting a complex tone by 1 Hz rising to 500Hz
37 {FreqShift.ar(Klang.ar(`[[101,303,606,808]]),XLine.kr(1,500,10),0,[0.1,0.1])}.play(s);
39 // modulating shift and phase
40 {FreqShift.ar(SinOsc.ar(10),LFNoise2.ar(0.3,1500),SinOsc.ar(500).range(0,2pi),[0.1,0.1])}.play(s);
42 // the ubiquitous houston example
44 b = Buffer.read(s, Help.dir +/+ "sounds/a11wlk01.wav");
45 {FreqShift.ar(PlayBuf.ar(1,b.bufnum,BufRateScale.kr(b.bufnum),loop:1),LFNoise0.kr(0.45,1000),0,[1,1])}.play(s);
48 // shifting bandpassed noise
49 {FreqShift.ar(BPF.ar(WhiteNoise.ar(0.2),1000,0.001),LFNoise0.kr(5.5,1000),0,[32,32])}.play(s);
52 subsection:: More Examples
53 send a SynthDef, run the routine then send a different SynthDef
55 code::
56 (// simple detune & pitchmod via FreqShift
57 SynthDef("frqShift1",{arg frq,detune=1.5;
58         var e1,left,right;
59         e1 = EnvGen.ar(Env.new([0,0.1,0],[1,2.3]),1,doneAction:2);
60         left = SinOsc.ar(frq,0,e1); // original tone
61         left = left + FreqShift.ar(left,frq*detune); // shift and add back to original
62         right = FreqShift.ar(left,SinOsc.kr(3.23,0,5));
63         Out.ar(0, [left,right] * 0.1);
64 }).add;
67 (// the routine
68 r = Routine({
69         var table,pitch;
70         table = [0,2,4,5,7,9,11,12];
71         inf.do{
72                 pitch = (48+(12*2.rand) + table.choose).midicps;
73                 Synth.grain(\frqShift1, [\frq, pitch]);
74                 3.wait;
75                 };
76         };
77 ).play;
80 (// shift pulse wave in opposite directions
81 SynthDef("frqShift1",{arg frq,detune=0.15;
82         var e1,snd,left,right;
83         e1 = EnvGen.ar(Env.new([0,1,0],[0.02,3.2]),1,doneAction:2);
84         snd = Pulse.ar(frq,SinOsc.kr(2.3).range(0.2,0.8),e1); // original tone
85         left = FreqShift.ar(snd,XLine.kr(-0.1,-200,2)); // shift and add back to original
86         right = FreqShift.ar(snd,XLine.kr(0.1,200,2));
87         Out.ar(0, [left,right] * 0.1);
88 }).add
91 (// FreqShift >> feedback >>> FreqShiftc
92 SynthDef("frqShift1",{arg frq;
93         var e1,snd,snd2,in;
94         in = FreqShift.ar(InFeedback.ar(0,1)*3.2,XLine.ar(0.01,frq*1.5,1)); // shift the feedback
95         e1 = Env.new([0,0.1,0],[0.02,2.98]);
96         snd = SinOsc.ar(frq,0,EnvGen.ar(e1,1,doneAction:2));
97         snd2 = FreqShift.ar(snd+in,SinOsc.ar(4.24,0.5,3),0,0.5); // subtle modulating shift
98         OffsetOut.ar([0,1], Limiter.ar(snd2+snd * 0.5,1,0.005));
99 }).add;
103 (// ssllooww columbia tuned shift detune
104 r.stop; // stop old routine
105 Buffer.read(s, Help.dir +/+ "sounds/a11wlk01.wav", bufnum:99);
107 SynthDef("frqShift1",{arg frq, bufnum;
108         var e1,snd,left,right;
109         e1 = Env.new([0,1,0],[3,1],-4);
110         snd = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum) * 0.01, loop:1);
111         left = FreqShift.ar(snd,frq*2,0,EnvGen.ar(e1,1,doneAction:2)); // subtle shift of the output
112         right = FreqShift.ar(snd,frq*3,0,EnvGen.ar(e1,1,doneAction:2));
113         Out.ar(0, [left,right] * 3);
114 }).add;
116 (// the routine
117 r = Routine({
118         var table,pitch;
119         table = [0,2,4,5,7,9,11,12];
120         inf.do{
121                 pitch = (48+(12*2.rand) + table.choose).midicps;
122                 s.sendMsg("s_new","frqShift1",-1,1,1, "frq", pitch, "bufnum", 99);
123                 3.wait;
124                 };
125         };
126 ).play;