File: octave_33.html

package info (click to toggle)
octave2.1 1%3A2.1.73-13
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 37,028 kB
  • ctags: 20,874
  • sloc: cpp: 106,508; fortran: 46,978; ansic: 5,720; sh: 4,800; makefile: 3,186; yacc: 3,132; lex: 2,892; lisp: 1,715; perl: 778; awk: 174; exp: 134
file content (192 lines) | stat: -rw-r--r-- 7,887 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                      "http://www.w3.org/TR/html40/loose.dtd">
<HTML>
<!-- Created on May, 18 2005 by texi2html 1.66 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>

-->
<HEAD>
<TITLE>GNU Octave: Audio Processing</TITLE>

<META NAME="description" CONTENT="GNU Octave: Audio Processing">
<META NAME="keywords" CONTENT="GNU Octave: Audio Processing">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.66">

</HEAD>

<BODY LANG="en" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">

<A NAME="SEC207"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_32.html#SEC206"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_34.html#SEC208"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_32.html#SEC206"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave.html#SEC_Top"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_34.html#SEC208"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_42.html#SEC245">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H1> 32. Audio Processing </H1>
<!--docid::SEC207::-->
<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>
<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
`<TT>/pub/usenet/news.answers/audio-fmts</TT>' of the archive site
<CODE>rtfm.mit.edu</CODE>.
</P>
<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 `<TT>lin</TT>' or `<TT>raw</TT>', and that
files holding data in mu-law encoding end in `<TT>au</TT>', `<TT>mu</TT>', or
`<TT>snd</TT>'.
</P>
<P>

<A NAME="doc-lin2mu"></A>
<A NAME="IDX1183"></A>
</P>
<DL>
<DT><U>Function File:</U>  <B>lin2mu</B> <I>(<VAR>x</VAR>, <VAR>n</VAR>)</I>
<DD>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>.
</DL>
<P>

<A NAME="doc-mu2lin"></A>
<A NAME="IDX1184"></A>
</P>
<DL>
<DT><U>Function File:</U>  <B>mu2lin</B> <I>(<VAR>x</VAR>, <VAR>bps</VAR>)</I>
<DD>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.
</DL>
<P>

<A NAME="doc-loadaudio"></A>
<A NAME="IDX1185"></A>
</P>
<DL>
<DT><U>Function File:</U>  <B>loadaudio</B> <I>(<VAR>name</VAR>, <VAR>ext</VAR>, <VAR>bps</VAR>)</I>
<DD>Loads audio data from the file `<TT><VAR>name</VAR>.<VAR>ext</VAR></TT>' into the
vector <VAR>x</VAR>.
<P>

The extension <VAR>ext</VAR> determines how the data in the audio file is
interpreted;  the extensions `<TT>lin</TT>' (default) and `<TT>raw</TT>'
correspond to linear, the extensions `<TT>au</TT>', `<TT>mu</TT>', or `<TT>snd</TT>'
to mu-law encoding.
</P>
<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.
</P>
</DL>
<P>

<A NAME="doc-saveaudio"></A>
<A NAME="IDX1186"></A>
</P>
<DL>
<DT><U>Function File:</U>  <B>saveaudio</B> <I>(<VAR>name</VAR>, <VAR>x</VAR>, <VAR>ext</VAR>, <VAR>bps</VAR>)</I>
<DD>Saves a vector <VAR>x</VAR> of audio data to the file
`<TT><VAR>name</VAR>.<VAR>ext</VAR></TT>'.  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 `<TT>lin</TT>' and
8, respectively.
</DL>
<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
`<TT>/dev/dsp</TT>', and that similarly `<TT>/dev/audio</TT>' 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.
</P>
<P>

<A NAME="doc-playaudio"></A>
<A NAME="IDX1187"></A>
</P>
<DL>
<DT><U>Function File:</U>  <B>playaudio</B> <I>(<VAR>name</VAR>, <VAR>ext</VAR>)</I>
<DD><A NAME="IDX1188"></A>
<DT><U>Function File:</U>  <B>playaudio</B> <I>(<VAR>x</VAR>)</I>
<DD>Plays the audio file `<TT><VAR>name</VAR>.<VAR>ext</VAR></TT>' or the audio data
stored in the vector <VAR>x</VAR>.
</DL>
<P>

<A NAME="doc-record"></A>
<A NAME="IDX1189"></A>
</P>
<DL>
<DT><U>Function File:</U>  <B>record</B> <I>(<VAR>sec</VAR>, <VAR>sampling_rate</VAR>)</I>
<DD>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 <KBD>RET</KBD> and then
immediately starts to record.
</DL>
<P>

<A NAME="doc-setaudio"></A>
<A NAME="IDX1190"></A>
</P>
<DL>
<DT><U>Function File:</U> setaudio <B>([<VAR>w_type</VAR></B> <I>[, <VAR>value</VAR>]])</I>
<DD>Execute the shell command `<SAMP>mixer [<VAR>w_type</VAR> [, <VAR>value</VAR>]]</SAMP>'
</DL>
<P>

<A NAME="Quaternions"></A>
<HR SIZE="6">
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_32.html#SEC206"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_34.html#SEC208"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_42.html#SEC245">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="octave_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>
<FONT SIZE="-1">
This document was generated
by <I>John W. Eaton</I> on <I>May, 18 2005</I>
using <A HREF="http://texi2html.cvshome.org"><I>texi2html</I></A>
</FONT>

</BODY>
</HTML>