Sysquake Pro – Table of Contents
Sysquake for LaTeX – Table of Contents
Library - wav
wav is a library which adds to LME functions for encoding and decoding WAV files. WAV files contain digital sound. The wav library supports uncompressed, 8-bit and 16-bit, monophonic and polyphonic WAV files. It can also encode and decode WAV data in memory without files.
The following statement makes available functions defined in wav:
use wav
Functions
wavread
WAV decoding.
Syntax
use wav (samples, samplerate, nbits) = wavread(filename) (samples, samplerate, nbits) = wavread(filename, n) (samples, samplerate, nbits) = wavread(filename, [n1,n2]) (samples, samplerate, nbits) = wavread(data, ...)
Description
wavread(filename) reads the WAV file filename. The result is a 2-d array, where each row corresponds to a sample and each column to a channel. Its class is the same as the native type of the WAV file, i.e. int8 or int16.
wavread(filename,n), where n is a scalar integer, reads the first n samples of the file. wavread(filename,[n1,n2]), where the second input argument is a vector of two integers, reads samples from n1 to n2 (the first sample corresponds to 1).
Instead of a file name string, the first input argument can be a vector of bytes, of class int8 or uint8, which represents directly the contents of the WAV file.
In addition to the samples, wavread can return the sample rate in Hz (such as 8000 for phone-quality speech or 44100 for CD-quality music), and the number of bits per sample and channel.
See also
wavwrite
WAV encoding.
Syntax
use wav wavwrite(samples, samplerate, nbits, filename) data = wavwrite(samples, samplerate, nbits) data = wavwrite(samples, samplerate)
Description
wavwrite(samples,samplerate,nbits,filename) writes a WAV file filename with samples in array samples, sample rate samplerate (in Hz), and nbits bits per sample and channel. Rows of samples corresponds to samples and columns to channels. nbits can be 8 or 16.
With 2 or 3 input arguments, wavwrite returns the contents of the WAV file as a vector of class uint8. The default word size is 16 bits per sample and channel.
Example
use wav sr = 44100; t = (0:sr)' / sr; s = sin(2 * pi * 740 * t); wavwrite(map2int(s, -1, 1, 'int16'), sr, 16, 'beep.wav');