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
(Update to add new feature (#185)) |
No edit summary |
||
Line 8: | Line 8: | ||
{{Parameters}} | {{Parameters}} | ||
* The [[LONG]] {{Parameter|handle&}} value is returned by [[_SNDOPEN]] using a specific sound file. | * The [[LONG]] {{Parameter|handle&}} value is returned by [[_SNDOPEN]] using a specific sound file. | ||
* The {{Parameter|volume!}} parameter can be any [[SINGLE]] value from 0 (no volume) to 1 (full volume). | * The {{Parameter|volume!}} parameter can be any [[SINGLE]] value from 0 (no volume) to 1 (full volume). | ||
* {{Parameter|x!}} distance values go from left (negative) to right (positive) (beginning with '''v3.3.x'''). | * {{Parameter|x!}} distance values go from left (negative) to right (positive) (beginning with '''v3.3.x'''). | ||
Line 22: | Line 22: | ||
:#Plays the copy. | :#Plays the copy. | ||
:#Closes 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. | * 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. | *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. | *Omitted x!, y! or z! values are set to 0. | ||
Line 52: | Line 52: | ||
''Example 2:'' Playing a sound at random volumes. | ''Example 2:'' Playing a sound at random volumes. | ||
{{CodeStart}} | {{CodeStart}} | ||
chomp& = {{Cl|_SNDOPEN}}("chomp.wav") | chomp& = {{Cl|_SNDOPEN}}("chomp.wav") | ||
{{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}} |
Revision as of 02:42, 23 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!]]
- 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