Audio Playback

This section describes functions which play sounds.

audioplay

Play audio samples.

Syntax

audioplay(samples)
audioplay(samples, options)

Description

audioplay(samples) plays the audio samples in array samples at a sample rate of 44.1 kHz. Each column of samples is a channel (i.e. samples is a column vector for monophonic sound and a two-column array for stereophonic sound), and each row is a sample. Samples are stored as double or single numbers between -1 and 1, int8 numbers between -128 and 127, or int16 numbers between -32768 and 32767.

audioplay(samples,options) uses the specified options, which are typically built with audioset.

Examples

A monophonic bell-like sound of two seconds with a frequency of 740 Hz and a damping time constant of 0.5 second:

t = (0:88200)'/44100;
samples = sin(2*pi*740*t).*exp(-t/0.5);
audioplay(samples);

Some white noise which oscillates 5 times between left and right:

t = (0:44099)' / 44100;
noise = 0.1 * randn(length(t), 1);
left = cos(2 * pi * t) .* noise;
right = sin(2 * pi * t) .* noise;
opt = audioset('Repeat', 5);
audioplay([left, right], opt);

See also

audioset

audioset

Options for audio.

Syntax

options = audioset
options = audioset(name1, value1, ...)
options = audioset(options0, name1, value1, ...)

Description

audioset(name1,value1,...) creates the option argument used by audioplay. Options are specified with name/value pairs, where the name is a string which must match exactly the names in the table below. Case is significant. Options which are not specified have a default value. The result is a structure whose fields correspond to each option. Without any input argument, audioset creates a structure with all the default options. Note that audioplay also interprets the lack of an option argument, or the empty array [], as a request to use the default values.

When its first input argument is a structure, audioset adds or changes fields which correspond to the name/value pairs which follow.

Here is the list of permissible options:

NameDefaultMeaning
Repeat1number of repetitions
SampleRate44100sample rate in Hz

Default values may be different on platforms with limited audio capabilities.

Example

Default options:

audioset
  Repeat: 1
  SampleRate: 44100

See also

audioplay


Copyright 2004-2007, Calerga.
All rights reserved.