err = Snd
Old Sound driver for Psychtoolbox. USE OF THIS DRIVER IS DEPRECATED FOR
ALL BUT THE MOST TRIVIAL PURPOSES!
Have a look at the help for PsychPortAudio
") for an introduction into the new sound
driver, which is recommended for most purposes.
() is a rather dumb and primitive wrapper around the PsychPortAudio
driver. It uses PsychPortAudio
's most basic functionality to achieve
"sort of ok" sound playback. The driver is used in high-latency,
low-timing precision mode, so Snd
()'s audio playback timing will likely
be very unreliable.
Alternatively you can create an empty file named 'Snd_use_oldstyle.txt' in
() folder, ie., [PsychtoolboxConfigDir
This will enable the old-style implementation of Snd
(), which is equally
shoddy and works as follows:
used to use a special purpose low level driver on MacOS
was well suited for cognitive science, Snd
for all other operating
systems (Windows, MacOS
-X, Linux) just calls into Matlab's Sound()
function which is of varying - but usually pretty poor - quality in most
implementations of Matlab. There are many bugs, latency- and timing
problems associated with the use of Snd
GNU/OCTAVE: If you don't use the PsychPortAudio
() functin, then
you must install the optional octave "audio" package from Octave-Forge,
as of Octave 3.0.5, otherwise the required sound() function won't be
available and this function will fail!
('Play', signal [, rate][, sampleSize]) plays a sound.
') returns the default sampling rate in Hz, which
currently is 22254.5454545454 Hz on all platforms for the old style sound
implementation, and the default device sampling rate if PsychPortAudio
used. This default may change in the future, so please either specify a
rate, or use this function to get the default rate. (This default is
suboptimal on any system except MacOS
-9, but kept for backwards
The optional 'sampleSize' argument used with Snd
('Play') is only retained
for backwards compatibility and has no meaning, unless you opt in to use
the old-style implementation on Matlab with some operating systems. - It
is checked for correctness, but other than that it is ignored. Allowable
values are either 8 or 16.
('Open') opens the channel, which stays open until you call
('Play',...) automatically opens the channel if it isn't
already open. In reality 'Open' does nothing in the current
implementation and is silently ignored .
') immediately stops all sound and closes the channel.
('Wait') waits until the sound is done playing.
') returns true if any sound is playing, and
false (0) otherwise.
('Quiet') stops the sound currently playing and flushes the queue, but
leaves the channel open.
"signal" must be a numeric array of samples.
Your "signal" data should lie between -1 and 1 (smaller to play more
softly). If the "signal" array has one row then it's played monaurally,
through both speakers. If it has two rows then it's played in stereo.
has no provision for changing which speaker(s), or the volume, used
by a named snd resource, so use READSND to get the snd into an array,
and supply the appropriately modified array to Snd
"rate" is the rate (in Hz) at which the samples in "signal" should be
played. We suggest you always specify the "rate" parameter. If not
specified, the sample "rate", on all platforms, defaults to OS9's
standard hardware sample rate of 22254.5454545454 Hz. That value is
returned by Snd
'). Other values can be specified.
OSX & WIN: "samplesize". Snd
accepts the sampleSize argument and passes
it to the Matlab SOUND command. SOUND (and therefore Snd
also) obeys the
specified sampleSize value, either 8 or 16, only if it is supported by
your computer hardware.
('Play',sin(0:10000)); % play 22 KHz/(2*pi)=3.5 kHz tone
('Play',[sin(1:20000) zeros(1,10000);zeros(1,10000) sin(1:20000)]); % stereo
('Wait'); % wait until end of all sounds currently in channel
('Quiet'); % stop the sound and flush the queue
For most of the commands, the returned value is zero when successful, and
a nonzero error number when Snd
('Play', signal) takes some time to open the channel, if it isn't
already open, and allocate a snd structure for your sound. This overhead
of the call to Snd
, if you call it in the middle of a movie, may be
perceptible as a pause in the movie, which would be bad. However, the
actual playing of the sound, asynchronously, is a background process that
usually has very little overhead. So, even if you want a sound to begin
after the movie starts, you should create a soundtrack for your entire
movie duration (possibly including long silences), and call Snd
the sound going before you start your movie. (Thanks to Liz Ching for
raising the issue.)
NOTE: We suggest you always specify the "rate" parameter. If not
specified, the sample rate, on all platforms, defaults to OS9's
standard hardware sample rate of 22254.5454545454 Hz. That value is returned
See also PsychPortAudio
, AUDIOPLAYER, PLAY, MakeBeep
, READSND, and WRITESND.