Documentation Center

  • Trial Software
  • Product Updates

soundsc

Scale data and play as sound

Syntax

Description

example

soundsc(y) scales 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, soundsc plays the audio as loudly as possible without clipping. The mean of the dynamic range of the data is set to zero.

example

soundsc(y,Fs) sends audio signal y to the speaker at sample rate Fs.

example

soundsc(y,Fs,nBits) uses nBits bits per sample for audio signal y.

example

soundsc(___,yRange), where yRange is a vector of the form [low,high], linearly scales the values in y between low and high to the full sound range [-1.0,1.0]. Values outside [low,high] are not clipped. You can use yRange with any of the input arguments in the above syntaxes.

Examples

expand all

Play Sample Data at Default Sample Rate

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 Sample Data at Specific Sample Rate

Play an excerpt from Handel's "Hallelujah Chorus" at twice the recorded sample rate.

load handel.mat;
soundsc(y, 2*Fs);

Play Sample Data with Specific Bit Depth

load handel.mat;
nBits = 16;
soundsc(y,Fs,nBits);

MATLAB® plays the scaled audio with a bit depth of 16 bits per sample.

Scale Selected Audio Data

load handel.mat;
yRange = [-0.7,0.7];
soundsc(y,yRange);

Input Arguments

expand all

y — Audio datacolumn vector | m-by-2 matrix

Audio data, specified as an m-by-1 column vector for single-channel (mono) audio, or an m-by-2 matrix for stereo playback, where m is the number of audio samples. If y is an m-by-2 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.

Data Types: double

Fs — Sample rate8192 (default) | positive number

Sample rate, in hertz, of audio data y, specified as a positive number between 80 and 1000000.

Data Types: single | double

nBits — Bit depth of sample values8 (default) | 16 | 24

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[min(y),max(y)] (default) | two-element vector

Range of audio data to scale, specified as a two-element vector of the form [low,high], where low and high are the lower and upper limits of the range.

Example: [-0.8,0.8]

Data Types: double

More About

expand all

Tips

  • The 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.

See Also

| | |

Was this topic helpful?