1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"949.43">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #001bb9}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #ad140d}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #001bb9}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #2c7014}
18 span
.s1
{font: 18.0px Helvetica
}
19 span
.s2
{font: 9.0px Monaco
}
20 span
.s3
{color: #000000}
21 span
.s4
{color: #0021e7}
22 span
.s5
{color: #001bb9}
23 span
.s6
{color: #2c7014}
24 span
.s7
{color: #ad140d}
25 span
.Apple-tab-span
{white-space:pre
}
29 <p class=
"p1"><span class=
"s1"><b>SubsampleOffset
</b></span><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span><b>offset from synth start within one sample
</b></p>
30 <p class=
"p2"><br></p>
31 <p class=
"p3"><span class=
"s3"><b>Inherits from:
</b><a href=
"../../Core/Object.html"><span class=
"s4"><b>Object
</b></span></a></span><b> :
</b><a href=
"../../Core/Kernel/AbstractFunction.html"><b>AbstractFunction
</b></a><b> :
</b><a href=
"../UGen.html"><b>UGen
</b></a><b> :
<span class=
"Apple-converted-space"> </span></b><span class=
"s3"> <b>InfoUGenBase
</b></span></p>
32 <p class=
"p4"><br></p>
33 <p class=
"p1"><b>SubsampleOffset.ir
</b></p>
34 <p class=
"p4"><br></p>
35 <p class=
"p4"><br></p>
36 <p class=
"p1">When a synth is created from a time stamped osc-bundle, it starts calculation at the next possible block (normally
64 samples). Using an
<b>OffsetOut
</b> ugen, one can delay the audio so that it matches sample accurately.
<span class=
"Apple-converted-space"> </span></p>
37 <p class=
"p1">For some synthesis methods, one needs subsample accuracy.
<b>SubsampleOffset
</b> provides the information where, within the current sample, the synth was scheduled. It can be used to offset envelopes or resample the audio output.
</p>
38 <p class=
"p4"><br></p>
39 <p class=
"p1">see also:
<a href=
"../InOut/OffsetOut.html"><span class=
"s5">OffsetOut
</span></a></p>
40 <p class=
"p4"><br></p>
41 <p class=
"p4"><br></p>
42 <p class=
"p2"><br></p>
43 <p class=
"p5">// example: demonstrate cubic subsample interpolation
</p>
44 <p class=
"p2"><br></p>
45 <p class=
"p2"><br></p>
46 <p class=
"p5"><span class=
"s5">Server
</span><span class=
"s3">.default = s =
</span><span class=
"s5">Server
</span><span class=
"s3">.internal;
</span>// switch servers for scope
</p>
47 <p class=
"p2"><br></p>
48 <p class=
"p2"><br></p>
49 <p class=
"p5">// impulse train that can be moved between samples
</p>
51 <p class=
"p7">SynthDef
<span class=
"s3">(
</span><span class=
"s6">\Help_SubsampleOffset
</span><span class=
"s3">, {
</span>|out, addOffset|
</p>
52 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s5">var
</span> in, dt, sampDur, extraSamples, sampleOffset, resampledSignal;
</p>
53 <p class=
"p6"><span class=
"Apple-tab-span"> </span>in =
<span class=
"s5">Impulse
</span>.ar(
2000,
0,
0.3);
<span class=
"s7">// some input.
</span></p>
54 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span>sampDur =
</span><span class=
"s5">SampleDur
</span><span class=
"s3">.ir;
<span class=
"Apple-tab-span"> </span></span>// duration of one sample
</p>
55 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span>extraSamples =
4;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// DelayC needs at least
4 samples buffer
</p>
56 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span>sampleOffset =
1 -
</span><span class=
"s5">SubsampleOffset
</span><span class=
"s3">.ir;
</span>// balance out subsample offset
</p>
57 <p class=
"p6"><span class=
"Apple-tab-span"> </span>sampleOffset = sampleOffset +
<span class=
"s5">MouseX
</span>.kr(
0, addOffset);
<span class=
"s7">// add a mouse dependent offset
</span></p>
58 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>// cubic resampling:
</p>
59 <p class=
"p6"><span class=
"Apple-tab-span"> </span>resampledSignal =
<span class=
"s5">DelayC
</span>.ar(in,
<span class=
"Apple-converted-space"> </span></p>
60 <p class=
"p6"><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><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>maxdelaytime: sampDur * (
1 + extraSamples),
</p>
61 <p class=
"p6"><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><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>delaytime: sampDur * (sampleOffset + extraSamples)
</p>
62 <p class=
"p6"><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>);
</p>
63 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s5">OffsetOut
</span>.ar(out, resampledSignal)
</p>
64 <p class=
"p6">}).send(s);
</p>
66 <p class=
"p2"><br></p>
67 <p class=
"p5">// create
2 pulse trains
1 sample apart, move one relatively to the other.
</p>
68 <p class=
"p5">// when cursor is at the left, the impulses are adjacent, on the right, they are
</p>
69 <p class=
"p5">// exactly
1 sample apart.
</p>
70 <p class=
"p2"><br></p>
72 <p class=
"p6"><span class=
"s5">var
</span> dt = s.sampleRate.reciprocal;
<span class=
"s7">//
1 sample delay
</span></p>
73 <p class=
"p6">s.sendBundle(
0.2, [
9,
<span class=
"s6">\Help_SubsampleOffset
</span>, s.nextNodeID,
1,
1,
<span class=
"s6">\out
</span>,
40,
<span class=
"s6">\addOffset
</span>,
3]);
</p>
74 <p class=
"p6">s.sendBundle(
0.2 + dt, [
9,
<span class=
"s6">\Help_SubsampleOffset
</span>, s.nextNodeID,
1,
1,
<span class=
"s6">\out
</span>,
40,
<span class=
"s6">\addOffset
</span>,
0]);
</p>
76 <p class=
"p2"><br></p>
77 <p class=
"p6">s.scope(
1,
40, zoom:
0.2);
</p>
78 <p class=
"p2"><br></p>
79 <p class=
"p2"><br></p>
80 <p class=
"p2"><br></p>
81 <p class=
"p2"><br></p>
82 <p class=
"p2"><br></p>
83 <p class=
"p5">// example of a subsample accurate sine grain:
</p>
84 <p class=
"p5">// (I don't hear a difference to normal sample accurate grains, but maybe
</p>
85 <p class=
"p5">// someone could add an example that shows the effect)
</p>
86 <p class=
"p2"><br></p>
88 <p class=
"p8"><span class=
"s5">SynthDef
</span><span class=
"s3">(
</span>\Help_Subsample_Grain
<span class=
"s3">,
<span class=
"Apple-converted-space"> </span></span></p>
89 <p class=
"p6"><span class=
"Apple-tab-span"> </span>{
<span class=
"s5">arg
</span> out=
0, freq=
440, sustain=
0.005, attack=
0.001;
</p>
90 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">var
</span> env, offset, sig, sd;
</p>
91 <p class=
"p2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
92 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>sd =
<span class=
"s5">SampleDur
</span>.ir;
</p>
93 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>offset = (
1 -
<span class=
"s5">SubsampleOffset
</span>.ir) * sd;
</p>
94 <p class=
"p5"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// free synth after delay:
</p>
95 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">Line
</span>.ar(
1,
0, attack + sustain + offset, doneAction:
2);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>env =
<span class=
"s5">EnvGen
</span>.kr(
<span class=
"s5">Env
</span>.perc(attack, sustain,
0.2));
</p>
96 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s5">SinOsc
</span>.ar(freq,
0, env);
</p>
97 <p class=
"p2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
98 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s5">DelayC
</span>.ar(sig, sd *
4, offset);
</p>
99 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">OffsetOut
</span>.ar(out, sig);
</p>
100 <p class=
"p6"><span class=
"Apple-tab-span"> </span>}, [
<span class=
"s6">\ir
</span>,
<span class=
"s6">\ir
</span>,
<span class=
"s6">\ir
</span>,
<span class=
"s6">\ir
</span>]).send(s);
</p>
102 <p class=
"p2"><br></p>
104 <p class=
"p7"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>Routine
<span class=
"s3"> {
</span></p>
105 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>loop {
</p>
106 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>s.sendBundle(
0.2, [
9,
<span class=
"s6">\Help_Subsample_Grain
</span>, -
1,
1,
1,
<span class=
"s6">\freq
</span>,
1000]);
</p>
107 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>rrand(
0.001,
0.002).wait;
</p>
108 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
109 <p class=
"p6"><span class=
"Apple-tab-span"> </span>}.play;
</p>
111 <p class=
"p2"><br></p>
112 <p class=
"p2"><br></p>