File: Audio-Processing.html

package info (click to toggle)
octave3.2 3.2.4-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 62,936 kB
  • ctags: 37,353
  • sloc: cpp: 219,497; fortran: 116,336; ansic: 10,264; sh: 5,508; makefile: 4,245; lex: 3,573; yacc: 3,062; objc: 2,042; lisp: 1,692; awk: 860; perl: 844
file content (242 lines) | stat: -rw-r--r-- 14,794 bytes parent folder | download
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
<html lang="en">
<head>
<title>Audio Processing - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="Image-Processing.html#Image-Processing" title="Image Processing">
<link rel="next" href="Object-Oriented-Programming.html#Object-Oriented-Programming" title="Object Oriented Programming">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Audio-Processing"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="Object-Oriented-Programming.html#Object-Oriented-Programming">Object Oriented Programming</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Image-Processing.html#Image-Processing">Image Processing</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>

<h2 class="chapter">32 Audio Processing</h2>

<p>Octave provides a few functions for dealing with audio data.  An audio
`sample' is a single output value from an A/D converter, i.e., a small
integer number (usually 8 or 16 bits), and audio data is just a series
of such samples.  It can be characterized by three parameters:  the
sampling rate (measured in samples per second or Hz, e.g., 8000 or
44100), the number of bits per sample (e.g., 8 or 16), and the number of
channels (1 for mono, 2 for stereo, etc.).

   <p>There are many different formats for representing such data.  Currently,
only the two most popular, <em>linear encoding</em> and <em>mu-law
encoding</em>, are supported by Octave.  There is an excellent FAQ on audio
formats by Guido van Rossum &lt;guido@cwi.nl&gt; which can be found at any
FAQ ftp site, in particular in the directory
<samp><span class="file">/pub/usenet/news.answers/audio-fmts</span></samp> of the archive site
<code>rtfm.mit.edu</code>.

   <p>Octave simply treats audio data as vectors of samples (non-mono data are
not supported yet).  It is assumed that audio files using linear
encoding have one of the extensions <samp><span class="file">lin</span></samp> or <samp><span class="file">raw</span></samp>, and that
files holding data in mu-law encoding end in <samp><span class="file">au</span></samp>, <samp><span class="file">mu</span></samp>, or
<samp><span class="file">snd</span></samp>.

<!-- ./audio/lin2mu.m -->
   <p><a name="doc_002dlin2mu"></a>

<div class="defun">
&mdash; Function File:  <b>lin2mu</b> (<var>x, n</var>)<var><a name="index-lin2mu-2238"></a></var><br>
<blockquote><p>Converts audio data from linear to mu-law.  Mu-law values use 8-bit
unsigned integers.  Linear values use <var>n</var>-bit signed integers or
floating point values in the range -1&lt;=<var>x</var>&lt;=1 if <var>n</var> is 0. 
If <var>n</var> is not specified it defaults to 0, 8 or 16 depending on
the range values in <var>x</var>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmu2lin.html#doc_002dmu2lin">mu2lin</a>, <a href="doc_002dloadaudio.html#doc_002dloadaudio">loadaudio</a>, <a href="doc_002dsaveaudio.html#doc_002dsaveaudio">saveaudio</a>, <a href="doc_002dplayaudio.html#doc_002dplayaudio">playaudio</a>, <a href="doc_002dsetaudio.html#doc_002dsetaudio">setaudio</a>, <a href="doc_002drecord.html#doc_002drecord">record</a>. 
</p></blockquote></div>

<!-- ./audio/mu2lin.m -->
   <p><a name="doc_002dmu2lin"></a>

<div class="defun">
&mdash; Function File:  <b>mu2lin</b> (<var>x, bps</var>)<var><a name="index-mu2lin-2239"></a></var><br>
<blockquote><p>Converts audio data from linear to mu-law.  Mu-law values are 8-bit
unsigned integers.  Linear values use <var>n</var>-bit signed integers
or floating point values in the range -1&lt;=y&lt;=1 if <var>n</var> is 0.  If
<var>n</var> is not specified it defaults to 8. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dlin2mu.html#doc_002dlin2mu">lin2mu</a>, <a href="doc_002dloadaudio.html#doc_002dloadaudio">loadaudio</a>, <a href="doc_002dsaveaudio.html#doc_002dsaveaudio">saveaudio</a>, <a href="doc_002dplayaudio.html#doc_002dplayaudio">playaudio</a>, <a href="doc_002dsetaudio.html#doc_002dsetaudio">setaudio</a>, <a href="doc_002drecord.html#doc_002drecord">record</a>. 
</p></blockquote></div>

<!-- ./audio/loadaudio.m -->
   <p><a name="doc_002dloadaudio"></a>

<div class="defun">
&mdash; Function File:  <b>loadaudio</b> (<var>name, ext, bps</var>)<var><a name="index-loadaudio-2240"></a></var><br>
<blockquote><p>Loads audio data from the file <samp><var>name</var><span class="file">.</span><var>ext</var></samp> into the
vector <var>x</var>.

        <p>The extension <var>ext</var> determines how the data in the audio file is
interpreted;  the extensions <samp><span class="file">lin</span></samp> (default) and <samp><span class="file">raw</span></samp>
correspond to linear, the extensions <samp><span class="file">au</span></samp>, <samp><span class="file">mu</span></samp>, or <samp><span class="file">snd</span></samp>
to mu-law encoding.

        <p>The argument <var>bps</var> can be either 8 (default) or 16, and specifies
the number of bits per sample used in the audio file. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dlin2mu.html#doc_002dlin2mu">lin2mu</a>, <a href="doc_002dmu2lin.html#doc_002dmu2lin">mu2lin</a>, <a href="doc_002dsaveaudio.html#doc_002dsaveaudio">saveaudio</a>, <a href="doc_002dplayaudio.html#doc_002dplayaudio">playaudio</a>, <a href="doc_002dsetaudio.html#doc_002dsetaudio">setaudio</a>, <a href="doc_002drecord.html#doc_002drecord">record</a>. 
</p></blockquote></div>

<!-- ./audio/saveaudio.m -->
   <p><a name="doc_002dsaveaudio"></a>

<div class="defun">
&mdash; Function File:  <b>saveaudio</b> (<var>name, x, ext, bps</var>)<var><a name="index-saveaudio-2241"></a></var><br>
<blockquote><p>Saves a vector <var>x</var> of audio data to the file
<samp><var>name</var><span class="file">.</span><var>ext</var></samp>.  The optional parameters <var>ext</var> and
<var>bps</var> determine the encoding and the number of bits per sample used
in the audio file (see <code>loadaudio</code>);  defaults are <samp><span class="file">lin</span></samp> and
8, respectively. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dlin2mu.html#doc_002dlin2mu">lin2mu</a>, <a href="doc_002dmu2lin.html#doc_002dmu2lin">mu2lin</a>, <a href="doc_002dloadaudio.html#doc_002dloadaudio">loadaudio</a>, <a href="doc_002dplayaudio.html#doc_002dplayaudio">playaudio</a>, <a href="doc_002dsetaudio.html#doc_002dsetaudio">setaudio</a>, <a href="doc_002drecord.html#doc_002drecord">record</a>. 
</p></blockquote></div>

   <p>The following functions for audio I/O require special A/D hardware and
operating system support.  It is assumed that audio data in linear
encoding can be played and recorded by reading from and writing to
<samp><span class="file">/dev/dsp</span></samp>, and that similarly <samp><span class="file">/dev/audio</span></samp> is used for mu-law
encoding.  These file names are system-dependent.  Improvements so that
these functions will work without modification on a wide variety of
hardware are welcome.

<!-- ./audio/playaudio.m -->
   <p><a name="doc_002dplayaudio"></a>

<div class="defun">
&mdash; Function File:  <b>playaudio</b> (<var>name, ext</var>)<var><a name="index-playaudio-2242"></a></var><br>
&mdash; Function File:  <b>playaudio</b> (<var>x</var>)<var><a name="index-playaudio-2243"></a></var><br>
<blockquote><p>Plays the audio file <samp><var>name</var><span class="file">.</span><var>ext</var></samp> or the audio data
stored in the vector <var>x</var>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dlin2mu.html#doc_002dlin2mu">lin2mu</a>, <a href="doc_002dmu2lin.html#doc_002dmu2lin">mu2lin</a>, <a href="doc_002dloadaudio.html#doc_002dloadaudio">loadaudio</a>, <a href="doc_002dsaveaudio.html#doc_002dsaveaudio">saveaudio</a>, <a href="doc_002dsetaudio.html#doc_002dsetaudio">setaudio</a>, <a href="doc_002drecord.html#doc_002drecord">record</a>. 
</p></blockquote></div>

<!-- ./audio/record.m -->
   <p><a name="doc_002drecord"></a>

<div class="defun">
&mdash; Function File:  <b>record</b> (<var>sec, sampling_rate</var>)<var><a name="index-record-2244"></a></var><br>
<blockquote><p>Records <var>sec</var> seconds of audio input into the vector <var>x</var>.  The
default value for <var>sampling_rate</var> is 8000 samples per second, or
8kHz.  The program waits until the user types &lt;RET&gt; and then
immediately starts to record. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dlin2mu.html#doc_002dlin2mu">lin2mu</a>, <a href="doc_002dmu2lin.html#doc_002dmu2lin">mu2lin</a>, <a href="doc_002dloadaudio.html#doc_002dloadaudio">loadaudio</a>, <a href="doc_002dsaveaudio.html#doc_002dsaveaudio">saveaudio</a>, <a href="doc_002dplayaudio.html#doc_002dplayaudio">playaudio</a>, <a href="doc_002dsetaudio.html#doc_002dsetaudio">setaudio</a>. 
</p></blockquote></div>

<!-- ./audio/setaudio.m -->
   <p><a name="doc_002dsetaudio"></a>

<div class="defun">
&mdash; Function File:  <b>setaudio</b> ([<var>w_type </var>[<var>, value</var>]])<var><a name="index-setaudio-2245"></a></var><br>
<blockquote><p>Execute the shell command &lsquo;<samp><span class="samp">mixer [</span><var>w_type</var><span class="samp"> [, </span><var>value</var><span class="samp">]]</span></samp>&rsquo;
</p></blockquote></div>

<!-- ./audio/wavread.m -->
   <p><a name="doc_002dwavread"></a>

<div class="defun">
&mdash; Function File: <var>y</var> = <b>wavread</b> (<var>filename</var>)<var><a name="index-wavread-2246"></a></var><br>
<blockquote><p>Load the RIFF/WAVE sound file <var>filename</var>, and return the samples
in vector <var>y</var>.  If the file contains multichannel data, then
<var>y</var> is a matrix with the channels represented as columns.

   &mdash; Function File: [<var>y</var>, <var>Fs</var>, <var>bits</var>] = <b>wavread</b> (<var>filename</var>)<var><a name="index-wavread-2247"></a></var><br>
<blockquote><p>Additionally return the sample rate (<var>fs</var>) in Hz and the number of bits
per sample (<var>bits</var>).

   &mdash; Function File: [<small class="dots">...</small>] = <b>wavread</b> (<var>filename, n</var>)<var><a name="index-wavread-2248"></a></var><br>
<blockquote><p>Read only the first <var>n</var> samples from each channel.

   &mdash; Function File: [<small class="dots">...</small>] = <b>wavread</b> (<var>filename,</var>[<var>n1 n2</var>])<var><a name="index-wavread-2249"></a></var><br>
<blockquote><p>Read only samples <var>n1</var> through <var>n2</var> from each channel.

   &mdash; Function File: [<var>samples</var>, <var>channels</var>] = <b>wavread</b> (<var>filename, "size"</var>)<var><a name="index-wavread-2250"></a></var><br>
<blockquote><p>Return the number of samples (<var>n</var>) and channels (<var>ch</var>)
instead of the audio data. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dwavwrite.html#doc_002dwavwrite">wavwrite</a>. 
</p></blockquote></div>

<!-- ./audio/wavwrite.m -->
   <p><a name="doc_002dwavwrite"></a>

<div class="defun">
&mdash; Function File:  <b>wavwrite</b> (<var>y, filename</var>)<var><a name="index-wavwrite-2251"></a></var><br>
&mdash; Function File:  <b>wavwrite</b> (<var>y, fs, filename</var>)<var><a name="index-wavwrite-2252"></a></var><br>
&mdash; Function File:  <b>wavwrite</b> (<var>y, fs, bits, filename</var>)<var><a name="index-wavwrite-2253"></a></var><br>
<blockquote><p>Write <var>y</var> to the canonical RIFF/WAVE sound file <var>filename</var>
with sample rate <var>fs</var> and bits per sample <var>bits</var>.  The
default sample rate is 8000 Hz with 16-bits per sample.  Each column
of the data represents a separate channel. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dwavread.html#doc_002dwavread">wavread</a>. 
</p></blockquote></div>

<!-- DO NOT EDIT!  Generated automatically by munge-texi. -->
<!-- Copyright (C) 2008, 2009 David Bateman -->
<!-- This file is part of Octave. -->
<!-- Octave is free software; you can redistribute it and/or modify it -->
<!-- under the terms of the GNU General Public License as published by the -->
<!-- Free Software Foundation; either version 3 of the License, or (at -->
<!-- your option) any later version. -->
<!-- Octave is distributed in the hope that it will be useful, but WITHOUT -->
<!-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -->
<!-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License -->
<!-- for more details. -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with Octave; see the file COPYING.  If not, see -->
<!-- <http://www.gnu.org/licenses/>. -->
<!-- FIXME -->
<!-- For now can't include "@" character in the path name, and so name -->
<!-- the example directory without the "@"!! -->
   </body></html>