Managing the CPU Load
Managing the CPU Load Monitoring processing power consumed
When you want to open multiple channels of sound, or even when you want to
open a single channel of sound that requires intensive processing to provide a
high-quality sound (for example, real-time expansion of compressed sampled
sound with stereo output and linear interpolation), you may want to pay close
attention to the amount of processing power consumed by your sound- related
activity. The new Sound Manager allows you to monitor and limit the load
placed on the CPU by sound activity.
You need to be able to monitor the sound processing done by your application
because every Macintosh computer has some absolute limit to its processing
power, which is determined largely by the speed of the CPU. Other factors also
affect how much sound-related activity a given computer can support, such as
processing necessary to track mouse movements, processing done by the
Operating System, processing done by interrupt routines, and so on. When no
sound channels are open, the Sound Manager considers the computer to be
completely available for sound tasks. In that case, the current load value is 0
percent. As sound channels are opened, the current CPU loading value increases
from 0 percent to the maximum value, 100 percent. The amount of increase
due to a new sound channel depends on the initialization parameters specified
in the call to SndNewChannel that created that channel.
Note: The CPU load values provided by the Sound Manager do not
account for any nonsound processing, such as networking software or
other interrupt code.
In the enhanced Sound Manager, the loadCmd command returns (in
param1) the percentage of CPU load that would be reserved by calling
SndNewChannel with the initialization parameters passed into param2 of
the loadCmd command. On a Macintosh II, the value returned in param1 might
be 15 percent, indicating that a stereo sound channel would need 15 percent of
the available processor power to play sound.
The totalLoadCmd command returns a potentially more useful number. The
totalLoadCmd command is identical to the loadCmd command except that instead
of returning just the percentage of processor power for the specified
initialization parameters, it adds the current CPU loading value to that
number. The value returned in param1 is the total processor power that would
be used by the Sound Manager if those initialization parameters were
actually used to allocate a sound channel. If the number returned is greater
than 100 percent, allocating that channel would not be advisable.