Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 5fcfcb7517038d1f44ab4e478e6e61fa > files > 254

csound-doc-6.10.0-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Realtime I/O on Linux</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <link rel="stylesheet" type="text/css" href="syntax-highlighting.css" />
    <meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="Using.html" title="Using Csound" />
    <link rel="prev" href="UsingRealTime.html" title="Real-Time Audio" />
    <link rel="next" href="RealTimeMac.html" title="Mac OSX" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Realtime I/O on Linux</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="UsingRealTime.html">Prev</a> </td>
          <th width="60%" align="center">Using Csound</th>
          <td width="20%" align="right"> <a accesskey="n" href="RealTimeMac.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="section">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="RealTimeLinux"></a>Realtime I/O on Linux</h2>
          </div>
        </div>
      </div>
      <p>
    Under Linux, the default portaudio/portmidi settings will result in
    higher latency than that which can be achieved using ALSA and/or
    JACK (see a separate manual section on this).
    The portaudio/portmidi plugins are audio and MIDI servers, which provide an
    interface to the ALSA drivers, in a manner which is in some respects
    similar but fundamentally different from that provided by JACK.
  </p>
      <h3><a id="idm281472964801112"></a>Using ALSA</h3>
      <p>
    The highest level of control and the lowest possible level of latency
    are to be achieved using the ALSA plugins in combination with the <a class="link" href="CommandFlagsCategory.html#IndexCatMinusSched"><em class="citetitle">--sched</em></a>
     flag. Using <a class="link" href="CommandFlagsCategory.html#IndexCatMinusSched"><em class="citetitle">--sched</em></a> requires that Csound be run as the root user, which may be impossible or undesirable in some
    circumstances.
  </p>
      <p>
    The ALSA plugins require the "name" of a "card" and a "device". Unless
    you have named your "cards" in ~/.asoundrc (or /etc/asound.conf), the
    "names" will actually be numbers. In order to obtain a list of the
    possible configurations, use the command line utilities "aplay",
    "arecord" and "amidi". These utilities are included with most Linux
    distros, or can be downloaded and built from source here:
  </p>
      <p>
        <a class="ulink" href="ftp://ftp.alsa-project.org/pub/utils/" target="_top">ftp://ftp.alsa-project.org/pub/utils/</a>
      </p>
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
        <table border="0" summary="Note">
          <tr>
            <td rowspan="2" align="center" valign="top" width="25">
              <img alt="[Note]" src="images/note.png" />
            </td>
            <th align="left">Note</th>
          </tr>
          <tr>
            <td align="left" valign="top">
    On every boot, the soundcard may have a different hardware order number, especially when there are more soundcards in the system. This can be awkward as every time you have to set the right number again. You can assign a fixed order by adding some lines to /etc/modprobe.d/alsa-base-conf, for example for a card with the ice1712 chip :
  <div class="literallayout"><p> <br />
    # ALSA module ordering for soundcard<br />
    options snd slots=snd_ice1712<br />
  </p></div></td>
          </tr>
        </table>
      </div>
      <h3><a id="idm281472964751768"></a>Audio Output</h3>
      <p>Running the following command:</p>
      <pre class="screen">
          aplay -l</pre>
      <p>will give you a list of the audio playback devices available on your
    system. Typically this list will look something like:
  </p>
      <div class="literallayout">
        <p>[....]<br />
**** List of PLAYBACK Hardware Devices ****<br />
card 0: A5451 [ALI 5451], device 0: ALI 5451 [ALI 5451]<br />
[....]<br />
</p>
      </div>
      <p>If you have more than one card on your system, or if there is more
        than one device on your card, the list will of course be more
        complicated, however in all cases the information that is pertinent is
        the number/name of the card/device. In order to use the above
        soundcard for audio output, the following flag would be added to the
        Csound command line, ~/.csoundrc, or the &lt;CsOptions&gt;section of a
        CSD:
    </p>
      <pre class="screen">
          -+rtaudio=alsa -o dac</pre>
      <h3><a id="idm281472964746712"></a>Output with dmix</h3>
      <p>
    If you would like to use Csound with dmix and your soundcard does not
    support hardware mixing of audio streams, special care is needed in setting
    up of software (-b) and hardware (-B) buffers.  If you get a message from
    Csound's ALSA driver that looks like the following:
  </p>
      <pre class="screen">
ALSA: -B 8192 not allowed on this device; use 7526 instead</pre>
      <p>
    there is a good chance that you may be using dmix.  If you are using dmix,
    the -b and -B settings of Csound must be synced the period_size and
    buffer_size of dmix respectively, using a ratio of the sr for the Csound
    project to the sample rate that dmix is set up to.  The following formula
    will determine what settings to use for Csound given the settings of dmix:
  </p>
      <pre class="screen">
-b = (csound_sr/dmix_sample_rate) * dmix_period_size
-B = (csound_sr/dmix_sample_rate)  * dmix_buffer_size</pre>
      <p>
    For example, if dmix is set to 48000 sample rate, a period_size of 1024,
    and a buffer_size of 8192, when running a Csound project with sr=48000,
    the settings for buffers should be "-b 1024 -B8192".  If the sr=24000,
    the settings for buffers should be "-b 512 -B4096".
  </p>
      <p>
    Because of this relationship, if a Csound project's sr does not evenly
    divide into the sample_rate used by dmix, then it may be difficult if not
    imposible to set the correct setting for -b and -B due to rounding errors.
    It is suggested then that if you are using sample rates different than
    what your setting is for dmix, then you may want to configure dmix to
    have a period_size and buffer_size that can be evenly divided by the ratio
    between the csound sr and dmix sample_rate.  For example, to run a project
    with sr=16000, the following dmix setting:
  </p>
      <pre class="screen">
pcm.amix {
   type dmix
   ipc_key 50557
   slave {
       pcm "hw:0,0"
       period_time 0
       #period_size 1024
       #buffer_size 8192
       period_size 1536
       buffer_size 12288
   }
   bindings {
       0 0
       1 1
   }
}

# route ALSA software through pcm.amix
pcm.!default {
   type plug
   slave.pcm "amix"
}</pre>
      <p>   with period_size 1536 and buffer_size 12288 will divide nicely by 3 
    (the ratio of the csound sr to the dmix sample_rate) to get "-b 512 -B4096" 
    ( (16000/48000) * 1536 = 512, (16000/48000) * 12288 = 4096 ).

  </p>
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
        <table border="0" summary="Note: Note">
          <tr>
            <td rowspan="2" align="center" valign="top" width="25">
              <img alt="[Note]" src="images/note.png" />
            </td>
            <th align="left">Note</th>
          </tr>
          <tr>
            <td align="left" valign="top">
              <p>
      For most soundcards that this affects, the default sample rate for the
      card will be 48000 and the defaults for dmix will be 1024 and 8192.
    </p>
            </td>
          </tr>
        </table>
      </div>
      <h3><a id="idm281472964738712"></a>Audio Input</h3>
      <p>
      Typically the same card will be used for both input and output, so to
      continue using the foregoing example, the flag:
    </p>
      <pre class="screen">
          -i adc:hw:0,0</pre>
      <p>would be added for audio input from Card 0 Device 0. To use the
      default card employ one of the following flags, with the forementioned
      warning that this will not necessarily work:
    </p>
      <pre class="screen">
          -i adc</pre>
      <p>If you wish to use a different card or device for input, running the
      following utility from the command line will provide a list of input
      devices:
    </p>
      <pre class="screen">
          arecord -l</pre>
      <p>If, by way of an example, you wanted to use a USB audio interface,
      which is the second "card" in your system, for output, but wanted to
      use your internal soundcard, the first card in your setup, for input,
      you would put the following flags somewhere useful:
    </p>
      <pre class="screen">
          -+rtaudio=alsa -i adc:hw:0,0 -o dac:hw:1,0</pre>
      <p>If you wanted to use the second device on your USB interface, to send
      audio to a specific channel, for instance, you would use the following
      flags:
    </p>
      <pre class="screen">
          -+rtaudio=alsa -i adc:hw:0,0 -o dac:hw:1,1</pre>
      <h3><a id="idm281472964731848"></a>MIDI</h3>
      <p>2 Midi drivers are available:
</p>
      <div class="itemizedlist">
        <ul class="itemizedlist" style="list-style-type: disc; ">
          <li class="listitem">Raw Midi.</li>
        </ul>
      </div>
      <p>
</p>
      <div class="itemizedlist">
        <ul class="itemizedlist" style="list-style-type: disc; ">
          <li class="listitem">Alsa Sequencer (since version 5.18).</li>
        </ul>
      </div>
      <p>
    </p>
      <h3><a id="idm281472964728616"></a>MIDI Input (Raw Midi driver)</h3>
      <p>In order to enable your orchestra to receive MIDI input you can use VirMIDI or MIDIThru, whichever you prefer. Setting up these
      virtual MIDI ports is a topic that has been covered extensively
      elsewhere, see 
      <a class="ulink" href="http://www.midi-howto.com/" target="_top">The Linux MIDI how-to</a> 
      or browse your distro's documentation or the ALSA documentation for
      instructions on how to install and configure either VirMIDI or
      MIDIThru (seqdummy). Once you have done so run:
    </p>
      <pre class="screen">
          amidi -l</pre>
      <p>for a list of available devices. Typically this will look something
      like the following:
    </p>
      <div class="literallayout">
        <p>    [....]<br />
Device    Name<br />
hw:1,0    Virtual Raw MIDI (16 subdevices)<br />
hw:1,1    Virtual Raw MIDI (16 subdevices)<br />
hw:1,2    Virtual Raw MIDI (16 subdevices)<br />
hw:1,3    Virtual Raw MIDI (16 subdevices)<br />
hw:2,0,0  PCR MIDI<br />
hw:2,0,1  PCR 1</p>
      </div>
      <p>In this example, Csound can connect to any of the four available
      Virtual Raw MIDI ports, where it will listen for MIDI input. The
      following flag instructs Csound to listen on the first of these ports:
    </p>
      <pre class="screen">
          -+rtmidi=alsa -Mhw:1,0</pre>
      <p>
      You will then need to connect your hardware or software controller to
      the port which is hosting your Csound synthesizer. The simplest way to do
      this is using the "aconnect" utility. Run:
    </p>
      <pre class="screen">
          aconnect -li</pre>
      <p>for a list of available input devices, and:</p>
      <pre class="screen">
          aconnect -lo</pre>
      <p>for a list of available output devices (including the port to which
      Csound has been connected). These should give something like the following:
    </p>
      <div class="literallayout">
        <p><br />
#aconnect -li<br />
client 0: 'System' [type=kernel]<br />
    0 'Timer           '<br />
    1 'Announce        '<br />
        Connecting To: 15:0<br />
client 20: 'Virtual Raw MIDI 1-0' [type=kernel]<br />
    0 'VirMIDI 1-0     '<br />
client 21: 'Virtual Raw MIDI 1-1' [type=kernel]<br />
    0 'VirMIDI 1-1     '<br />
client 22: 'Virtual Raw MIDI 1-2' [type=kernel]<br />
    0 'VirMIDI 1-2     '<br />
client 23: 'Virtual Raw MIDI 1-3' [type=kernel]<br />
    0 'VirMIDI 1-3     '<br />
client 24: 'PCR' [type=kernel]<br />
    0 'PCR MIDI        '<br />
    1 'PCR 1           '<br />
    2 'PCR 2           '</p>
      </div>
      <div class="literallayout">
        <p><br />
#aconnect -lo<br />
client 20: 'Virtual Raw MIDI 1-0' [type=kernel]<br />
    0 'VirMIDI 1-0     '<br />
client 21: 'Virtual Raw MIDI 1-1' [type=kernel]<br />
    0 'VirMIDI 1-1     '<br />
client 22: 'Virtual Raw MIDI 1-2' [type=kernel]<br />
    0 'VirMIDI 1-2     '<br />
client 23: 'Virtual Raw MIDI 1-3' [type=kernel]<br />
    0 'VirMIDI 1-3     '<br />
client 24: 'PCR' [type=kernel]<br />
    0 'PCR MIDI        '<br />
    1 'PCR 1           '</p>
      </div>
      <p>
      In the following example, the USB keyboard which is listed above as
      client 24 will be connected to a Csound synthesizer which is listening
      on the first VirMIDI port. The keyboard has three output ports. The
      first (24:0) transmits messages received on the MIDI in port, the
      second (24:1) transmits keyboard and controller messages, and the
      third (24:2) transmits system exclusive messages. The following
      command connects the second port of the keyboard to the Csound
      synthesizer:</p>
      <pre class="screen">
          aconnect 24:1 20:0</pre>
      <p>Remember that Csound acts as a raw MIDI device and is not an ALSA sequencer client. This means that Csound will not appear in MIDI device listings and will not be available for use directly with <span class="emphasis"><em>aconnect</em></span>, so you must connect to a virtual device (like 'virtual raw MIDI' or 'MIDI through') for persistent connections, or conect directly to the destination using command line flags.</p>
      <h3><a id="idm281472964714312"></a>MIDI Output (Raw Midi driver)</h3>
      <p>Csound can be connected to any device which shows up on the ALSA
      sequencer list of output ports, obtained by "amidi -l" as above. In
      order to connect a Csound synthesizer to the MIDI out port of the
      keyboard listed above, the following flag would be used:</p>
      <pre class="screen">
          -Qhw:2,0,0</pre>
      <h3><a id="idm281472964712520"></a>MIDI Input and Output (Midi Sequencer driver)</h3>
      <p>This driver is to be preferred over the Raw Midi driver. It has these advantages:
</p>
      <div class="itemizedlist">
        <ul class="itemizedlist" style="list-style-type: disc; ">
          <li class="listitem">Multiple concurrent access.</li>
          <li class="listitem">Scheduled by priority queues.</li>
          <li class="listitem">Real-time event dispatching i.e., the role of the Midi Sequencer is to deliver events at the right time (sequence) to the right destination (device).</li>
        </ul>
      </div>
      <p>
    </p>
      <p>The following command will call the Midi Sequencer. Here it listens to midi port 20. The midi output port is also 20:
    </p>
      <pre class="screen">
          -+rtmidi=alsaseq -M20 -Q20  </pre>
      <p>Csound will automatically create its own ALSA sequencer port. For a list of available devices, use the following command: </p>
      <pre class="screen">
          aconnect -i -o </pre>
      <p>This will create output that will look something
      like the following:
    </p>
      <div class="literallayout">
        <p>    client 0: 'System' [type=kernel]<br />
    0 'Timer           '<br />
    1 'Announce        '<br />
client 14: 'Midi Through' [type=kernel]<br />
    0 'Midi Through Port-0'<br />
client 20: 'M Audio Delta 1010' [type=kernel]<br />
    0 'M Audio Delta 1010 MIDI'<br />
client 130: 'Csound' [type=user]<br />
    0 'Csound </p>
      </div>
      <p>The output of Csound will contain lines like:</p>
      <div class="literallayout">
        <p><br />
...........<br />
ALSASEQ: opened MIDI output sequencer<br />
ALSASEQ: created output port 'Csound' 130:0<br />
ALSASEQ: connected to 20:0<br />
.............. <br />
...........<br />
ALSASEQ: opened MIDI input sequencer<br />
ALSASEQ: created input port 'Csound' 130:0<br />
ALSASEQ: connected from 20:0<br />
.............. <br />
    </p>
      </div>
      <h3><a id="idm281472964702760"></a>Scheduling</h3>
      <p>If you are able to run Csound as the root user, using the "--sched"
      flag will dramatically improve realtime performance, when using ALSA,
      however you may hang your system if you do something stupid. DO NOT
      use "--sched" if you are using JACK for audio output. JACK controls
      scheduling for the audio applications connected to it, and also tries
      to run at the highest possible priority. If the "--sched" flag is
      used, Csound and JACK will be competing rather than cooperating,
      resulting in extremely poor performance. </p>
      <h3><a id="idm281472964701384"></a>Using Pulseaudio</h3>
      <p>Support for <a class="ulink" href="http://www.pulseaudio.org/" target="_top">Pulseaudio</a> was added in Csound 5.09. You can specify the following settings:</p>
      <div class="orderedlist">
        <ol class="orderedlist" type="1">
          <li class="listitem">Sink names: it's possible to use a number instead of the full name, so
      -odac:1  would select your second device (count starts at 0).</li>
          <li class="listitem">Server name: it's possible to connect to a specific server by using
      -+server=&lt;server_string&gt;
        where server_string is a name of a server or a more
        complex server selection string (see <a class="ulink" href="http://www.pulseaudio.org/" target="_top">pulseaudio.org</a> on
        server strings). This should be network transparent and should allow connections to remote machines.</li>
          <li class="listitem">Stream names: it is possible to label the streams generated by csound, by
            using
            -+output_stream=&lt;stream-name&gt;
              and
              -+input_stream=&lt;stream-name&gt;</li>
        </ol>
      </div>
      <p>Here's an example command line:</p>
      <div class="literallayout">
        <p>csound -odac:1 examples/trapped.csd -+rtaudio=pulse -+server=unix:/tmp/pulse-victor/native -+output_stream=trapped</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="UsingRealTime.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="Using.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="RealTimeMac.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Real-Time Audio </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Mac OSX</td>
        </tr>
      </table>
    </div>
  </body>
</html>