RobotC provides a comprehensive suite of functions for controlling the NXT speaker.
RobotC firmware queues up to 10 sound items for playback. This allows user programs to initiate playback of a sound item and continue execution without having to wait for a sound item to finish; this mode of operatio nis very desirable for robots where, if you waited for the sound to complete playback, you could be delayed in updating the robot’s motors in reaction to a change in sensors.
RobotC plays both uncompressed and compressed sound files. The RobotC development environment provides a command to compress sound files. It is located in the menu “Windows->NXT Brick->File Management”.
ClearSounds();
Clears all existing and buffered sound commands
PlayImmediateTone(frequency, durationIn10MsecTicks);
Immediately play tone at frequency & duration ahead of queued requests.
PlaySound(sound);
Play one of the system predefined sounds (buzz, beep, click, ...).
PlaySoundFile(sFileName);
Plays a sound file from the NXT file system. This file must exist on the NXT file system.
When a user program is downloaded by RobotC, a check is made to ensure that all sound files referenced by the “PlaySoundFile” function exist on the NXT; if not, then RobotC will attempt to download these files from the PC.
PlayTone(frequency, durationIn10MsecTicks);
Plays a constant tone at the specified frequency and duration.
bPlaySounds
Boolean flag. Indicates whether new sound requests should be accepted or discarded. A user can use this flag to ‘mute’ and ‘unmute’ sound playback.
bSoundActive
Boolean flag. If true indicates sound system is actively playing a sound.
bSoundQueueAvailable
Boolean flag. Indicates whether there is space available in the sound queue for another item.
This flag is useful at the end of a program, if you want to ensure that all sounds have finished before exiting the program. Simply add a check for completion as follows:
while (!bSoundQueueAvailable)
{}
kMaxVolumeLevel
Constant. The maximum volume level that can be set.
nVolume
Sound volume. Range 0 to 4 (loudest).