1 Signal[float] : FloatArray {
3 *sineFill { arg size, amplitudes, phases;
4 ^Signal.newClear(size).sineFill(amplitudes, phases).normalize
6 *chebyFill { arg size, amplitudes, normalize=true;
7 ^Signal.newClear(size).chebyFill(amplitudes, normalize); //.normalizeTransfer //shouldn't normalize by default!
9 *hammingWindow { arg size, pad=0;
11 ^this.newClear(size).fill(0.5).addSine(1, 0.39, -0.5pi);
13 ^this.newClear(size-pad).fill(0.5).addSine(1, 0.39, -0.5pi) ++ this.newClear(pad);
16 *hanningWindow { arg size, pad=0;
18 ^this.newClear(size).fill(0.5).addSine(1, 0.5, -0.5pi);
20 ^this.newClear(size-pad).fill(0.5).addSine(1, 0.5, -0.5pi) ++ this.newClear(pad);
23 *welchWindow { arg size, pad=0;
25 ^this.newClear(size).addSine(0.5, 1, 0);
27 ^this.newClear(size-pad).addSine(0.5, 1, 0) ++ this.newClear(pad);
30 *rectWindow { arg size, pad=0;
32 ^this.newClear(size).fill(1.0);
34 ^this.newClear(size-pad).fill(1.0) ++ this.newClear(pad);
42 fill { arg val; _SignalFill ^this.primitiveFailed }
43 scale { arg scale; _SignalScale ^this.primitiveFailed }
44 offset { arg offset; _SignalOffset ^this.primitiveFailed }
47 // Interpolating oscillators require wavetables in a special format.
48 // This method returns a wavetable in that format.
54 // Shaper requires wavetables without wrap.
55 // This method returns a wavetable in that format.
56 //To generate size N wavetable need N/2+1 signal values rather than N/2
57 //because Buffer's add_wchebyshev calculates N/2+1 values whilst
58 //Signal's _SignalAddChebyshev calculates N/2!
60 var newsig = Signal.newClear((this.size-1)*2);
68 newsig[index]= 2*cur -next;
69 newsig[index+1]= next-cur;
77 peak { _SignalPeak; ^this.primitiveFailed }
79 normalize { arg beginSamp=0, endSamp;
84 _SignalNormalizeTransferFn;
88 invert { arg beginSamp=0, endSamp;
92 reverse { arg beginSamp=0, endSamp;
96 fade { arg beginSamp=0, endSamp, beginLevel=0.0, endLevel=1.0;
102 ^this.primitiveFailed
105 zeroPad { arg minSize;
106 var size = max(minSize ? 0, this.size).nextPowerOfTwo;
107 ^this ++ Signal.newClear(size - this.size);
110 integral { _SignalIntegral; ^this.primitiveFailed }
111 overDub { arg aSignal, index=0;
113 // add a signal to myself starting at the index
114 // if the other signal is too long only the first part is overdubbed
115 ^this.primitiveFailed
117 overWrite { arg aSignal, index=0;
119 // write a signal to myself starting at the index
120 // if the other signal is too long only the first part is overwritten
121 ^this.primitiveFailed
124 play { arg loop=false, mul=0.2, numChannels=1, server;
126 buf = Buffer.sendCollection(server ? Server.default, this, numChannels, -1, { buf.play(loop, mul); });
130 waveFill { arg function, start = 0.0, end = 1.0;
131 var i = 0, step, size, val, x;
133 // evaluate a function for every sample over the interval from
136 if (size <= 0, { ^this });
139 step = (end - start) / size;
140 while ({ i < size }, {
141 val = function.value(x, this.at(i), i);
148 addSine { arg harmonicNumber = 1, amplitude = 1.0, phase = 0.0;
150 ^this.primitiveFailed
152 sineFill { arg amplitudes, phases;
154 if (phases.isNil, { phases = #[0]; });
155 amplitudes.do({ arg amp, i; this.addSine(i+1, amp, phases @@ i) });
157 sineFill2 { arg list;
159 list.do({ arg item, i;
160 var harm, amp, phase;
161 # harm, amp, phase = item;
162 this.addSine(harm, amp ? 1.0, phase ? 0.0);
166 addChebyshev { arg harmonicNumber = 1, amplitude = 1.0;
168 ^this.primitiveFailed
170 chebyFill { arg amplitudes, normalize=true;
172 amplitudes.do({ arg amp, i; this.addChebyshev(i+1, amp); if(i%4==1,{this.offset(1)}); if(i%4==3,{this.offset(-1)}); }); //corrections for JMC DC offsets, as per Buffer:cheby
174 if(normalize,{this.normalizeTransfer}); //no automatic cheby
178 chebyFill_old { arg amplitudes;
180 amplitudes.do({ arg amp, i; this.addChebyshev(i+1, amp) });
181 this.normalizeTransfer
185 *fftCosTable { arg fftsize;
186 ^this.newClear((fftsize/4) + 1).fftCosTable
190 harm = this.size / ((this.size - 1) * 4);
191 this.addSine(harm, 1, 0.5pi);
194 fft { arg imag, cosTable;
195 // argCosTable must contain 1/4 cycle of a cosine (use fftCosTable)
196 // fftsize is the next greater power of two than the receiver's length
198 ^this.primitiveFailed
200 ifft { arg imag, cosTable;
201 // argCosTable must contain 1/4 cycle of a cosine (use fftCosTable)
202 // fftsize is the next greater power of two than the receiver's length
204 ^this.primitiveFailed
207 neg { _Neg; ^this.primitiveFailed }
208 abs { _Abs; ^this.primitiveFailed }
209 sign { _Sign; ^this.primitiveFailed }
210 squared { _Squared; ^this.primitiveFailed }
211 cubed { _Cubed; ^this.primitiveFailed }
212 sqrt { _Sqrt; ^this.primitiveFailed }
213 exp { _Exp; ^this.primitiveFailed }
214 //reciprocal { _Recip; ^this.primitiveFailed }
215 //midicps { _MIDICPS; ^this.primitiveFailed }
216 //cpsmidi { _CPSMIDI; ^this.primitiveFailed }
217 //midiratio { _MIDIRatio; ^this.primitiveFailed }
218 //ratiomidi { _RatioMIDI; ^this.primitiveFailed }
219 //ampdb { _AmpDb; ^this.primitiveFailed }
220 //dbamp { _DbAmp; ^this.primitiveFailed }
221 //octcps { _OctCPS; ^this.primitiveFailed }
222 //cpsoct { _CPSOct; ^this.primitiveFailed }
223 log { _Log; ^this.primitiveFailed }
224 log2 { _Log2; ^this.primitiveFailed }
225 log10 { _Log10; ^this.primitiveFailed }
226 sin { _Sin; ^this.primitiveFailed }
227 cos { _Cos; ^this.primitiveFailed }
228 tan { _Tan; ^this.primitiveFailed }
229 asin { _ArcSin; ^this.primitiveFailed }
230 acos { _ArcCos; ^this.primitiveFailed }
231 atan { _ArcTan; ^this.primitiveFailed }
232 sinh { _SinH; ^this.primitiveFailed }
233 cosh { _CosH; ^this.primitiveFailed }
234 tanh { _TanH; ^this.primitiveFailed }
235 distort { _Distort; ^this.primitiveFailed }
236 softclip { _SoftClip; ^this.primitiveFailed }
238 rectWindow { _RectWindow; ^this.primitiveFailed }
239 hanWindow { _HanWindow; ^this.primitiveFailed }
240 welWindow { _WelchWindow; ^this.primitiveFailed }
241 triWindow { _TriWindow; ^this.primitiveFailed }
243 scurve { _SCurve; ^this.primitiveFailed }
244 ramp { _Ramp; ^this.primitiveFailed }
246 + { arg aNumber; _Add; ^aNumber.performBinaryOpOnSignal('+', this) }
247 - { arg aNumber; _Sub; ^aNumber.performBinaryOpOnSignal('-', this) }
248 * { arg aNumber; _Mul; ^aNumber.performBinaryOpOnSignal('*', this) }
249 / { arg aNumber; _FDiv; ^aNumber.performBinaryOpOnSignal('/', this) }
250 mod { arg aNumber; _Mod; ^aNumber.performBinaryOpOnSignal('mod', this) }
251 div { arg aNumber; _IDiv; ^aNumber.performBinaryOpOnSignal('div', this) }
252 pow { arg aNumber; _Pow; ^aNumber.performBinaryOpOnSignal('pow', this) }
253 min { arg aNumber; _Min; ^aNumber.performBinaryOpOnSignal('min', this) }
254 max { arg aNumber; _Max; ^aNumber.performBinaryOpOnSignal('max', this) }
255 ring1 { arg aNumber; _Ring1; ^aNumber.performBinaryOpOnSignal('ring1', this) }
256 ring2 { arg aNumber; _Ring2; ^aNumber.performBinaryOpOnSignal('ring2', this) }
257 ring3 { arg aNumber; _Ring3; ^aNumber.performBinaryOpOnSignal('ring3', this) }
258 ring4 { arg aNumber; _Ring4; ^aNumber.performBinaryOpOnSignal('ring4', this) }
259 difsqr { arg aNumber; _DifSqr; ^aNumber.performBinaryOpOnSignal('difsqr', this) }
260 sumsqr { arg aNumber; _SumSqr; ^aNumber.performBinaryOpOnSignal('sumsqr', this) }
261 sqrsum { arg aNumber; _SqrSum; ^aNumber.performBinaryOpOnSignal('sqrsum', this) }
262 sqrdif { arg aNumber; _SqrDif; ^aNumber.performBinaryOpOnSignal('sqrdif', this) }
263 absdif { arg aNumber; _AbsDif; ^aNumber.performBinaryOpOnSignal('absdif', this) }
264 thresh { arg aNumber; _Thresh; ^aNumber.performBinaryOpOnSignal('thresh', this) }
265 amclip { arg aNumber; _AMClip; ^aNumber.performBinaryOpOnSignal('amclip', this) }
266 scaleneg { arg aNumber; _ScaleNeg; ^aNumber.performBinaryOpOnSignal('scaleneg', this) }
267 clip2 { arg aNumber=1; _Clip2; ^aNumber.performBinaryOpOnSignal('clip2', this) }
268 fold2 { arg aNumber; _Fold2; ^aNumber.performBinaryOpOnSignal('fold2', this) }
269 wrap2 { arg aNumber; _Wrap2; ^aNumber.performBinaryOpOnSignal('wrap2', this) }
270 excess { arg aNumber; _Excess; ^aNumber.performBinaryOpOnSignal('excess', this) }
271 firstArg { arg aNumber; _FirstArg; ^aNumber.performBinaryOpOnSignal('firstArg', this) }
273 == { arg aNumber; _EQ; ^aNumber.performBinaryOpOnSignal('==', this) }
274 != { arg aNumber; _NE; ^aNumber.performBinaryOpOnSignal('!=', this) }
276 clip { arg lo, hi; _ClipSignal; ^this.primitiveFailed }
277 wrap { arg lo, hi; _WrapSignal; ^this.primitiveFailed }
278 fold { arg lo, hi; _FoldSignal; ^this.primitiveFailed }
280 asInteger { _AsInt; ^this.primitiveFailed }
281 asFloat { _AsFloat; ^this.primitiveFailed }
282 asComplex { ^Complex.new(this, 0.0) }
290 performBinaryOpOnSignal { arg aSelector, aNumber, adverb;
291 BinaryOpFailureError(this, aSelector, [aNumber, adverb]).throw;
295 Wavetable[float] : FloatArray {
296 // the only way to make a Wavetable is by Signal::asWavetable
298 ^this.shouldNotImplement(thisMethod)
301 ^this.shouldNotImplement(thisMethod)
304 *sineFill { arg size, amplitudes, phases;
305 ^Signal.sineFill(size, amplitudes, phases).asWavetable
308 //size must be N/2+1 for N power of two; N is eventual size of wavetable
309 *chebyFill { arg size, amplitudes, normalize=true;
311 ^Signal.chebyFill(size, amplitudes, normalize).asWavetableNoWrap; //asWavetable causes wrap here, problem
314 *chebyFill_old { arg size, amplitudes;
316 //this.deprecated(thisMethod, Buffer.findRespondingMethodFor(\cheby));
318 ^Signal.chebyFill(size, amplitudes).asWavetable; //asWavetable causes wrap here, problem
323 ^this.primitiveFailed
326 blend { arg anotherWavetable, blendFrac=0.5;
327 ^this.asSignal.blend(anotherWavetable.asSignal, blendFrac).asWavetable;
331 ^file.readAllSignal.asWavetable;
335 file = File.new(path, "wb");
337 file.write(this.asSignal);
341 //libMenuAction { arg names;
342 // this.plot(names.last);