background image
C H A P T E R 1 4
Using Sound
Creating Sound Frames Procedurally
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
You can use the
function to make a modifiable copy of the sound frame by
passing the frame or its reference to
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
does not actually store a copy of the
data. Instead, the
frame stores a pointer to the ROM data in its
slot. Thus, the
frame is fairly lightweight in terms of
overhead in the NewtonScript heap.
Playing Sound
Newton system software plays sound in two ways. The first is to use the global
sound functions
. 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
Using a sound channel to play a sound is accomplished by creating a sound
channel and sending the
message to it.
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна