background image
C H A P T E R 1 4
Sound
Using Sound
14-5
Creating Sound Frames Procedurally
14
To create a sound frame, you usually need to create a copy of the sound frame you
wish to modify. Because you cannot modify sound frames in ROM, you must copy
the sound frame in order to modify the binary
sample data.
Cloning the original version of a sound frame you want to modify also allows you
to reset values to their original state and provides a means of recovering the original
sound frame easily if an operation fails.
Cloning Sound Frames
14
You can use the
Clone
function to make a modifiable copy of the sound frame by
passing the frame or its reference to
Clone
and saving the result in a variable, as in
the following example:
clonedSound := clone(ROM_simpleBeep);
This technique is an extremely efficient means of creating a modifiable sound
frame, because the copy created is a shallow clone; that is, the cloned frame
clonedSound
does not actually store a copy of the
ROM_simpleBeep
binary
data. Instead, the
clonedSound
frame stores a pointer to the ROM data in its
samples
slot. Thus, the
clonedSound
frame is fairly lightweight in terms of
overhead in the NewtonScript heap.
Playing Sound
14
Newton system software plays sound in two ways. The first is to use the global
sound functions
PlaySoundAtVolume
or
PlaySoundIrregardless
. The
other way is to instantiate a sound playback channel and send messages to it. Each
approach has benefits and drawbacks. Using the global functions is the simplest
and most efficient approach, but it offers less control than sending messages to a
sound channel.
Sound channels are appropriate for applications that require greater control over
playback, such as one that allows pausing playback and sound completion. Sound
channels are also useful for games, which might require having many sounds
available on short notice or playing multiple sounds at the same time.
Using a Sound Channel to Play Sound
14
Using a sound channel to play a sound is accomplished by creating a sound
channel and sending the
Start
message to it.
© 2007-2017, o7 studio » при воспроизведении материала сайта ссылка обязательна