Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
wavread
reads sound data or querries data info from a .wav audio file
Syntax
Info = wavread(wavfile, 'info') s = wavread(wavfile, 'size') y = wavread(wavfile) y = wavread(wavfile, n) y = wavread(wavfile, [i1 i2]) [y, Fs, bits] = wavread(..)
Arguments
- wavfile
string: path and file name pointing to the audio file. Included heading constant strings
SCI
,TMPDIR
,SCIHOME
, orhome
are automatically expanded. The .wav extension is appended if no extension is given.- n
positive integer: number of first samples to get, per channel.
- [i1 i2]
positive integers, to select and return from each channel the samples #i1 to #i2.
- y
Matrix: values of sound amplitudes in [-1,+1], with one row per channel.
- Fs
integer: sampling frequency in Hz = number of samples per second per channel.
- bits
Positive integer: number of bits for
y
values.- Info
Row vector of 8 decimal integers describing the recorded signal. See the description section for details.
Description
Utility function to read .wav
sound file.
wavread(wavfile)
loads a sound file specified by the
string wavfile, returning the sampled data in y. Amplitude values are in
the range [-1,+1]. Supports multi-channel data in the following formats:
8-, 16-, and 32-bit linear, and floating point.
[y,Fs,bits]=wavread(wavfile)
returns the sample
rate (Fs) in Hertz and the number of bits per sample used to encode the
data in the file.
wavread(wavfile,n)
returns the first n samples
from each channel.
wavread(wavfile,[n1,n2])
returns samples n1 to
n2.
wavread(wavfile,'size')
returns the size of the
audio data contained in the file in place of the actual audio data,
returning the vector as [channels samples].
wavread(wavfile,'info')
returns information
about the audio data contained in the file, instead of the actual audio
data, returning a row vector with the following components:
(1) | encoding code | : | AKA format category: positive integer = standard id of the type of data encoding. Supported formats: 1 (PCM), 3 (normalized floating point). |
---|---|---|---|
(2) | number of channels | : | Number of simultaneous single-valued collected signals = size(y,1) . |
(3) | sampling frequency | : | number of samples recorded for each channel, per second. |
(4) | average bytes per second | : | For plain PCM it is the sampling rate multiplied by the number of channels and the number of bytes per sample. For compressed formats it is approximately the total data length in bytes divided by the duration of the sound. |
(5) | block alignment | : | The number of bytes associated with each sampling instant. For the plain PCM uncompressed format, it is equal to the number of channels multiplied by the number of bytes per channel. |
(6) | bits per sample (per channel) | : | Number of bits used to quantize each value of the sound amplitude. |
(7) | bytes per sample (per channel) | : | Number of bytes assigned to each individual value of the sound amplitude. |
(8) | length of sound data (per channel) | : | The total number of samples on each channel = size(y,2) .
Hence, the record's duration is Info(8)/Info(3) . |
Examples
File = "SCI/modules/sound/demos/chimes.wav"; wavread(File, "size") wavread(File, "info") y = wavread(File, 5) // the first five samples y = wavread(File, [4 7]) // only samples #4 to #7 [y, Fs, bits] = wavread(File); Fs, bits clf subplot(2,1,1) plot2d(y(1,:)) // first channel subplot(2,1,2) plot2d(y(2,:)) // second channel
--> wavread(File, "size") ans = 2. 13921. --> wavread(File, "info") ans = 1. 2. 22050. 88200. 4. 16. 2. 13921. --> y = wavread(File, 5) // the first five samples y = 0.000061 0.0002747 0.0002136 0.0001526 0.0000916 0.0000916 0.0001831 0.000061 0. 0.0000916 --> y = wavread(File, [4 7]) // only samples #4 to #7 y = 0.0001526 0.0000916 0.0000305 -0.0000305 0. 0.0000916 0.000061 0.0000916 --> [y, Fs, bits] = wavread(File); Fs, bits Fs = 22050. bits = 16.
See also
- auread — load .au sound file
- wavwrite — writes .wav sound file
- analyze — frequency plot of a sound signal
- mapsound — Computes and displays an Amplitude(time, frequency) spectrogram of a sound record
- RIFF-wav encoding (p.56)
Report an issue | ||
<< soundsec | Manipulação de Arquivos de Som | wavwrite >> |