SNDPLAYCOPY: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
Line 55: | Line 55: | ||
{{Cl|IF}} chomp& > 0 {{Cl|THEN}} {{Cl|_SNDPLAYCOPY}} chomp&, 0.5 + {{Cl|RND}} * 0.49 | {{Cl|IF}} chomp& > 0 {{Cl|THEN}} {{Cl|_SNDPLAYCOPY}} chomp&, 0.5 + {{Cl|RND}} * 0.49 | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Latest revision as of 01:08, 29 January 2023
The _SNDPLAYCOPY statement copies a sound, plays it, and automatically closes the copy using a handle parameter passed from _SNDOPEN or _SNDCOPY
Syntax
- _SNDPLAYCOPY handle&[, [volume!][, x!][, y!][, z!]]
Parameters
- The LONG handle& value is returned by _SNDOPEN using a specific sound file.
- The volume! parameter can be any SINGLE value from 0 (no volume) to 1 (full volume).
- x! distance values go from left (negative) to right (positive) (beginning with v3.3.x).
- y! distance values go from below (negative) to above (positive) (beginning with v3.3.x).
- z! distance values go from behind (negative) to in front (positive) (beginning with v3.3.x).
Description
- Makes coding easier by doing all of the following automatically:
- Copies/duplicates the source handle (see _SNDCOPY).
- Changes the volume of the copy if volume is passed.
- Applies stereo panning or a 3D position if x, y, z is passed.
- Plays the copy.
- Closes the copy.
- This statement is a better choice than _SNDPLAYFILE if the sound will be played often, reducing the burden on the computer.
- By setting the x! value to -1 or 1 it plays the sound at full volume from the appropriate speaker.
- Omitted x!, y! or z! values are set to 0.
Examples
Example 1: Playing a previously opened sound from left and right speakers.
DIM AS LONG h, i h = _SNDOPEN("explosion.wav") IF h > 0 THEN FOR i = 0 TO 9 _LIMIT 1 IF i MOD 2 = 0 THEN PRINT "Playing from right" _SNDPLAYCOPY h, , 1 ELSE PRINT "Playing from left" _SNDPLAYCOPY h, , -1 END IF NEXT END IF |
Example 2: Playing a sound at random volumes.
chomp& = _SNDOPEN("chomp.wav") IF chomp& > 0 THEN _SNDPLAYCOPY chomp&, 0.5 + RND * 0.49 |
See also