Debian Codegraph @

opcodes/spat3d.xml

raw symbols SCIP
1
2 <refentry id="spat3d">
3 <indexterm id="IndexSpat3d"><primary>spat3d</primary></indexterm>
4 <refentryinfo><title>Signal Modifiers:Panning and Spatialization</title></refentryinfo>
5 <refmeta>
6 <refentrytitle>spat3d</refentrytitle>
7 </refmeta>
8
9
10
11 <refnamediv>
12 <refname>spat3d</refname>
13 <refpurpose>
14 Positions the input sound in a 3D space and allows moving the sound at k-rate.
15 </refpurpose>
16 </refnamediv>
17
18 <refsect1>
19 <title>Description</title>
20 <para>
21 This opcode positions the input sound in a 3D space, with optional simulation of room acoustics, in various output formats. <emphasis>spat3d</emphasis> allows moving the sound at k-rate (this movement is interpolated internally to eliminate "zipper noise" if sr not equal to kr).
22 </para>
23 </refsect1>
24
25 <refsect1>
26 <title>Syntax</title>
27 <synopsis>aW, aX, aY, aZ <command>spat3d</command> ain, kX, kY, kZ, idist, ift, imode, imdel, iovr [, istor]</synopsis>
28 </refsect1>
29
30 <refsect1>
31 <title>Initialization</title>
32 <para>
33 <emphasis>idist</emphasis> -- For modes 0 to 3, <emphasis>idist</emphasis> is the unit circle distance in meters. For mode 4, <emphasis>idist</emphasis> is the distance between microphones.
34 </para>
35
36 <para>
37 The following formulas describe amplitude and delay as a function of sound source distance from microphone(s):
38 <literallayout>
39 amplitude = 1 / (0.1 + distance)
40 </literallayout>
41
42 <literallayout>
43 delay = distance / 340 (in seconds)
44 </literallayout>
45 </para>
46
47 <para>
48 Distance can be calculated as:
49
50 <literallayout>
51 distance = sqrt(iX&circ;2 + iY&circ;2 + iZ&circ;2)
52 </literallayout>
53
54 In Mode 4, distance can be calculated as:
55
56 <literallayout>
57 distance from left mic = sqrt((iX + idist/2)&circ;2 + iY&circ;2 + iZ&circ;2)
58 distance from right mic = sqrt((iX - idist/2)&circ;2 + iY&circ;2 + iZ&circ;2)
59 </literallayout>
60 </para>
61
62 <para>
63 With <emphasis>spat3d</emphasis> the distance between the sound source and any microphone should be at least (340 * 18) / sr meters. Shorter distances will work, but may produce artifacts in some cases. There is no such limitation for <emphasis>spat3di</emphasis> and <emphasis>spat3dt</emphasis>.
64 </para>
65
66 <para>
67 Sudden changes or discontinuities in sound source location can result in pops or clicks. Very fast movement may also degrade quality.
68 </para>
69
70 <para>
71 <emphasis>ift</emphasis> -- Function table storing room parameters (for free field spatialization, set it to zero or negative). Table size is 54. The values in the table are:
72
73 <informaltable frame="all">
74 <tgroup cols="2" colsep="1" rowsep="1">
75 <thead>
76 <row>
77 <entry>Room Parameter</entry>
78 <entry>Purpose</entry>
79 </row>
80 </thead>
81
82 <tbody>
83 <row>
84 <entry>0</entry>
85 <entry>Early reflection recursion depth (0 is the sound source, 1 is the first reflection etc.) for spat3d and spat3di. The number of echoes for four walls (front, back, right, left) is: N = (2*R + 2) * R. If all six walls are enabled: N = (((4*R + 6)*R + 8)*R) / 3</entry>
86 </row>
87
88 <row>
89 <entry>1</entry>
90 <entry>Late reflection recursion depth (used by spat3dt only). spat3dt skips early reflections and renders echoes up to this level. If early reflection depth is negative, spat3d and spat3di will output zero, while spat3dt will start rendering from the sound source.</entry>
91 </row>
92
93 <row>
94 <entry>2</entry>
95 <entry>imdel for spat3d. Overrides opcode parameter if non-negative.</entry>
96 </row>
97
98 <row>
99 <entry>3</entry>
100 <entry>irlen for spat3dt. Overrides opcode parameter if non-negative.</entry>
101 </row>
102
103 <row>
104 <entry>4</entry>
105 <entry>idist value. Overrides opcode parameter if >= 0.</entry>
106 </row>
107
108 <row>
109 <entry>5</entry>
110 <entry>Random seed (0 - 65535) -1 seeds from current time.</entry>
111 </row>
112
113 <row>
114 <entry>6 - 53</entry>
115 <entry>wall parameters (w = 6: ceil, w = 14: floor, w = 22: front, w = 30: back, w = 38: right, w = 46: left)</entry>
116 </row>
117
118 <row>
119 <entry>w + 0</entry>
120 <entry>Enable reflections from this wall (0: no, 1: yes)</entry>
121 </row>
122
123 <row>
124 <entry>w + 1</entry>
125 <entry>Wall distance from listener (in meters)</entry>
126 </row>
127
128 <row>
129 <entry>w + 2</entry>
130 <entry>Randomization of wall distance (0 - 1) (in units of 1 / (wall distance))</entry>
131 </row>
132
133 <row>
134 <entry>w + 3</entry>
135 <entry>Reflection level (-1 - 1)</entry>
136 </row>
137
138 <row>
139 <entry>w + 4</entry>
140 <entry>Parametric equalizer frequency in Hz.</entry>
141 </row>
142
143 <row>
144 <entry>w + 5</entry>
145 <entry>Parametric equalizer level (1.0: no filtering)</entry>
146 </row>
147
148 <row>
149 <entry>w + 6</entry>
150 <entry>Parametric equalizer Q (0.7071: no resonance)</entry>
151 </row>
152
153 <row>
154 <entry>w + 7</entry>
155 <entry>Parametric equalizer mode (0: peak EQ, 1: low shelf, 2: high shelf)</entry>
156 </row>
157 </tbody>
158 </tgroup>
159 </informaltable>
160 </para>
161
162 <para>
163 <emphasis>imode</emphasis> -- Output mode
164 <itemizedlist>
165 <listitem><para>0: B format with W output only (mono)
166 <literallayout>
167 aout = aW
168 </literallayout>
169 </para></listitem>
170
171 <listitem><para>1: B format with W and Y output (stereo)
172 <literallayout>
173 aleft = aW + 0.7071*aY
174 aright = aW - 0.7071*aY
175 </literallayout>
176 </para></listitem>
177
178 <listitem><para>2: B format with W, X, and Y output (2D). This can be converted to UHJ:
179 <literallayout>
180 aWre, aWim hilbert aW
181 aXre, aXim hilbert aX
182 aYre, aYim hilbert aY
183 aWXr = 0.0928*aXre + 0.4699*aWre
184 aWXiYr = 0.2550*aXim - 0.1710*aWim + 0.3277*aYre
185 aleft = aWXr + aWXiYr
186 aright = aWXr - aWXiYr
187 </literallayout>
188 </para></listitem>
189
190 <listitem><para>3: B format with all outputs (3D)</para></listitem>
191
192 <listitem><para>4: Simulates a pair of microphones (stereo output)
193 <literallayout>
194 aW butterlp aW, ifreq ; recommended values for ifreq
195 aY butterlp aY, ifreq ; are around 1000 Hz
196 aleft = aW + aX
197 aright = aY + aZ
198 </literallayout>
199 </para></listitem>
200 </itemizedlist>
201 </para>
202
203 <para>
204 Mode 0 is the cheapest to calculate, while mode 4 is the most expensive.
205 </para>
206
207 <para>
208 In Mode 4, The optional lowpass filters can change the frequency response depending on direction. For example, if the sound source is located left to the listener then the high frequencies are attenuated in the right channel and slightly increased in the left. This effect can be disabled by not using filters. You can also experiment with other filters (tone etc.) for better effect.
209 </para>
210
211 <para>
212 Note that mode 4 is most useful for listening with headphones, and is also more expensive to calculate than the B-format (0 to 3) modes. The <emphasis>idist</emphasis> parameter in this case sets the distance between left and right microphone; for headphones, values between 0.2 - 0.25 are recommended, although higher settings up to 0.4 may be used for wide stereo effects.
213 </para>
214
215 <para>
216 More information about B format can be found here: <ulink url="http://www.york.ac.uk/inst/mustech/3d_audio/ambis2.htm"><citetitle>http://www.york.ac.uk/inst/mustech/3d_audio/ambis2.htm</citetitle></ulink>
217 </para>
218
219 <para>
220 <emphasis>imdel</emphasis> -- Maximum delay time for spat3d in seconds. This has to be longer than the delay time of the latest reflection (depends on room dimensions, sound source distance, and recursion depth; using this formula gives a safe (although somewhat overestimated) value:
221
222 <literallayout>
223 imdel = (R + 1) * sqrt(W*W + H*H + D*D) / 340.0
224 </literallayout>
225
226 where R is the recursion depth, W, H, and D are the width, height, and depth
227 of the room, respectively).
228 </para>
229
230 <para>
231 <emphasis>iovr</emphasis> -- Oversample ratio for spat3d (1 to 8). Setting it higher improves quality at the expense of memory and CPU usage. The recommended value is 2.
232 </para>
233
234 <para>
235 <emphasis>istor</emphasis> (optional, default=0) -- Skip initialization if non-zero (default: 0).
236 </para>
237 </refsect1>
238
239 <refsect1>
240 <title>Performance</title>
241 <para>
242 <emphasis>aW, aX, aY, aZ</emphasis> -- Output signals
243
244 <informaltable frame="all">
245 <tgroup cols="6" colsep="1" rowsep="1">
246 <thead>
247 <row>
248 <entry>&nbsp;</entry>
249 <entry>mode 0</entry>
250 <entry>mode 1</entry>
251 <entry>mode 2</entry>
252 <entry>mode 3</entry>
253 <entry>mode 4</entry>
254 </row>
255 </thead>
256
257 <tbody>
258 <row>
259 <entry>aW</entry>
260 <entry>W out</entry>
261 <entry>W out</entry>
262 <entry>W out</entry>
263 <entry>W out</entry>
264 <entry>left chn / low freq.</entry>
265 </row>
266
267 <row>
268 <entry>aX</entry>
269 <entry>0</entry>
270 <entry>0</entry>
271 <entry>X out</entry>
272 <entry>X out</entry>
273 <entry>left chn / high frq.</entry>
274 </row>
275
276 <row>
277 <entry>aY</entry>
278 <entry>0</entry>
279 <entry>Y out</entry>
280 <entry>Y out</entry>
281 <entry>Y out</entry>
282 <entry>right chn / low frq.</entry>
283 </row>
284
285 <row>
286 <entry>aZ</entry>
287 <entry>0</entry>
288 <entry>0</entry>
289 <entry>0</entry>
290 <entry>Z out</entry>
291 <entry>right chn / high fr.</entry>
292 </row>
293 </tbody>
294 </tgroup>
295 </informaltable>
296 </para>
297
298 <para>
299 <emphasis>ain</emphasis> -- Input signal
300 </para>
301
302 <para>
303 <emphasis>kX, kY, kZ</emphasis> -- Sound source coordinates (in meters)
304 </para>
305
306 <para>
307 If you encounter very slow performance (up to 100 times slower), it may be caused by denormals (this is also true of many other IIR opcodes, including <link linkend="butterlp"><citetitle>butterlp</citetitle></link>, <link linkend="pareq"><citetitle>pareq</citetitle></link>, <link linkend="hilbert"><citetitle>hilbert</citetitle></link>, and many others). Underflows can be avoided by:
308 <itemizedlist>
309 <listitem><para>Using the <link linkend="denorm"><citetitle>denorm</citetitle></link> opcode on <emphasis>ain</emphasis> before <emphasis>spat3d</emphasis>.</para></listitem>
310
311 <listitem><para>mixing low level DC or noise to the input signal, e.g. <literallayout>atmp rnd31 1/1e24, 0, 0</literallayout> <literallayout>aW, aX, aY, aZ spa3di ain + atmp, ...</literallayout> or <literallayout>aW, aX, aY, aZ spa3di ain + 1/1e24, ...</literallayout></para></listitem>
312 <listitem><para>reducing <emphasis>irlen</emphasis> in the case of <emphasis>spat3dt</emphasis> (which does not have an input signal). A value of about 0.005 is suitable for most uses, although it also depends on EQ settings. If the equalizer is not used, <quote>irlen</quote> can be set to 0.</para></listitem>
313 </itemizedlist>
314 </para>
315 </refsect1>
316
317 <refsect1>
318 <title>Examples</title>
319 <para>
320 Here is a example of the spat3d opcode that outputs a stereo file. It uses the file <ulink url="examples/spat3d_stereo.csd"><citetitle>spat3d_stereo.csd</citetitle></ulink>.
321
322 <example>
323 <title>Stereo example of the spat3d opcode.</title>
324
325 <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para>
326 <xi:include href="examples-xml/spat3d_stereo.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
327 </example>
328 </para>
329
330 <para>
331 Here is a example of the spat3d opcode that outputs a UHJ file. It uses the file <ulink url="examples/spat3d_UHJ.csd"><citetitle>spat3d_UHJ.csd</citetitle></ulink>.
332
333 <example>
334 <title>UHJ example of the spat3d opcode.</title>
335
336 <xi:include href="examples-xml/spat3d_UHJ.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
337 </example>
338 </para>
339
340 <para>
341 Here is a example of the spat3d opcode that outputs a quadrophonic file. It uses the file <ulink url="examples/spat3d_quad.csd"><citetitle>spat3d_quad.csd</citetitle></ulink>.
342
343 <example>
344 <title>Quadrophonic example of the spat3d opcode.</title>
345
346 <xi:include href="examples-xml/spat3d_quad.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
347 </example>
348 </para>
349 </refsect1>
350
351 <refsect1>
352 <title>See also</title>
353 <para><link linkend="SigmodPanspatl"><citetitle>Panning and Spatialization: Simulation of room acoustics</citetitle></link></para>
354 </refsect1>
355
356 <refsect1>
357 <title>Credits</title>
358 <para>
359 <simplelist>
360 <member>Author: &nameistvan;</member>
361 <member>2001</member>
362 </simplelist>
363 </para>
364
365 <para>New in version 4.12</para>
366 <para>Updated April 2002 by &nameistvan;</para>
367 </refsect1>
368 </refentry>