player = audioplayer(Y, Fs)
player = audioplayer(Y, Fs, nBits)
player = audioplayer(Y, Fs, nBits, ID)
player = audioplayer(R)
player = audioplayer(R, ID)
Note To use all of the features of the audio player object, your system needs a properly installed and configured sound card with 8- and 16-bit I/O, two channels, and support for sampling rates of up to 48 kHz. |
player = audioplayer(Y, Fs) creates an audio player object for signal Y, using sample rate Fs. The function returns player, a handle to the audio player object. The audio player object supports methods and properties that you can use to control how the audio data is played.
The input signal Y can be a vector or two-dimensional array containing single, double, int8, uint8, or int16 MATLAB data types. Fs is the sampling rate in Hz to use for playback. Valid values for Fs depend on the specific audio hardware installed. Typical values supported by most sound cards are 8000, 11025, 22050, and 44100 Hz.
player = audioplayer(Y, Fs, nBits) creates an audio player object and uses nBits bits per sample for floating point signal Y. Valid values for nBits are 8, 16, and 24 on Windows, 8 and 16 on UNIX. The default number of bits per sample for floating point signals is 16.
player = audioplayer(Y, Fs, nBits, ID) creates an audio player object using audio device identifier ID for output. If ID equals -1, the default output device will be used. This option is only available on Windows.
player = audioplayer(R) creates an audio player object using audio recorder object R.
player = audioplayer(R, ID) creates an audio player object from audio recorder object R using audio device identifier ID for output. This option is only available on Windows.
The value range of the input sample depends on the MATLAB data type. The following table lists these ranges.
Data Type | Input Sample Value Range |
---|---|
-128 to 127 | |
0 to 255 | |
-32768 to 32767 | |
-1 to 1 | |
-1 to 1 |
Load a sample audio file of Handel's Hallelujah Chorus, create an audio player object, and play back only the first three seconds. y contains the audio samples and Fs is the sampling rate. You can use any of the audioplayer functions listed above on the player:
load handel; player = audioplayer(y, Fs); play(player,[1 (get(player, 'SampleRate')*3)]);
To stop the playback, use this command:
stop(player); % Equivalent to player.stop
After you create an audio player object, you can use the methods listed below on that object. player represents a handle to the audio player object.
Method | Description |
---|---|
Starts playback from the beginning and plays to the end of audio
player object player. | |
Same as play, but does not return control until playback completes. | |
Stops playback. | |
Pauses playback. | |
Restarts playback from where playback was paused. | |
Indicates whether playback is in progress. If 0, playback is not in progress. If 1, playback is in progress. | |
Displays all property information about audio player player. |
Audio player objects have the properties listed below. To set a user-settable property, use this syntax:
set(player, 'property1', value,'property2',value,...)
To view a read-only property,
get(player,'property') % Displays 'property' setting.
© 1984-2008 The MathWorks, Inc.