Documentation

audioplayer

Create object for playing audio

Syntax

player = audioplayer(Y,Fs)
player = audioplayer(Y,Fs,nBits)
player = audioplayer(Y,Fs,nBits,ID)
player = audioplayer(recorder)
player = audioplayer(recorder,ID)

Description

player= audioplayer(Y,Fs)creates anaudioplayerobject for signalY, using sample rateFs. The function returns a handle to theaudioplayerobject,player.

player= audioplayer(Y,Fs,nBits)usesnBitsbits per sample for signalY.

player= audioplayer(Y,Fs,nBits,ID)uses the audio device identified byIDfor output.

player= audioplayer(recorder)creates anaudioplayerobject using audio recorder objectrecorder.

player= audioplayer(recorder,ID)creates an object fromrecorderthat uses the audio device identified byIDfor output.

Input Arguments

Y

Audio signal represented by a vector or two-dimensional array containingsingle,double,int8,uint8, orint16values.

The value range of the input sample depends on the data type. The following table lists these ranges.

Data Type

Sample Value Range

int8

-128 to 127

uint8

0到255

int16

-32768 to 32767

single

-1 to 1

double

-1 to 1

Fs

Sampling rate in Hz. Valid values depend on both the sample rates permitted by MATLAB®和特定的音频硬件系统上。妈TLAB has a hard restriction of 1000 Hz <= Fs <= 384000 Hz, although further hardware-dependent restrictions apply. Typical values supported by most sound cards are 8000, 11025, 22050, 44100, 48000, and 96000 Hz.

nBits

Bits per sample. Specify only when signalYis represented by floating-point values. Valid values depend on the audio hardware installed:8,16, or24.

Default:16

ID

Device identifier. To obtain the ID of a device, use theaudiodevinfofunction.

Default:-1(default device)

recorder

Audio recorder object created byaudiorecorder.

Methods

Note

When calling any method, include theaudioplayerobject name using function syntax, such asstop(player).

get

Query properties ofaudioplayerobject.

isplaying

Query whether playback is in progress: returnstrueorfalse.

pause

Pause playback.

play

Play audio from beginning to end.

playblocking

Play, and do not return control until playback completes.

resume

Restart playback from paused position.

set

Set properties ofaudioplayerobject.

stop

Stop playback.

See the reference pages forget,play,playblocking, andsetfor additional syntax options.

Properties

BitsPerSample

Number of bits per sample. (Read-only)

CurrentSample

Current sample that the audio output device is playing. If the device is not playing,CurrentSampleis the next sample to play withplayorresume. (Read-only)

DeviceID

Identifier for audio device. (Read-only)

NumberOfChannels

Number of audio channels. (Read-only)

Running

Status of the audio player:'on'or'off'. (Read-only)

SampleRate

Sampling frequency in Hz.

TotalSamples

Total length of the audio data in samples. (Read-only)

Tag

Label of the object.

Type

Name of the class:'audioplayer'. (Read-only)

UserData

Any type of additional data to store with the object.

The following four properties apply tocallback functions. The first two inputs to your callback function must be theaudioplayerobject and aneventstructure.

StartFcn

Function to execute one time when playback starts.

StopFcn

Function to execute one time when playback stops.

TimerFcn

Function to execute repeatedly during playback. To specify time intervals for the repetitions, use theTimerPeriodproperty.

TimerPeriod

Time in seconds betweenTimerFcncallbacks. Default:.05

Examples

Load and play a sample audio file of Handel's “Hallelujah Chorus:”

load handel; player = audioplayer(y, Fs); play(player);

Introduced before R2006a

Was this topic helpful?