Scale data and play as sound
the values of audio signal
y to fit in the range
from –1.0 to 1.0, and then sends the data to the speaker at
the default sample rate of 8192 hertz. By first scaling the data,
the audio as loudly as possible without clipping. The mean of the
dynamic range of the data is set to zero.
Load the example file
gong.mat, which contains sample data
y and rate
Fs, and listen to the audio.
load gong.mat; soundsc(y);
Play an excerpt from Handel's "Hallelujah Chorus" at twice the recorded sample rate.
load handel.mat; soundsc(y, 2*Fs);
load handel.mat; nBits = 16; soundsc(y,Fs,nBits);
MATLAB® plays the scaled audio with a bit depth of 16 bits per sample.
load handel.mat; yRange = [-0.7,0.7]; soundsc(y,yRange);
y— Audio data
Audio data, specified as an
vector for single-channel (mono) audio, or an
matrix for stereo playback, where
m is the number
of audio samples. If
y is an
matrix, then the first column corresponds to the left channel, and
the second column corresponds to the right channel. Stereo playback
is available only if your system supports it.
Fs— Sample rate
Sample rate, in hertz, of audio data
specified as a positive number from 1000 through 384000. Valid values
depend on both the sample rates permitted by MATLAB® and the specific
audio hardware on your system. MATLAB has a hard restriction
of 1000 Hz <= Fs <= 384000 Hz, although further hardware-dependent
nBits— Bit depth of sample values
Bit depth of the sample values, specified as an integer. Valid values depend on the audio hardware installed. Most platforms support bit depths of 8 bits or 16 bits.
yRange— Range of audio data to scale
[-max(abs(y)),max(abs(y))](default) | two-element vector
Range of audio data to scale, specified as a two-element vector
of the form
the lower and upper limits of the range. Values in
are scaled beyond
[-1.0, 1.0] are clipped when
played back on a sound device.
sound function supports sound
devices on all Windows® and most UNIX® platforms.
Most sound cards support sample rates between 5 and 48 kilohertz. Specifying a sample rate outside this range might produce unexpected results.