| 1 | |
| 2 | <refentry id="sndwarpst"> |
| 3 | <indexterm id="IndexSndwarpst"><primary>sndwarpst</primary></indexterm> |
| 4 | <refentryinfo><title>Signal Generators:Granular Synthesis</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>sndwarpst</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | |
| 10 | |
| 11 | <refnamediv> |
| 12 | <refname>sndwarpst</refname> |
| 13 | <refpurpose> |
| 14 | Reads a stereo sound sample from a table and applies time-stretching and/or pitch modification. |
| 15 | </refpurpose> |
| 16 | </refnamediv> |
| 17 | |
| 18 | <refsect1> |
| 19 | <title>Description</title> |
| 20 | <para> |
| 21 | <emphasis>sndwarpst</emphasis> reads stereo sound samples from a table and applies time-stretching and/or pitch modification. Time and frequency modification are independent from one another. For example, a sound can be stretched in time while raising the pitch! |
| 22 | </para> |
| 23 | |
| 24 | <para> |
| 25 | The window size and overlap arguments are important to the result and should be experimented with. In general they should be as small as possible. For example, start with <emphasis>iwsize</emphasis>=sr/10 and <emphasis>ioverlap</emphasis>=15. Try <emphasis>irandw</emphasis>=<emphasis>iwsize</emphasis>*.2. If you can get away with less overlaps, the program will be faster. But too few may cause an audible flutter in the amplitude. The algorithm reacts differently depending upon the input sound and there are no fixed rules for the best use in all circumstances. But with proper tuning, excellent results can be achieved. |
| 26 | </para> |
| 27 | </refsect1> |
| 28 | |
| 29 | <refsect1> |
| 30 | <title>Syntax</title> |
| 31 | <synopsis>ar1, ar2 [,ac1] [, ac2] <command>sndwarpst</command> xamp, xtimewarp, xresample, ifn1, \ |
| 32 | ibeg, iwsize, irandw, ioverlap, ifn2, itimemode</synopsis> |
| 33 | </refsect1> |
| 34 | |
| 35 | <refsect1> |
| 36 | <title>Initialization</title> |
| 37 | <para> |
| 38 | <emphasis>ifn1</emphasis> -- the number of the table holding the sound samples which will be subjected to the <emphasis>sndwarpst</emphasis> processing. <link linkend="GEN01"><citetitle>GEN01</citetitle></link> is the appropriate function generator to use to store the sound samples from a pre-existing soundfile. |
| 39 | </para> |
| 40 | |
| 41 | <para> |
| 42 | <emphasis>ibeg</emphasis> -- the time in seconds to begin reading in the table (or soundfile). When <emphasis>itimemode</emphasis> is non-zero, the value of <emphasis>xtimewarp</emphasis> is offset by <emphasis>ibeg</emphasis>. |
| 43 | </para> |
| 44 | |
| 45 | <para> |
| 46 | <emphasis>iwsize</emphasis> -- the window size in samples used in the time scaling algorithm. |
| 47 | </para> |
| 48 | |
| 49 | <para> |
| 50 | <emphasis>irandw</emphasis> -- the bandwidth of a random number generator. The random numbers will be added to <emphasis>iwsize</emphasis>. |
| 51 | </para> |
| 52 | |
| 53 | <para> |
| 54 | <emphasis>ioverlap</emphasis> -- determines the density of overlapping windows. |
| 55 | </para> |
| 56 | |
| 57 | <para> |
| 58 | <emphasis>ifn2</emphasis> -- a function used to shape the window. It is usually used to create a ramp of some kind from zero at the beginning and back down to zero at the end of each window. Try using a half a sine (i.e.: f1 0 16384 9 .5 1 0) which works quite well. Other shapes can also be used. |
| 59 | </para> |
| 60 | </refsect1> |
| 61 | |
| 62 | <refsect1> |
| 63 | <title>Performance</title> |
| 64 | <para> |
| 65 | <emphasis>ar1, ar2</emphasis> -- <emphasis>ar1</emphasis> and <emphasis>ar2</emphasis> are the stereo (left and right) outputs from <emphasis>sndwarpst</emphasis>. <emphasis>sndwarpst</emphasis> assumes that the function table holding the sampled signal is a stereo one. <emphasis>sndwarpst</emphasis> will index the table by a two-sample frame increment. The user must be aware then that if a mono signal is used with <emphasis>sndwarpst</emphasis>, time and pitch will be altered accordingly. |
| 66 | </para> |
| 67 | |
| 68 | <para> |
| 69 | <emphasis>ac1, ac2</emphasis> -- <emphasis>ac1</emphasis> and <emphasis>ac2</emphasis> are single-layer (no overlaps), unwindowed versions of the time and/or pitch altered signal. They are supplied in order to be able to balance the amplitude of the signal output, which typically contains many overlapping and windowed versions of the signal, with a clean version of the time-scaled and pitch-shifted signal. The <emphasis>sndwarpst</emphasis> process can cause noticeable changes in amplitude, (up and down), due to a time differential between the overlaps when time-shifting is being done. When used with a <link linkend="balance"><citetitle>balance</citetitle></link> unit, <emphasis>ac1</emphasis> and <emphasis>ac2</emphasis> can greatly enhance the quality of sound. They are optional, but note that they must both be present in the syntax (use both or neither). An example of how to use this is given below. |
| 70 | </para> |
| 71 | |
| 72 | <para> |
| 73 | <emphasis>xamp</emphasis> -- the value by which to scale the amplitude (see note on the use of this when using <emphasis>ac1</emphasis> and <emphasis>ac2</emphasis>). |
| 74 | </para> |
| 75 | |
| 76 | <para> |
| 77 | <emphasis>xtimewarp</emphasis> -- determines how the input signal will be stretched or shrunk in time. There are two ways to use this argument depending upon the value given for <emphasis>itimemode</emphasis>. When the value of <emphasis>itimemode</emphasis> is 0, <emphasis>xtimewarp</emphasis> will scale the time of the sound. For example, a value of 2 will stretch the sound by 2 times. When <emphasis>itimemode</emphasis> is any non-zero value then <emphasis>xtimewarp</emphasis> is used as a time pointer in a similar way in which the time pointer works in <link linkend="lpread"><citetitle>lpread</citetitle></link> and <link linkend="pvoc"><citetitle>pvoc</citetitle></link>. An example below illustrates this. In both cases, the pitch will <emphasis>not</emphasis> be altered by this process. Pitch shifting is done independently using <emphasis>xresample</emphasis>. |
| 78 | </para> |
| 79 | |
| 80 | <para> |
| 81 | <emphasis>xresample</emphasis> -- the factor by which to change the pitch of the sound. For example, a value of 2 will produce a sound one octave higher than the original. The timing of the sound, however, will <emphasis>not</emphasis> be altered. |
| 82 | </para> |
| 83 | </refsect1> |
| 84 | |
| 85 | <refsect1> |
| 86 | <title>Example</title> |
| 87 | <para> |
| 88 | Here is an example of the sndwarpst opcode. It uses the file <ulink url="examples/sndwarpst.csd"><citetitle>sndwarpst.csd</citetitle></ulink>. |
| 89 | <example> |
| 90 | <title>Example of the sndwarpst opcode.</title> |
| 91 | <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> |
| 92 | <xi:include href="examples-xml/sndwarpst.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 93 | </example> |
| 94 | </para> |
| 95 | </refsect1> |
| 96 | |
| 97 | <refsect1> |
| 98 | <title>Other examples</title> |
| 99 | <para> |
| 100 | The below example shows a slowing down or stretching of the sound stored in the stored table (<emphasis>ifn1</emphasis>). Over the duration of the note, the stretching will grow from no change from the original to a sound which is ten times <quote>slower</quote> than the original. At the same time the overall pitch will move upward over the duration by an octave. |
| 101 | <informalexample> |
| 102 | <programlisting> |
| 103 | iwindfun <emphasis role="op">=</emphasis> 1 |
| 104 | isampfun <emphasis role="op">=</emphasis> 2 |
| 105 | ibeg <emphasis role="op">=</emphasis> 0 |
| 106 | iwindsize <emphasis role="op">=</emphasis> 2000 |
| 107 | iwindrand <emphasis role="op">=</emphasis> 400 |
| 108 | ioverlap <emphasis role="op">=</emphasis> 10 |
| 109 | awarp <emphasis role="opc">line</emphasis> 1, p3, 1 |
| 110 | aresamp <emphasis role="opc">line</emphasis> 1, p3, 2 |
| 111 | kenv <emphasis role="opc">line</emphasis> 1, p3, .1 |
| 112 | asig <emphasis role="opc">sndwarp</emphasis> kenv, awarp, aresamp, isampfun, ibeg, iwindsize, iwindrand, ioverlap, iwindfun, 0</programlisting> |
| 113 | </informalexample> |
| 114 | </para> |
| 115 | |
| 116 | <para> |
| 117 | Now, here is an example using <emphasis>xtimewarp</emphasis> as a time pointer and using stereo: |
| 118 | <informalexample> |
| 119 | <programlisting> |
| 120 | itimemode <emphasis role="op">=</emphasis> 1 |
| 121 | atime <emphasis role="opc">line</emphasis> 0, p3, 10 |
| 122 | ar1, ar2 <emphasis role="opc">sndwarpst</emphasis> kenv, atime, aresamp, sampfun, ibeg, iwindsize, iwindrand, ioverlap, \ |
| 123 | iwindfun, itimemode</programlisting> |
| 124 | </informalexample> |
| 125 | </para> |
| 126 | |
| 127 | <para> |
| 128 | In the above, <emphasis>atime</emphasis> advances the time pointer used in the <emphasis>sndwarpst</emphasis> from 0 to 10 over the duration of the note. If p3 is 20 then the sound will be two times slower than the original. Of course you can use a more complex function than just a single straight line to control the time factor. |
| 129 | </para> |
| 130 | |
| 131 | <para> |
| 132 | Now the same as above but using the <emphasis>balance</emphasis> function with the optional outputs: |
| 133 | <informalexample> |
| 134 | <programlisting> |
| 135 | asig,acmp <emphasis role="opc">sndwarp</emphasis> 1, awarp, aresamp, isampfun, ibeg, iwindsize, iwindrand, ioverlap, iwindfun, itimemode |
| 136 | abal <emphasis role="opc">balance</emphasis> asig, acmp |
| 137 | |
| 138 | asig1,asig2,acmp1,acmp2 <emphasis role="opc">sndwarpst</emphasis> 1, atime, aresamp, sampfun, ibeg, iwindsize, iwindrand, ioverlap, \ |
| 139 | iwindfun, itimemode |
| 140 | abal1 <emphasis role="opc">balance</emphasis> asig1, acmp1 |
| 141 | abal2 <emphasis role="opc">balance</emphasis> asig2, acmp2</programlisting> |
| 142 | </informalexample> |
| 143 | </para> |
| 144 | |
| 145 | <para> |
| 146 | In the above two examples notice the use of the <emphasis>balance</emphasis> unit. The output of <emphasis>balance</emphasis> can then be scaled, enveloped, sent to an <emphasis>out</emphasis> or <emphasis>outs</emphasis>, and so on. Notice that the amplitude arguments to <emphasis>sndwarp</emphasis> and <emphasis>sndwarpst</emphasis> are <quote>1</quote> in these examples. By scaling the signal after the <emphasis>sndwarp</emphasis> process, <emphasis>abal</emphasis>, <emphasis>abal1</emphasis>, and <emphasis>abal2</emphasis> should contain signals that have nearly the same amplitude as the original input signal to the <emphasis>sndwarp</emphasis> process. This makes it much easier to predict the levels and avoid samples out of range or sample values that are too small. |
| 147 | </para> |
| 148 | |
| 149 | <note> |
| 150 | <title>More Advice</title> |
| 151 | <para> |
| 152 | Only use the stereo version when you really need to be processing a stereo file. It is somewhat slower than the mono version and if you use the <emphasis>balance</emphasis> function it is slower again. There is nothing wrong with using a mono <emphasis>sndwarp</emphasis> in a stereo orchestra and sending the result to one or both channels of the stereo output! |
| 153 | </para> |
| 154 | </note> |
| 155 | </refsect1> |
| 156 | |
| 157 | <refsect1> |
| 158 | <title>See Also</title> |
| 159 | <para> |
| 160 | <link linkend="SiggenGranular"><citetitle>Granular Synthesis</citetitle></link> |
| 161 | </para> |
| 162 | </refsect1> |
| 163 | |
| 164 | <refsect1> |
| 165 | <title>Credits</title> |
| 166 | <para> |
| 167 | <simplelist> |
| 168 | <member>Author: Richard Karpen</member> |
| 169 | <member>Seattle, WA USA</member> |
| 170 | <member>1997</member> |
| 171 | </simplelist> |
| 172 | </para> |
| 173 | </refsect1> |
| 174 | </refentry> |