1 # Created by Octave 3.6.1, Tue Mar 20 07:03:19 2012 UTC <root@t61>
13 # name: <cell-element>
17 y = au(x, fs, lo [, hi])
19 Extract data from x for time range lo to hi in milliseconds. If lo
20 is [], start at the beginning. If hi is [], go to the end. If hi is
21 not specified, return the single element at lo. If lo<0, prepad the
22 signal to time lo. If hi is beyond the end, postpad the signal to
27 # name: <cell-element>
31 y = au(x, fs, lo [, hi])
36 # name: <cell-element>
43 # name: <cell-element>
47 -- Function File: [X,FS,SAMPLEFORMAT] = auload (FILENAME)
48 Reads an audio waveform from a file given by the string FILENAME.
49 Returns the audio samples in data, one column per channel, one row
50 per time slice. Also returns the sample rate and stored format
51 (one of ulaw, alaw, char, int16, int24, int32, float, double). The
52 sample value will be normalized to the range [-1,1] regardless of
55 [x, fs] = auload(file_in_loadpath("sample.wav"));
58 Note that translating the asymmetric range [-2^n,2^n-1] into the
59 symmetric range [-1,1] requires a DC offset of 2/2^n. The inverse
60 process used by ausave requires a DC offset of -2/2^n, so loading
61 and saving a file will not change the contents. Other
62 applications may compensate for the asymmetry in a different way
63 (including previous versions of auload/ausave) so you may find
64 small differences in calculated DC offsets for the same file.
69 # name: <cell-element>
73 Reads an audio waveform from a file given by the string FILENAME.
77 # name: <cell-element>
84 # name: <cell-element>
88 -- Function File: [Y,T,SCALE] = auplot (X)
89 -- Function File: [Y,T,SCALE] = auplot (X,FS)
90 -- Function File: [Y,T,SCALE] = auplot (X,FS,OFFSET)
91 -- Function File: [Y,T,SCALE] = auplot (...,PLOTSTR)
92 Plot the waveform data, displaying time on the X axis. If you are
93 plotting a slice from the middle of an array, you may want to
94 specify the OFFSET into the array to retain the appropriate time
95 index. If the waveform contains multiple channels, then the data
96 are scaled to the range [-1,1] and shifted so that they do not
97 overlap. If a PLOTSTR is given, it is passed as the third argument
98 to the plot command. This allows you to set the linestyle easily.
99 FS defaults to 8000 Hz, and OFFSET defaults to 0 samples.
101 Instead of plotting directly, you can ask for the returned
102 processed vectors. If Y has multiple channels, the plot should
103 have the y-range [-1 2*size(y,2)-1]. scale specifies how much the
104 matrix was scaled so that each signal would fit in the specified
107 Since speech samples can be very long, we need a way to plot them
108 rapidly. For long signals, auplot windows the data and keeps the
109 minimum and maximum values in the window. Together, these values
110 define the minimal polygon which contains the signal. The number
111 of points in the polygon is set with the global variable
112 auplot_points. The polygon may be either 'filled' or 'outline',
113 as set by the global variable auplot_format. For moderately long
114 data, the window does not contain enough points to draw an
115 interesting polygon. In this case, simply choosing an arbitrary
116 point from the window looks best. The global variable
117 auplot_window sets the size of the window required for creating
118 polygons. You can turn off the polygons entirely by setting
119 auplot_format to 'sampled'. To turn off fast plotting entirely,
120 set auplot_format to 'direct', or set auplot_points=1. There is no
121 reason to do this since your screen resolution is limited and
122 increasing the number of points plotted will not add any
123 information. auplot_format, auplot_points and auplot_window may
124 be set in .octaverc. By default auplot_format is 'outline',
125 auplot_points=1000 and auplot_window=7.
130 # name: <cell-element>
134 Plot the waveform data, displaying time on the X axis.
138 # name: <cell-element>
145 # name: <cell-element>
149 usage: ausave('filename.ext', x, fs, format)
151 Writes an audio file with the appropriate header. The extension on
152 the filename determines the layout of the header. Currently supports
153 .wav and .au layouts. Data is a matrix of audio samples in the
154 range [-1,1] (inclusive), one row per time step, one column per
155 channel. Fs defaults to 8000 Hz. Format is one of ulaw, alaw, char,
156 short, long, float, double
158 Note that translating the symmetric range [-1,1] into the asymmetric
159 range [-2^n,2^n-1] requires a DC offset of -2/2^n. The inverse
160 process used by auload requires a DC offset of 2/2^n, so loading and
161 saving a file will not change the contents. Other applications may
162 compensate for the asymmetry in a different way (including previous
163 versions of auload/ausave) so you may find small differences in
164 calculated DC offsets for the same file.
168 # name: <cell-element>
172 usage: ausave('filename.
176 # name: <cell-element>
183 # name: <cell-element>
187 Clip values outside the range to the value at the boundary of the
194 Clip to range [0, hi]
196 X = clip(X, [lo, hi])
197 Clip to range [lo, hi]
201 # name: <cell-element>
205 Clip values outside the range to the value at the boundary of the
210 # name: <cell-element>
217 # name: <cell-element>
221 usage: sound(x [, fs, bs])
223 Play the signal through the speakers. Data is a matrix with
224 one column per channel. Rate fs defaults to 8000 Hz. The signal
225 is clipped to [-1, 1]. Buffer size bs controls how many audio samples
226 are clipped and buffered before sending them to the audio player. bs
227 defaults to fs, which is equivalent to 1 second of audio.
229 Note that if $DISPLAY != $HOSTNAME:n then a remote shell is opened
230 to the host specified in $HOSTNAME to play the audio. See manual
231 pages for ssh, ssh-keygen, ssh-agent and ssh-add to learn how to
234 This function writes the audio data through a pipe to the program
235 "play" from the sox distribution. sox runs pretty much anywhere,
236 but it only has audio drivers for OSS (primarily linux and freebsd)
237 and SunOS. In case your local machine is not one of these, write
238 a shell script such as ~/bin/octaveplay, substituting AUDIO_UTILITY
239 with whatever audio utility you happen to have on your system:
241 cat > ~/.octave_play.au
242 SYSTEM_AUDIO_UTILITY ~/.octave_play.au
243 rm -f ~/.octave_play.au
244 and set the global variable (e.g., in .octaverc)
245 global sound_play_utility="~/bin/octaveplay";
247 If your audio utility can accept an AU file via a pipe, then you
249 global sound_play_utility="SYSTEM_AUDIO_UTILITY flags"
250 where flags are whatever you need to tell it that it is receiving
253 With clever use of the command dd, you can chop out the header and
254 dump the data directly to the audio device in big-endian format:
255 global sound_play_utility="dd of=/dev/audio ibs=2 skip=12"
256 or little-endian format:
257 global sound_play_utility="dd of=/dev/dsp ibs=2 skip=12 conv=swab"
258 but you lose the sampling rate in the process.
260 Finally, you could modify sound.m to produce data in a format that
261 you can dump directly to your audio device and use "cat >/dev/audio"
262 as your sound_play_utility. Things you may want to do are resample
263 so that the rate is appropriate for your machine and convert the data
264 to mulaw and output as bytes.
266 If you experience buffer underruns while playing audio data, the bs
267 buffer size parameter can be increased to tradeoff interactivity
268 for smoother playback. If bs=Inf, then all the data is clipped and
269 buffered before sending it to the audio player pipe. By default, 1
270 sec of audio is buffered.
274 # name: <cell-element>
278 usage: sound(x [, fs, bs])
283 # name: <cell-element>
290 # name: <cell-element>
294 usage: soundsc(x, fs, limit) or soundsc(x, fs, [ lo, hi ])
297 Scale the signal so that [min(x), max(x)] -> [-1, 1], then
298 play it through the speakers at 8000 Hz sampling rate. The
299 signal has one column per channel.
302 Scale the signal and play it at sampling rate fs.
304 soundsc(x, fs, limit)
305 Scale the signal so that [-|limit|, |limit|] -> [-1, 1], then
306 play it at sampling rate fs. If fs is empty, then the default
307 8000 Hz sampling rate is used.
309 soundsc(x, fs, [ lo, hi ])
310 Scale the signal so that [lo, hi] -> [-1, 1], then play it
311 at sampling rate fs. If fs is empty, then the default 8000 Hz
312 sampling rate is used.
315 return the scaled waveform rather than play it.
317 See sound for more information.
321 # name: <cell-element>
325 usage: soundsc(x, fs, limit) or soundsc(x, fs, [ lo, hi ])