2 summary::Sampled audio buffer
3 related::Classes/Wavetable
7 A Signal is a FloatArray that represents a sampled function of time buffer. Signals support math operations.
12 Fill a Signal of the given size with a sum of sines at the given amplitudes and phases. The Signal will be normalized.
14 Signal.sineFill(1000, 1.0/[1, 2, 3, 4, 5, 6]).plot;
17 the number of samples in the Signal.
19 an Array of amplitudes for each harmonic beginning with the fundamental.
21 an Array of phases in radians for each harmonic beginning with the fundamental.
24 Fill a Signal of the given size with a sum of Chebyshev polynomials at the given amplitudes. For eventual use in waveshaping by the Shaper ugen; see link::Classes/Shaper:: helpfile and link::Classes/Buffer#-cheby#Buffer:cheby:: too.
26 Signal.chebyFill(1000, [1]).plot;
27 Signal.chebyFill(1000, [0, 1]).plot;
28 Signal.chebyFill(1000, [0, 0, 1]).plot;
29 Signal.chebyFill(1000, [0.3, -0.8, 1.1]).plot;
32 the number of samples in the Signal.
34 an Array of amplitudes for each Chebyshev polynomial beginning with order 1.
37 Fill a Signal of the given size with a Hanning window.
39 Signal.hanningWindow(1024).plot;
40 Signal.hanningWindow(1024, 512).plot;
43 the number of samples in the Signal.
45 the number of samples of the size that is zero padding.
48 Fill a Signal of the given size with a Hamming window.
50 Signal.hammingWindow(1024).plot;
51 Signal.hammingWindow(1024, 512).plot;
54 the number of samples in the Signal.
56 the number of samples of the size that is zero padding.
59 Fill a Signal of the given size with a Welch window.
61 Signal.welchWindow(1024).plot;
62 Signal.welchWindow(1024, 512).plot;
65 the number of samples in the Signal.
67 the number of samples of the size that is zero padding.
70 Fill a Signal of the given size with a rectangular window.
72 Signal.rectWindow(1024).plot;
73 Signal.rectWindow(1024, 512).plot;
76 the number of samples in the Signal.
78 the number of samples of the size that is zero padding.
81 Fourier Transform: Fill a Signal with the cosine table needed by the FFT methods. See also the instance methods link::#-fft:: and link::#-ifft::.
83 Signal.fftCosTable(512).plot;
88 private::performBinaryOpOnSignal, performBinaryOpOnComplex, performBinaryOpOnSimpleNumber
91 Plot the Signal in a window. The arguments are not required and if not given defaults will be used.
93 Signal.sineFill(512, [1]).plot;
94 Signal.sineFill(512, [1]).plot("Signal 1", Rect(50, 50, 150, 450));
97 a String, the name of the window.
99 a Rect giving the bounds of the window.
102 Loads the signal into a buffer on the server and plays it. Returns the buffer so you can free it again.
104 b = Signal.sineFill(512, [1]).play(true, 0.2);
105 b.free; // free the buffer again.
108 A link::Classes/Boolean:: whether to loop the entire signal or play it once. Default is to loop.
110 volume at which to play it, 0.2 by default.
111 argument::numChannels
112 if the signal is an interleaved multichannel file, number of channels, default is 1.
114 the server on which to load the signal into a buffer.
117 Fill the Signal with a function evaluated over an interval.
120 a = Signal.newClear(512);
121 a.waveFill({ arg x, i; sin(x).max(0) }, 0, 3pi);
126 a function that should calculate the value of a sample.
128 The function is called with two arguments:
130 ## x || the value along the interval.
131 ## i || the sample index.
135 the starting value of the interval.
137 the ending value of the interval.
140 Convert the Signal into a Wavetable.
142 Signal.sineFill(512, [1]).asWavetable.plot;
146 Fill the Signal with a value.
148 Signal.newClear(512).fill(0.2).plot;
152 Scale the Signal by a factor strong::in place::.
154 a = Signal[1, 2, 3, 4];
159 Offset the Signal by a value strong::in place::.
161 a = Signal[1, 2, 3, 4];
166 Return the peak absolute value of a Signal.
168 Signal[1, 2, -3, 2.5].peak;
172 Normalize the Signal strong::in place:: such that the maximum absolute peak value is 1.
174 Signal[1, 2, -4, 2.5].normalize;
175 Signal[1, 2, -4, 2.5].normalize(0, 1); // normalize only a range
178 method::normalizeTransfer
179 Normalizes a transfer function so that the center value of the table is offset to zero and the absolute peak value is 1. Transfer functions are meant to be used in the link::Classes/Shaper:: ugen.
181 Signal[1, 2, 3, 2.5, 1].normalizeTransfer;
185 Invert the Signal strong::in place::.
187 a = Signal[1, 2, 3, 4];
192 Reverse a subrange of the Signal strong::in place::.
194 a = Signal[1, 2, 3, 4];
199 Fade a subrange of the Signal strong::in place::.
201 a = Signal.fill(10, 1);
202 a.fade(0, 3); // fade in
203 a.fade(6, 9, 1, 0); // fade out
207 Return the integral of a signal.
209 Signal[1, 2, 3, 4].integral;
213 Add a signal to myself starting at the index. If the other signal is too long only the first part is overdubbed.
215 a = Signal.fill(10, 100);
216 a.overDub(Signal[1, 2, 3, 4], 3);
219 a = Signal.fill(10, 100);
220 a.overDub(Signal[1, 2, 3, 4], 8);
222 a = Signal.fill(10, 100);
223 a.overDub(Signal[1, 2, 3, 4], -4);
225 a = Signal.fill(10, 100);
226 a.overDub(Signal[1, 2, 3, 4], -1);
228 a = Signal.fill(10, 100);
229 a.overDub(Signal[1, 2, 3, 4], -2);
231 a = Signal.fill(4, 100);
232 a.overDub(Signal[1, 2, 3, 4, 5, 6, 7, 8], -2);
236 Write a signal to myself starting at the index. If the other signal is too long only the first part is overdubbed.
238 a = Signal.fill(10, 100);
239 a.overWrite(Signal[1, 2, 3, 4], 3);
242 a = Signal.fill(10, 100);
243 a.overWrite(Signal[1, 2, 3, 4], 8);
245 a = Signal.fill(10, 100);
246 a.overWrite(Signal[1, 2, 3, 4], -4);
248 a = Signal.fill(10, 100);
249 a.overWrite(Signal[1, 2, 3, 4], -1);
251 a = Signal.fill(10, 100);
252 a.overWrite(Signal[1, 2, 3, 4], -2);
254 a = Signal.fill(4, 100);
255 a.overWrite(Signal[1, 2, 3, 4, 5, 6, 7, 8], -2);
259 Blend two signals by some proportion.
261 Signal[1, 2, 3, 4].blend(Signal[5, 5, 5, 0], 0);
262 Signal[1, 2, 3, 4].blend(Signal[5, 5, 5, 0], 0.2);
263 Signal[1, 2, 3, 4].blend(Signal[5, 5, 5, 0], 0.4);
264 Signal[1, 2, 3, 4].blend(Signal[5, 5, 5, 0], 1);
265 Signal[1, 2, 3, 4].blend(Signal[5, 5, 5, 0], 2);
268 subsection::Fourier Transform
271 Perform an FFT on a real and imaginary signal in place. See also the class method link::#*fftCosTable::.
274 var size = 512, real, imag, cosTable, complex;
276 real = Signal.newClear(size);
278 real.sineFill2([[8], [13, 0.5], [21, 0.25], [55, 0.125, 0.5pi]]);
279 // add a little noise
280 real.overDub(Signal.fill(size, { 0.2.bilinrand }));
282 imag = Signal.newClear(size);
283 cosTable = Signal.fftCosTable(size);
285 complex = fft(real, imag, cosTable);
286 [real, imag, (complex.magnitude) / 100 ].flop.flat
287 .plot("fft", Rect(0, 0, 512 + 8, 500), numChannels: 3);
292 Perform an inverse FFT on a real and imaginary signal in place. See also the class method link::#*fftCosTable::.
295 var size = 512, real, imag, cosTable, complex, ifft;
297 real = Signal.newClear(size);
299 real.sineFill2([[8], [13, 0.5], [21, 0.25], [55, 0.125, 0.5pi]]);
300 // add a little noise
301 real.overDub(Signal.fill(size, { 0.2.bilinrand }));
303 imag = Signal.newClear(size);
304 cosTable = Signal.fftCosTable(size);
306 complex = fft(real, imag, cosTable).postln;
307 ifft = complex.real.ifft(complex.imag, cosTable);
309 [real, ifft.real].flop.flat
310 .plot("fft and back", Rect(0, 0, 512 + 8, 500), numChannels: 2);
314 subsection::Unary Messages
316 Signal will respond to unary operators by returning a new Signal.
318 x = Signal.sineFill(512, [0, 0, 0, 1]);
319 [x, x.neg, x.abs, x.sign, x.squared, x.cubed, x.asin.normalize, x.exp.normalize, x.distort].flop.flat
320 .plot(numChannels: 9);
323 method::neg, abs, sign, squared, cubed, sqrt, exp, log, log2, log10, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, distort, softclip, nyqring, isPositive, isNegative, isStrictlyPositive
325 subsection::Binary Messages
327 Signal will respond to binary operators by returning a new Signal.
330 x = Signal.fill(512, { rrand(0.0, 1.0) });
331 y = Signal.fill(512, { |i| (i * pi / 64).sin });
332 [x, y, (x + y) * 0.5, x * y, min(x, y), max(x, y) ].flop.flat
333 .plot(numChannels: 6);
336 method::+, -, *, /, div, %, **, min, max, ring1, ring2, ring3, ring4,
337 difsqr, sumsqr, sqrdif, absdif, amclip, scaleneg, clip2, excess, <!