Plays a sound in WAV format. This sound can be:
- stored on the disk.
- included in the library (.WDL).
- in an HFSQL memo.
This function can also be used to:
- play a system sound.
- play a sound of a given frequency for the desired time.
Remark: A sound card must be installed on the computer. The sound will be played according to the Windows settings (volume, balance, quality, etc.).
// Plays the sound found in the "TADA.WAV" file
// Plays while locking on sound card
// Plays while looping on sound card
// Plays a sound of a given frequency
FOR nIndex = 1 TO 5536 STEP 100
FOR nIndex = 5536 TO 1 STEP -100
<Name of WAV file>: Character string
Full or relative name of file to play. This file can be:
<Option>: Optional integer constant
Sound execution mode:
|The code continues to run as soon as the sound is started.|
|soundLoop||The sound is played in a loop.|
Caution: The file to play must be found on disk and not in the library (WDL file).
|soundWait||The code is locked as long as the sound is not entirely played.|
<System sound>: Constant
Preset system sound to play:
|soundSystemAsterisk||Asterisk system sound.|
|soundSystemClosing||System sound for closing Windows.|
|soundSystemCriticalStop||System sound corresponding to the critical shutdown of the system.|
|soundSystemDefault||Default system sound (beep in most cases).|
|soundSystemExclamation||Exclamation system sound.|
|soundSystemQuestion||Question system sound.|
Playing a sound of a given frequency during the requested time Hide the details
<Result> = Sound(<Frequency> , <Duration>)
- True if the sound was played,
- False otherwise.
Remark: Until Windows 7, the sound is played on the inside speaker of the PC. From Windows 7, the sound is played on the sound card.
<Frequency>: Unsigned integer
Frequency of the sound in Hertz.
Remark: For the versions earlier than Windows 7, only the audible frequencies can be used (between 37 and 32767).
<Duration>: Unsigned integer
Duration (in milliseconds) during which the sound is played. Caution: the sound is locking. This parameter can correspond to:
- an integer corresponding to the number of milliseconds,
- a Duration variable,
- the duration in a readable format (e.g., 1 s or 10 ms).
Stopping a non-locking sound
A sound played in non-locking mode can be stopped by the following code, called on a user action for example (click, control modification, etc.):
Size of sound files
Using large WAV files may trigger several problems (not enough RAM to load the sound, system stopped depending on the Windows version, etc.). For large ".WAV" files (several dozen megabytes), we recommend that you use the MCI functions
A sound is necessarily locking:
- If the sound is stored in a WINDEV library (.WDL file).
- If the sound comes from a binary memo.
Sound and component
Sound is a non-blocking function by default. To use Sound in a component without locking the application, you must comply with the following constraints:
- The file corresponding to the sound must not be found in the WDL or in the component.
- The file corresponding to the sound must be found in the EXE directory of the application.
Business / UI classification: UI Code