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.
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);
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.
soundscin MATLAB Online™ or MATLAB Web App Server™,
nBits. Instead, it plays audio data using the default number of bits per sample of the output audio device.
Security Considerations When Using MATLAB Online or MATLAB Web App Server
soundsc in MATLAB
Online or MATLAB
Web App Server, certain features and settings help you keep control of your
To reduce the likelihood of unwanted applications using your microphone, turn off automatic access to your audio device. You can change these settings at any time. After granting permission to a website once, your browser may be able to access your microphone automatically for that site on future visits. Use the browser settings for Google Chrome to revoke access for specific sites after you have initially allowed access.
You can also access the MATLAB
Online website or MATLAB
Web App Server using the private browsing mode in
Google Chrome. When you do this, Chrome™ automatically asks you for permission to access your microphone every
time you open the MATLAB
Online site or the MATLAB
Web App Server and run
soundsc, regardless of your browser
soundfunction 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.
Audio playback in MATLAB Online and MATLAB Web App Server are supported in Google Chrome™.