File: sndfile.html

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (261 lines) | stat: -rw-r--r-- 20,289 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/><meta content="Docutils 0.17.1: http://docutils.sourceforge.net/" name="generator"/>
<title>Soundfile — Pyo 1.0.5 documentation</title>
<link href="../../_static/pygments.css" rel="stylesheet" type="text/css"/>
<link href="../../_static/agogo.css" rel="stylesheet" type="text/css"/>
<link href="../../_static/sphinx-codeautolink.css" rel="stylesheet" type="text/css"/>
<link href="../../_static/autoclasstoc.css" rel="stylesheet" type="text/css"/>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<link href="../../_static/E-PyoIcon.ico" rel="shortcut icon"/>
<link href="../../about.html" rel="author" title="About these documents"/>
<link href="../../genindex.html" rel="index" title="Index"/>
<link href="../../search.html" rel="search" title="Search"/>
<link href="sampling.html" rel="next" title="Resampling"/>
<link href="midi.html" rel="prev" title="Midi Setup"/>
</head><body>
<div class="header-wrapper" role="banner">
<div class="header">
<div class="headertitle"><a href="../../index.html">Pyo 1.0.5 documentation</a></div>
<div aria-label="related navigation" class="rel" role="navigation">
<a accesskey="P" href="midi.html" title="Midi Setup">previous</a> |
          <a accesskey="N" href="sampling.html" title="Resampling">next</a> |
          <a accesskey="I" href="../../genindex.html" title="General Index">index</a>
</div>
</div>
</div>
<div class="content-wrapper">
<div class="content">
<div class="sidebar">
<h3>Table of Contents</h3>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../about.html">About pyo</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../download.html">Installing pyo with pip</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../compiling.html">Compiling pyo from sources</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../structure.html">Structure of the library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../gettingstarted.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../winaudioinspect.html">Configuring the audio output (Windows)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../perftips.html">Improve performance of pyo programs</a></li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">API documentation</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../constants.html">Constants</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../alphabetical.html">Alphabetical class reference</a></li>
<li class="toctree-l2"><a class="reference internal" href="../classes/index.html">Classes by category</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/index.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tutorials/index.html">Advanced tutorials</a></li>
</ul>
<div role="search">
<h3 style="margin-top: 1.5em;">Search</h3>
<form action="../../search.html" class="search" method="get">
<input name="q" type="text"/>
<input type="submit" value="Go"/>
</form>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="soundfile">
<h1>Soundfile<a class="headerlink" href="#soundfile" title="Permalink to this heading">¶</a></h1>
<p>Functions to inspect or write an audio file on disk.</p>
<section id="functions-in-this-category">
<h2>Functions in this category<a class="headerlink" href="#functions-in-this-category" title="Permalink to this heading">¶</a></h2>
<ul class="simple">
<li><p><a class="reference internal" href="#pyo.sndinfo" title="pyo.sndinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">sndinfo()</span></code></a> :     Retrieve informations about a soundfile.</p></li>
<li><p><a class="reference internal" href="#pyo.savefile" title="pyo.savefile"><code class="xref py py-func docutils literal notranslate"><span class="pre">savefile()</span></code></a> :     Creates an audio file from a list of floats.</p></li>
<li><p><a class="reference internal" href="#pyo.savefileFromTable" title="pyo.savefileFromTable"><code class="xref py py-func docutils literal notranslate"><span class="pre">savefileFromTable()</span></code></a> :     Creates an audio file from the content of a table.</p></li>
</ul>
</section>
<section id="sndinfo">
<h2><em>sndinfo</em><a class="headerlink" href="#sndinfo" title="Permalink to this heading">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="pyo.sndinfo">
<span class="sig-name descname"><span class="pre">sndinfo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">print</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pyo/lib/_core.html#sndinfo"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pyo.sndinfo" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve informations about a soundfile.</p>
<p>Prints the infos of the given soundfile to the console and returns a
tuple containing:</p>
<dl class="simple">
<dt>(number of frames, duration in seconds, sampling rate,</dt><dd><p>number of channels, file format, sample type)</p>
</dd>
</dl>
<dl class="field-list simple">
<dt class="field-odd">Args</dt>
<dd class="field-odd"><dl class="simple">
<dt>path: string</dt><dd><p>Path of a valid soundfile.</p>
</dd>
<dt>print: boolean, optional</dt><dd><p>If True, sndinfo will print sound infos to the console.
Defaults to False.</p>
</dd>
<dt>raise_on_failure: boolean, optional</dt><dd><p>If True, sndinfo will raise an exception when failing to get file info.
Defaults to False.</p>
</dd>
</dl>
</dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">path</span> <span class="o">=</span> <span class="n">SNDS_PATH</span> <span class="o">+</span> <span class="s1">'/transparent.aif'</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="go">/home/olivier/.local/lib/python3.9/site-packages/pyo/lib/snds/transparent.aif</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">info</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/functions/sndfile.html#pyo.sndinfo" title="pyo.sndinfo"><span class="n">sndinfo</span></a><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">info</span><span class="p">)</span>
<span class="go">(29877, 0.6774829931972789, 44100.0, 1, 'AIFF', '16 bit int')</span>
</pre></div>
</div>
</dd></dl>
</section>
<section id="savefile">
<h2><em>savefile</em><a class="headerlink" href="#savefile" title="Permalink to this heading">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="pyo.savefile">
<span class="sig-name descname"><span class="pre">savefile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">samples</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">44100</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">channels</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fileformat</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sampletype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quality</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.4</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pyo/lib/_core.html#savefile"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pyo.savefile" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an audio file from a list of floats.</p>
<dl class="field-list simple">
<dt class="field-odd">Args</dt>
<dd class="field-odd"><dl class="simple">
<dt>samples: list of floats</dt><dd><p>List of samples data, or list of list of samples data if more than 1 channels.</p>
</dd>
<dt>path: string</dt><dd><p>Full path (including extension) of the new file.</p>
</dd>
<dt>sr: int, optional</dt><dd><p>Sampling rate of the new file. Defaults to 44100.</p>
</dd>
<dt>channels: int, optional</dt><dd><p>Number of channels of the new file. Defaults to 1.</p>
</dd>
<dt>fileformat: int, optional</dt><dd><p>Format type of the new file. Defaults to 0. Supported formats are:</p>
<ol class="arabic simple" start="0">
<li><p>WAVE - Microsoft WAV format (little endian) {.wav, .wave}</p></li>
<li><p>AIFF - Apple/SGI AIFF format (big endian) {.aif, .aiff}</p></li>
<li><p>AU - Sun/NeXT AU format (big endian) {.au}</p></li>
<li><p>RAW - RAW PCM data {no extension}</p></li>
<li><p>SD2 - Sound Designer 2 {.sd2}</p></li>
<li><p>FLAC - FLAC lossless file format {.flac}</p></li>
<li><p>CAF - Core Audio File format {.caf}</p></li>
<li><p>OGG - Xiph OGG container {.ogg}</p></li>
</ol>
</dd>
<dt>sampletype ; int, optional</dt><dd><p>Bit depth encoding of the audio file. Defaults to 0.
SD2 and FLAC only support 16 or 24 bit int. Supported types are:</p>
<ol class="arabic simple" start="0">
<li><p>16 bit int</p></li>
<li><p>24 bit int</p></li>
<li><p>32 bit int</p></li>
<li><p>32 bit float</p></li>
<li><p>64 bit float</p></li>
<li><p>U-Law encoded</p></li>
<li><p>A-Law encoded</p></li>
</ol>
</dd>
<dt>quality: float, optional</dt><dd><p>The encoding quality value, between 0.0 (lowest quality) and
1.0 (highest quality). This argument has an effect only with
FLAC and OGG compressed formats. Defaults to 0.4.</p>
</dd>
</dl>
</dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">uniform</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">home</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s1">'~'</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sr</span><span class="p">,</span> <span class="n">dur</span><span class="p">,</span> <span class="n">chnls</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="mi">44100</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">home</span><span class="p">,</span> <span class="s1">'noise.aif'</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">samples</span> <span class="o">=</span> <span class="p">[[</span><span class="n">uniform</span><span class="p">(</span><span class="o">-</span><span class="mf">0.5</span><span class="p">,</span><span class="mf">0.5</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">sr</span><span class="o">*</span><span class="n">dur</span><span class="p">)]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">chnls</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><a class="sphinx-codeautolink-a" href="../../api/functions/sndfile.html#pyo.savefile" title="pyo.savefile"><span class="n">savefile</span></a><span class="p">(</span><span class="n">samples</span><span class="o">=</span><span class="n">samples</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">,</span> <span class="n">sr</span><span class="o">=</span><span class="n">sr</span><span class="p">,</span> <span class="n">channels</span><span class="o">=</span><span class="n">chnls</span><span class="p">,</span> <span class="n">fileformat</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">sampletype</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
</section>
<section id="savefilefromtable">
<h2><em>savefileFromTable</em><a class="headerlink" href="#savefilefromtable" title="Permalink to this heading">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="pyo.savefileFromTable">
<span class="sig-name descname"><span class="pre">savefileFromTable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">table</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fileformat</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sampletype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quality</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.4</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/pyo/lib/_core.html#savefileFromTable"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pyo.savefileFromTable" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an audio file from the content of a table.</p>
<dl class="field-list simple">
<dt class="field-odd">Args</dt>
<dd class="field-odd"><dl class="simple">
<dt>table: PyoTableObject</dt><dd><p>Table from which to retrieve the samples to write.</p>
</dd>
<dt>path: string</dt><dd><p>Full path (including extension) of the new file.</p>
</dd>
<dt>fileformat: int, optional</dt><dd><p>Format type of the new file. Defaults to 0. Supported formats are:</p>
<ol class="arabic simple" start="0">
<li><p>WAVE - Microsoft WAV format (little endian) {.wav, .wave}</p></li>
<li><p>AIFF - Apple/SGI AIFF format (big endian) {.aif, .aiff}</p></li>
<li><p>AU - Sun/NeXT AU format (big endian) {.au}</p></li>
<li><p>RAW - RAW PCM data {no extension}</p></li>
<li><p>SD2 - Sound Designer 2 {.sd2}</p></li>
<li><p>FLAC - FLAC lossless file format {.flac}</p></li>
<li><p>CAF - Core Audio File format {.caf}</p></li>
<li><p>OGG - Xiph OGG container {.ogg}</p></li>
</ol>
</dd>
<dt>sampletype ; int, optional</dt><dd><p>Bit depth encoding of the audio file. Defaults to 0.
SD2 and FLAC only support 16 or 24 bit int. Supported types are:</p>
<ol class="arabic simple" start="0">
<li><p>16 bit int</p></li>
<li><p>24 bit int</p></li>
<li><p>32 bit int</p></li>
<li><p>32 bit float</p></li>
<li><p>64 bit float</p></li>
<li><p>U-Law encoded</p></li>
<li><p>A-Law encoded</p></li>
</ol>
</dd>
<dt>quality: float, optional</dt><dd><p>The encoding quality value, between 0.0 (lowest quality) and
1.0 (highest quality). This argument has an effect only with
FLAC and OGG compressed formats. Defaults to 0.4.</p>
</dd>
</dl>
</dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">home</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s1">'~'</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">path1</span> <span class="o">=</span> <span class="n">SNDS_PATH</span> <span class="o">+</span> <span class="s1">'/transparent.aif'</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">path2</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">home</span><span class="p">,</span> <span class="s1">'/transparent2.aif'</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><a class="sphinx-codeautolink-a" href="../../api/classes/tables.html#pyo.SndTable" title="pyo.lib.tables.SndTable"><span class="n">t</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="../../api/classes/tables.html#pyo.SndTable" title="pyo.lib.tables.SndTable"><span class="n">SndTable</span></a><span class="p">(</span><span class="n">path1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><a class="sphinx-codeautolink-a" href="../../api/functions/sndfile.html#pyo.savefileFromTable" title="pyo.savefileFromTable"><span class="n">savefileFromTable</span></a><span class="p">(</span><span class="n">table</span><span class="o">=</span><a class="sphinx-codeautolink-a" href="../../api/classes/tables.html#pyo.SndTable" title="pyo.lib.tables.SndTable"><span class="n">t</span></a><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">,</span> <span class="n">fileformat</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">sampletype</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
<div class="footer-wrapper">
<div class="footer">
<div class="left">
<div aria-label="related navigaton" role="navigation">
<a href="midi.html" title="Midi Setup">previous</a> |
            <a href="sampling.html" title="Resampling">next</a> |
            <a href="../../genindex.html" title="General Index">index</a>
</div>
<div aria-label="source link" role="note">
</div>
</div>
<div class="right">
<div class="footer" role="contentinfo">
        © Copyright 2021, Olivier Bélanger.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
    </div>
</div>
<div class="clearer"></div>
</div>
</div>
</body>
</html>