| 1 | |
| 2 | <refentry id="sr"> |
| 3 | <indexterm id="IndexSr"><primary>sr</primary></indexterm> |
| 4 | <refentryinfo><title>Orchestra Syntax:Header</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>sr</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | |
| 10 | |
| 11 | <refnamediv> |
| 12 | <refname>sr</refname> |
| 13 | |
| 14 | <refpurpose> |
| 15 | Sets the audio sampling rate. |
| 16 | </refpurpose> |
| 17 | </refnamediv> |
| 18 | |
| 19 | <refsect1> |
| 20 | <title>Description</title> |
| 21 | <para> |
| 22 | These statements are global value <link |
| 23 | linkend="assign"><citetitle>assignments</citetitle></link>, made |
| 24 | at the beginning of an orchestra, before any instrument block is |
| 25 | defined. Their function is to set certain <link |
| 26 | linkend="VariableTypes"><citetitle>reserved symbol |
| 27 | variables</citetitle></link> that are required for |
| 28 | performance. Once set, these reserved symbols can be used in |
| 29 | expressions anywhere in the orchestra. |
| 30 | </para> |
| 31 | </refsect1> |
| 32 | |
| 33 | <refsect1> |
| 34 | <title>Syntax</title> |
| 35 | <synopsis><command>sr</command> = iarg</synopsis> |
| 36 | </refsect1> |
| 37 | |
| 38 | <refsect1> |
| 39 | <title>Initialization</title> |
| 40 | <para> |
| 41 | <emphasis>sr</emphasis> = (optional) -- set sampling rate to <emphasis>iarg</emphasis> samples per second per channel. The default value is 44100. |
| 42 | </para> |
| 43 | |
| 44 | <para> |
| 45 | In addition, any <link linkend="GlobalVariables"><citetitle>global variable</citetitle></link> can be initialized by an <emphasis>init-time assignment</emphasis> anywhere before the first <link linkend="instr"><citetitle>instr statement</citetitle></link>. All of the above assignments are run as instrument 0 (i-pass only) at the start of real performance. |
| 46 | </para> |
| 47 | |
| 48 | <para> |
| 49 | Beginning with Csound version 3.46, <emphasis>sr</emphasis> may |
| 50 | be omitted. The sample rate will be calculated from <link |
| 51 | linkend="kr"><citetitle>kr</citetitle></link> and <link |
| 52 | linkend="ksmps"><citetitle>ksmps</citetitle></link>, but this |
| 53 | must evaluate to an integer. If none of these global values is |
| 54 | defined, the sample rate will default to 44100. You will usually |
| 55 | want to use a value that your soundcard supports, like 44100 or |
| 56 | 48000, otherwise, the audio generated by csound may be |
| 57 | unplayable, or you will get an error if you attempt to run in |
| 58 | real-time. You may naturally use a sample rate like 96000, for |
| 59 | off-line rendering even if your soundcard does not support it. Csound will generate a valid file that can be played on capable systems. |
| 60 | </para> |
| 61 | </refsect1> |
| 62 | |
| 63 | <refsect1> |
| 64 | <title>Examples</title> |
| 65 | <para> |
| 66 | <informalexample> |
| 67 | <programlisting> |
| 68 | <emphasis role="ohdr">sr</emphasis> <emphasis role="op">=</emphasis> 10000 |
| 69 | <emphasis role="ohdr">kr</emphasis> <emphasis role="op">=</emphasis> 500 |
| 70 | <emphasis role="ohdr">ksmps</emphasis> <emphasis role="op">=</emphasis> 20 |
| 71 | gi1 <emphasis role="op">=</emphasis> <emphasis role="ohdr">sr</emphasis><emphasis role="op">/</emphasis>2. |
| 72 | ga <emphasis role="opc">init</emphasis> 0 |
| 73 | itranspose <emphasis role="op">=</emphasis> <emphasis role="opc">octpch</emphasis>(.0l)</programlisting> |
| 74 | </informalexample> |
| 75 | </para> |
| 76 | <para> |
| 77 | Here is another example of the sr opcode. It uses the file <ulink url="examples/sr.csd"><citetitle>sr.csd</citetitle></ulink>. |
| 78 | <example> |
| 79 | <title>Example of the sr opcode.</title> |
| 80 | <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> |
| 81 | <xi:include href="examples-xml/sr.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 82 | </example> |
| 83 | Its output should include lines like this: |
| 84 | <screen> |
| 85 | maximum number of harmonics = 240 |
| 86 | maximum number of harmonics = 24 |
| 87 | maximum number of harmonics = 2 |
| 88 | </screen> |
| 89 | </para> |
| 90 | </refsect1> |
| 91 | |
| 92 | <refsect1> |
| 93 | <title>See also</title> |
| 94 | <para><link linkend="OrchHeader"><citetitle>Orchestra Header Statements</citetitle></link></para> |
| 95 | </refsect1> |
| 96 | |
| 97 | </refentry> |