| 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>Saving list of floats to audio file on disk — 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="02-get-method.html" rel="next" title="Retrieving current value of a PyoObject as a python float"/> |
| 24 |
<link href="index.html" rel="prev" title="21-utilities"/> |
| 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="index.html" title="21-utilities">previous</a> | |
| 31 |
<a accesskey="N" href="02-get-method.html" title="Retrieving current value of a PyoObject as a python float">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> |
| 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"><a class="reference internal" href="../../winaudioinspect.html">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 class="current"> |
| 50 |
<li class="toctree-l1"><a class="reference internal" href="../../api/index.html">API documentation</a></li> |
| 51 |
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">Examples</a><ul class="current"> |
| 52 |
<li class="toctree-l2"><a class="reference internal" href="../01-intro/index.html">First steps</a></li> |
| 53 |
<li class="toctree-l2"><a class="reference internal" href="../02-controls/index.html">Parameter control</a></li> |
| 54 |
<li class="toctree-l2"><a class="reference internal" href="../03-generators/index.html">Synthesis generators</a></li> |
| 55 |
<li class="toctree-l2"><a class="reference internal" href="../04-soundfiles/index.html">Playing with soundfiles</a></li> |
| 56 |
<li class="toctree-l2"><a class="reference internal" href="../05-envelopes/index.html">Amplitude envelopes</a></li> |
| 57 |
<li class="toctree-l2"><a class="reference internal" href="../06-filters/index.html">Filtering</a></li> |
| 58 |
<li class="toctree-l2"><a class="reference internal" href="../07-effects/index.html">Creating sound effects</a></li> |
| 59 |
<li class="toctree-l2"><a class="reference internal" href="../08-dynamics/index.html">Dynamic range of audio signals</a></li> |
| 60 |
<li class="toctree-l2"><a class="reference internal" href="../09-callbacks/index.html">Calling python functions from audio objects</a></li> |
| 61 |
<li class="toctree-l2"><a class="reference internal" href="../10-tables/index.html">Using tables</a></li> |
| 62 |
<li class="toctree-l2"><a class="reference internal" href="../16-midi/index.html">How to use MIDI with pyo</a></li> |
| 63 |
<li class="toctree-l2"><a class="reference internal" href="../17-osc/index.html">How to use OSC with pyo</a></li> |
| 64 |
<li class="toctree-l2"><a class="reference internal" href="../19-multirate/index.html">Multirate audio processing</a></li> |
| 65 |
<li class="toctree-l2"><a class="reference internal" href="../20-multicore/index.html">Multicore audio programming</a></li> |
| 66 |
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Utilities</a></li> |
| 67 |
<li class="toctree-l2"><a class="reference internal" href="../22-events/index.html">Events framework</a></li> |
| 68 |
<li class="toctree-l2"><a class="reference internal" href="../23-expression/index.html">Evaluating prefix expression</a></li> |
| 69 |
</ul> |
| 70 |
</li> |
| 71 |
<li class="toctree-l1"><a class="reference internal" href="../../tutorials/index.html">Advanced tutorials</a></li> |
| 72 |
</ul> |
| 73 |
<div role="search"> |
| 74 |
<h3 style="margin-top: 1.5em;">Search</h3> |
| 75 |
<form action="../../search.html" class="search" method="get"> |
| 76 |
<input name="q" type="text"/> |
| 77 |
<input type="submit" value="Go"/> |
| 78 |
</form> |
| 79 |
</div> |
| 80 |
</div> |
| 81 |
<div class="document"> |
| 82 |
<div class="documentwrapper"> |
| 83 |
<div class="bodywrapper"> |
| 84 |
<div class="body" role="main"> |
| 85 |
<section id="saving-list-of-floats-to-audio-file-on-disk"> |
| 86 |
<h1>Saving list of floats to audio file on disk<a class="headerlink" href="#saving-list-of-floats-to-audio-file-on-disk" title="Permalink to this heading">¶</a></h1> |
| 87 |
<p><strong>01-list-to-audio-file.py</strong></p> |
| 88 |
<p>This program generates 5 seconds of white noise with pure python function |
| 89 |
and saves the samples in a file called noise.aif on the Desktop.</p> |
| 90 |
<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> <a class="sphinx-codeautolink-a" href="../../api/functions/sndfile.html#pyo.savefile" title="pyo.savefile"><span class="n">savefile</span></a> |
| 91 |
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">uniform</span> |
| 92 |
<span class="kn">import</span> <span class="nn">os</span> |
| 93 |
|
| 94 |
<span class="c1"># Create the path for the audio file.</span> |
| 95 |
<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="s2">"~"</span><span class="p">)</span> |
| 96 |
<span class="n">path</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="s2">"Desktop"</span><span class="p">,</span> <span class="s2">"noise.aif"</span><span class="p">)</span> |
| 97 |
|
| 98 |
<span class="c1"># Audio file properties (sampling rate, duration and number of channels).</span> |
| 99 |
<span class="n">sr</span> <span class="o">=</span> <span class="mi">44100</span> |
| 100 |
<span class="n">dur</span> <span class="o">=</span> <span class="mi">5</span> |
| 101 |
<span class="n">chnls</span> <span class="o">=</span> <span class="mi">2</span> |
| 102 |
|
| 103 |
<span class="c1"># Generate a list of `chnls` sub-lists with `sr * dur` floats in each of them.</span> |
| 104 |
<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> |
| 105 |
|
| 106 |
<span class="c1"># Save the list of floats in an audio file on disk.</span> |
| 107 |
<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> |
| 108 |
</pre></div> |
| 109 |
</div> |
| 110 |
</section> |
| 111 |
<div class="clearer"></div> |
| 112 |
</div> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
</div> |
| 116 |
<div class="clearer"></div> |
| 117 |
</div> |
| 118 |
</div> |
| 119 |
<div class="footer-wrapper"> |
| 120 |
<div class="footer"> |
| 121 |
<div class="left"> |
| 122 |
<div aria-label="related navigaton" role="navigation"> |
| 123 |
<a href="index.html" title="21-utilities">previous</a> | |
| 124 |
<a href="02-get-method.html" title="Retrieving current value of a PyoObject as a python float">next</a> | |
| 125 |
<a href="../../genindex.html" title="General Index">index</a> |
| 126 |
</div> |
| 127 |
<div aria-label="source link" role="note"> |
| 128 |
</div> |
| 129 |
</div> |
| 130 |
<div class="right"> |
| 131 |
<div class="footer" role="contentinfo"> |
| 132 |
© Copyright 2021, Olivier Bélanger. |
| 133 |
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0. |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
<div class="clearer"></div> |
| 137 |
</div> |
| 138 |
</div> |
| 139 |
</body> |
| 140 |
</html> |