Debian Codegraph @

docs/winaudioinspect.html

raw
1
2 <!DOCTYPE html>
3
4 <html lang="en">
5 <head>
6 <meta charset="utf-8"/>
7 <meta content="width=device-width, initial-scale=1.0" name="viewport"/><meta content="Docutils 0.17.1: http://docutils.sourceforge.net/" name="generator"/>
8 <title>Configuring the audio output (Windows) — Pyo 1.0.5 documentation</title>
9 <link href="_static/pygments.css" rel="stylesheet" type="text/css"/>
10 <link href="_static/agogo.css" rel="stylesheet" type="text/css"/>
11 <link href="_static/sphinx-codeautolink.css" rel="stylesheet" type="text/css"/>
12 <link href="_static/autoclasstoc.css" rel="stylesheet" type="text/css"/>
13 <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
14 <script src="_static/jquery.js"></script>
15 <script src="_static/underscore.js"></script>
16 <script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
17 <script src="_static/doctools.js"></script>
18 <script src="_static/sphinx_highlight.js"></script>
19 <link href="_static/E-PyoIcon.ico" rel="shortcut icon"/>
20 <link href="about.html" rel="author" title="About these documents"/>
21 <link href="genindex.html" rel="index" title="Index"/>
22 <link href="search.html" rel="search" title="Search"/>
23 <link href="perftips.html" rel="next" title="Improve performance of pyo programs"/>
24 <link href="gettingstarted.html" rel="prev" title="Getting started"/>
25 </head><body>
26 <div class="header-wrapper" role="banner">
27 <div class="header">
28 <div class="headertitle"><a href="index.html">Pyo 1.0.5 documentation</a></div>
29 <div aria-label="related navigation" class="rel" role="navigation">
30 <a accesskey="P" href="gettingstarted.html" title="Getting started">previous</a> |
31 <a accesskey="N" href="perftips.html" title="Improve performance of pyo programs">next</a> |
32 <a accesskey="I" href="genindex.html" title="General Index">index</a>
33 </div>
34 </div>
35 </div>
36 <div class="content-wrapper">
37 <div class="content">
38 <div class="sidebar">
39 <h3>Table of Contents</h3>
40 <ul class="current">
41 <li class="toctree-l1"><a class="reference internal" href="about.html">About pyo</a></li>
42 <li class="toctree-l1"><a class="reference internal" href="download.html">Installing pyo with pip</a></li>
43 <li class="toctree-l1"><a class="reference internal" href="compiling.html">Compiling pyo from sources</a></li>
44 <li class="toctree-l1"><a class="reference internal" href="structure.html">Structure of the library</a></li>
45 <li class="toctree-l1"><a class="reference internal" href="gettingstarted.html">Getting started</a></li>
46 <li class="toctree-l1 current"><a class="current reference internal" href="#">Configuring the audio output (Windows)</a></li>
47 <li class="toctree-l1"><a class="reference internal" href="perftips.html">Improve performance of pyo programs</a></li>
48 </ul>
49 <ul>
50 <li class="toctree-l1"><a class="reference internal" href="api/index.html">API documentation</a></li>
51 <li class="toctree-l1"><a class="reference internal" href="examples/index.html">Examples</a></li>
52 <li class="toctree-l1"><a class="reference internal" href="tutorials/index.html">Advanced tutorials</a></li>
53 </ul>
54 <div role="search">
55 <h3 style="margin-top: 1.5em;">Search</h3>
56 <form action="search.html" class="search" method="get">
57 <input name="q" type="text"/>
58 <input type="submit" value="Go"/>
59 </form>
60 </div>
61 </div>
62 <div class="document">
63 <div class="documentwrapper">
64 <div class="bodywrapper">
65 <div class="body" role="main">
66 <section id="configuring-the-audio-output-windows">
67 <h1>Configuring the audio output (Windows)<a class="headerlink" href="#configuring-the-audio-output-windows" title="Permalink to this heading">¶</a></h1>
68 <p>Here is some tips to help you to configure the audio input/output on Windows.
69 Some of these procedures are also valid for other systems.</p>
70 <section id="how-to-choose-the-audio-host-api-on-windows">
71 <h2>How to choose the audio host api on Windows<a class="headerlink" href="#how-to-choose-the-audio-host-api-on-windows" title="Permalink to this heading">¶</a></h2>
72 <p>Choosing the good audio API on Windows can turn out to be a real headache.</p>
73 <p>This document presents a script that will inspect your system and tell you if:</p>
74 <ul class="simple">
75 <li><p>Pyo can run in duplex mode. That means both audio input and output instead of output only.</p></li>
76 <li><p>Pyo is able to connect to the different host APIs that are usually available on Windows.</p></li>
77 </ul>
78 <p>In the hope that this will help you having a good experience with pyo under Windows!</p>
79 <p><a class="reference external" href="https://github.com/belangeo/pyo/tree/master/scripts/win_audio_drivers_inspector.py">https://github.com/belangeo/pyo/tree/master/scripts/win_audio_drivers_inspector.py</a></p>
80 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="sd">"""</span>
81 <span class="sd">Windows audio host inspector.</span>
82
83 <span class="sd">This script will check if pyo can run in duplex mode (both audio input and output)</span>
84 <span class="sd">and will test every host API to help the user in making his audio device choice.</span>
85
86 <span class="sd">"""</span>
87 <span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">time</span>
88 <span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
89
90 <span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span> <span class="o">==</span> <span class="s2">"win32"</span><span class="p">:</span>
91 <span class="n">host_apis</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"mme"</span><span class="p">,</span> <span class="s2">"directsound"</span><span class="p">,</span> <span class="s2">"asio"</span><span class="p">,</span> <span class="s2">"wasapi"</span><span class="p">,</span> <span class="s2">"wdm-ks"</span><span class="p">]</span>
92 <span class="k">else</span><span class="p">:</span>
93 <span class="nb">print</span><span class="p">(</span><span class="s2">"This program must be used on a windows system! Ciao!"</span><span class="p">)</span>
94 <span class="n">exit</span><span class="p">()</span>
95
96
97 <span class="nb">print</span><span class="p">(</span><span class="s2">"* Checking for any available audio input... *"</span><span class="p">)</span>
98
99 <span class="n">input_names</span><span class="p">,</span> <span class="n">input_indexes</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/functions/audio.html#pyo.pa_get_input_devices" title="pyo.pa_get_input_devices"><span class="n">pa_get_input_devices</span></a><span class="p">()</span>
100
101 <span class="nb">print</span><span class="p">(</span><span class="s2">"* Checking audio output hosts... *"</span><span class="p">)</span>
102
103 <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">s</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">(</span><span class="n">duplex</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
104 <span class="n">s</span><span class="o">.</span><span class="n">verbosity</span> <span class="o">=</span> <span class="mi">0</span>
105
106 <span class="n">host_results</span> <span class="o">=</span> <span class="p">[]</span>
107 <span class="k">for</span> <span class="n">host</span> <span class="ow">in</span> <span class="n">host_apis</span><span class="p">:</span>
108 <span class="nb">print</span><span class="p">(</span><span class="s2">"* Testing </span><span class="si">%s</span><span class="s2">... *"</span> <span class="o">%</span> <span class="n">host</span><span class="p">)</span>
109 <span class="k">try</span><span class="p">:</span>
110 <span class="n">s</span><span class="o">.</span><span class="n">reinit</span><span class="p">(</span><span class="n">buffersize</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span> <span class="n">duplex</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">winhost</span><span class="o">=</span><span class="n">host</span><span class="p">)</span>
111 <span class="n">s</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
112 <span class="n">a</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="n">freq</span><span class="o">=</span><span class="mi">440</span><span class="p">,</span> <span class="n">mul</span><span class="o">=</span><span class="mf">0.2</span><span class="p">)</span><span class="o">.</span><span class="n">out</span><span class="p">()</span>
113 <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
114 <span class="n">s</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
115 <span class="n">s</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>
116 <span class="n">host_results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
117 <span class="k">except</span><span class="p">:</span>
118 <span class="n">host_results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
119
120 <span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Results"</span><span class="p">)</span>
121 <span class="nb">print</span><span class="p">(</span><span class="s2">"-------</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
122
123 <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">input_names</span><span class="p">):</span>
124 <span class="nb">print</span><span class="p">(</span><span class="s2">"Duplex mode OK!"</span><span class="p">)</span>
125 <span class="nb">print</span><span class="p">(</span><span class="s2">"Initialize the Server with duplex=1 as argument.</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
126 <span class="k">else</span><span class="p">:</span>
127 <span class="nb">print</span><span class="p">(</span><span class="s2">"No input available. Duplex mode should be turned off."</span><span class="p">)</span>
128 <span class="nb">print</span><span class="p">(</span><span class="s2">"Initialize the Server with duplex=0 as argument.</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
129
130 <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">host</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">host_apis</span><span class="p">):</span>
131 <span class="k">if</span> <span class="n">host_results</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
132 <span class="nb">print</span><span class="p">(</span><span class="s2">"Host: </span><span class="si">%s</span><span class="s2"> ==&gt; OK!"</span> <span class="o">%</span> <span class="n">host</span><span class="p">)</span>
133 <span class="k">else</span><span class="p">:</span>
134 <span class="nb">print</span><span class="p">(</span><span class="s2">"Host: </span><span class="si">%s</span><span class="s2"> ==&gt; Failed..."</span> <span class="o">%</span> <span class="n">host</span><span class="p">)</span>
135
136 <span class="nb">print</span><span class="p">(</span><span class="s2">"Initialize the Server with the desired host given to winhost argument."</span><span class="p">)</span>
137
138 <span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Finished!"</span><span class="p">)</span>
139 </pre></div>
140 </div>
141 </section>
142 <section id="tunning-the-windows-wasapi-driver">
143 <h2>Tunning the Windows WASAPI driver<a class="headerlink" href="#tunning-the-windows-wasapi-driver" title="Permalink to this heading">¶</a></h2>
144 <p>The Windows Audio Session API (WASAPI) is Microsoft’s most modern method for talking with audio devices.
145 It is available in Windows since Vista. Pyo’s default host is DIRECTSOUND but you can change it to WASAPI
146 by changing the <cite>winhost</cite> argument of the <strong>Server</strong> object. If the script above tells you:</p>
147 <blockquote>
148 <div><p>Host: wasapi ==&gt; Failed…</p>
149 </div></blockquote>
150 <p>there is some things you can do to make it work. Open the <strong>Sound</strong> window by double-clicking on the volume
151 icon and choosing <em>Playback Devices</em>. Here, select your device and click on the <em>Properties</em> button. In
152 the <em>advanced</em> tab, make sure that the sampling rate is the same that the one used by pyo (pyo defaults to
153 44100 Hz). You can check the exclusive mode box if you want, this will bypass the system mixer, default
154 settings, and typically any effects provided by the audio driver.</p>
155 <p>Perform the same in the <em>recording</em> tab if you want to run pyo in duplex mode. If you got the message:</p>
156 <blockquote>
157 <div><p>No input available. Duplex mode should be turned off.</p>
158 </div></blockquote>
159 <p>you’ll have to make sure first that there is an available input device in that tab.</p>
160 <p>If you use a cheap soundcard (typically, any built in soundcard is not very good!), you may have to increase
161 the buffer size of the pyo’s Server in order to avoid glitches in the audio streams.</p>
162 </section>
163 <section id="server-initialization-examples">
164 <h2>Server initialization examples<a class="headerlink" href="#server-initialization-examples" title="Permalink to this heading">¶</a></h2>
165 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># sampling rate = 44100 Hz, buffer size = 256, channels = 2, full duplex, host = DIRECTSOUND</span>
166 <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">s</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">()</span>
167
168 <span class="c1"># sampling rate = 48000 Hz, buffer size = 1024, channels = 2, full duplex, host = DIRECTSOUND</span>
169 <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">s</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">(</span><span class="n">sr</span><span class="o">=</span><span class="mi">48000</span><span class="p">,</span> <span class="n">buffersize</span><span class="o">=</span><span class="mi">1024</span><span class="p">)</span>
170
171 <span class="c1"># sampling rate = 48000 Hz, buffer size = 512, channels = 2, full duplex, host = WASAPI</span>
172 <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">s</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">(</span><span class="n">sr</span><span class="o">=</span><span class="mi">48000</span><span class="p">,</span> <span class="n">buffersize</span><span class="o">=</span><span class="mi">512</span><span class="p">,</span> <span class="n">winhost</span><span class="o">=</span><span class="s2">"wasapi"</span><span class="p">)</span>
173
174 <span class="c1"># sampling rate = 48000 Hz, buffer size = 512, channels = 2, output only, host = ASIO</span>
175 <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">s</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">(</span><span class="n">sr</span><span class="o">=</span><span class="mi">48000</span><span class="p">,</span> <span class="n">buffersize</span><span class="o">=</span><span class="mi">512</span><span class="p">,</span> <span class="n">duplex</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">winhost</span><span class="o">=</span><span class="s2">"asio"</span><span class="p">)</span>
176
177 <span class="c1"># sampling rate = 96000 Hz, buffer size = 128, channels = 1, full duplex, host = ASIO</span>
178 <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">s</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">(</span><span class="n">sr</span><span class="o">=</span><span class="mi">96000</span><span class="p">,</span> <span class="n">nchnls</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">buffersize</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span> <span class="n">duplex</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">winhost</span><span class="o">=</span><span class="s2">"asio"</span><span class="p">)</span>
179 </pre></div>
180 </div>
181 </section>
182 <section id="choosing-a-specific-device">
183 <h2>Choosing a specific device<a class="headerlink" href="#choosing-a-specific-device" title="Permalink to this heading">¶</a></h2>
184 <p>A single host API can target more than one available devices.</p>
185 <p>There is some useful functions that can help you in the choice of the audio device:</p>
186 <ul class="simple">
187 <li><p><strong>pa_list_host_apis()</strong>: Prints the list of audio host APIs.</p></li>
188 <li><p><strong>pa_list_devices()</strong>: Prints the list of audio devices. The first column if the index of the device.</p></li>
189 <li><p><strong>pa_get_default_input()</strong>: Returns the index of the default input device.</p></li>
190 <li><p><strong>pa_get_default_output()</strong>: Returns the index of the default output device.</p></li>
191 <li><p><strong>pa_get_default_devices_from_host(host)</strong>: Returns the default input and output devices for a given audio host.</p></li>
192 </ul>
193 <p>Run this code to see the current state of your audio setup:</p>
194 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
195
196 <span class="nb">print</span><span class="p">(</span><span class="s2">"Audio host APIS:"</span><span class="p">)</span>
197 <a class="sphinx-codeautolink-a" href="api/functions/audio.html#pyo.pa_list_host_apis" title="pyo.pa_list_host_apis"><span class="n">pa_list_host_apis</span></a><span class="p">()</span>
198 <a class="sphinx-codeautolink-a" href="api/functions/audio.html#pyo.pa_list_devices" title="pyo.pa_list_devices"><span class="n">pa_list_devices</span></a><span class="p">()</span>
199 <span class="nb">print</span><span class="p">(</span><span class="s2">"Default input device: </span><span class="si">%i</span><span class="s2">"</span> <span class="o">%</span> <a class="sphinx-codeautolink-a" href="api/functions/audio.html#pyo.pa_get_default_input" title="pyo.pa_get_default_input"><span class="n">pa_get_default_input</span></a><span class="p">())</span>
200 <span class="nb">print</span><span class="p">(</span><span class="s2">"Default output device: </span><span class="si">%i</span><span class="s2">"</span> <span class="o">%</span> <a class="sphinx-codeautolink-a" href="api/functions/audio.html#pyo.pa_get_default_output" title="pyo.pa_get_default_output"><span class="n">pa_get_default_output</span></a><span class="p">())</span>
201 </pre></div>
202 </div>
203 <p>If the default device for the desired host is not the one you want, you can tell the Server
204 which device you want to use with the <em>setInputDevice(x)</em> and <em>setOutputDevice(x)</em> methods. These
205 methods take the index of the desired device and must be called before booting the Server. Ex:</p>
206 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
207
208 <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">s</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">(</span><span class="n">duplex</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
209 <span class="n">s</span><span class="o">.</span><span class="n">setOutputDevice</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
210 <span class="n">s</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span>
211 </pre></div>
212 </div>
213 </section>
214 </section>
215 <div class="clearer"></div>
216 </div>
217 </div>
218 </div>
219 </div>
220 <div class="clearer"></div>
221 </div>
222 </div>
223 <div class="footer-wrapper">
224 <div class="footer">
225 <div class="left">
226 <div aria-label="related navigaton" role="navigation">
227 <a href="gettingstarted.html" title="Getting started">previous</a> |
228 <a href="perftips.html" title="Improve performance of pyo programs">next</a> |
229 <a href="genindex.html" title="General Index">index</a>
230 </div>
231 <div aria-label="source link" role="note">
232 </div>
233 </div>
234 <div class="right">
235 <div class="footer" role="contentinfo">
236 © Copyright 2021, Olivier Bélanger.
237 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
238 </div>
239 </div>
240 <div class="clearer"></div>
241 </div>
242 </div>
243 </body>
244 </html>