Apple Newton Utilities User's Guide Page 561

  • Download
  • Add to my manuals
  • Print
  • Page
    / 942
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 560
CHAPTER 14
Sound
Using Sound 14-7
Synchronous and Asynchronous Sound 14
When a sound is played asynchronously, the playback can be intermixed with other
tasks because the system does not wait for the sound to nish before beginning
another task (such as updating the user interface, allowing user feedback; for
example with buttons, or playing a subsequent sound).
When playback must be allowed to complete, use the
PlaySoundSync,
PlaySoundAtVolume, or PlaySoundIrregardless to guarantee
uninterrupted playback. Synchronous playback is generally preferred unless the
sound is so long as to be tedious or the application requires a high degree of
responsiveness to the user. The NewtonScript interpreter can do nothing else until
it completes synchronous playback.
Both approaches have benets and drawbacks: synchronous playback can block
other NewtonScript code from running when it’s inconvenient to do so; on the
other hand, asynchronous playback is never guaranteed to complete. Your use of
synchronous or asynchronous sound playback depends on your application’s needs.
Differences Between Synchronous Asynchronous Playback 14
The following code example demonstrates the difference between asynchronous
playback and synchronous playback. To hear the demonstration of the two types
of sound playback, type following code example into the Inspector as it is shown
here, select all of these lines, and press Enter:
print ("Synchronous sound demo");
call func()
begin
for i := 0 to 20 do
PlaySoundSync(ROM_simplebeep);
end with();
print ("Async sound demo");
call func()
begin
for i := 0 to 20 do
PlaySoundSync(ROM_simplebeep);
end with();
The synchronous sound playback example plays the ROM_simplebeep sound
twenty times; the sound plays its entire length each time. Twenty repetitions may
seem a bit laborious until you hear how quickly the same calls are made in
asynchronous mode.
Note that the asynchronous version can call the sound chip so fast that the sound
does not have enough time to nish playing; as a result, part of the playback is
Page view 560
1 2 ... 556 557 558 559 560 561 562 563 564 565 566 ... 941 942

Comments to this Manuals

No comments