playSound: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<dd class="note">([^}]*)<code>([^<]*)<\/code>" to "<dd class="note">$1<sqf>$2</sqf>")
m (Some wiki formatting)
Line 48: Line 48:


|x2= Start a sound and then stop it after 1.2 second:
|x2= Start a sound and then stop it after 1.2 second:
<code>playSound "AlarmCar";
<sqf>playSound "AlarmCar";
[] spawn  
[] spawn  
{
{
Line 56: Line 56:
};
};


// since {{arma3 v1.99.146480}}
// since Arma 3 v2.00
_source = playSound "AlarmCar";
_source = playSound "AlarmCar";
_source spawn  
_source spawn  
Line 62: Line 62:
sleep 1.2;
sleep 1.2;
deleteVehicle _this;
deleteVehicle _this;
};</code>
};
</sqf>


|x3= Start a sound and wait until it is finished:
|x3= Start a sound and wait until it is finished:
<code>playSound "Alarm";
<sqf>
playSound "Alarm";
hint "Started!";
hint "Started!";
[] spawn
[] spawn
Line 74: Line 76:
};
};


// since {{arma3 v1.99.146480}}
// since Arma 3 v2.00
_source = playSound "Alarm";
_source = playSound "Alarm";
_source spawn  
_source spawn  
Line 80: Line 82:
waitUntil {isNull _this};
waitUntil {isNull _this};
hint "Finished!";
hint "Finished!";
};</code>
};
</sqf>


|seealso= [[playSound3D]] [[sideRadio]] [[say]] [[playMusic]] [[say2D]] [[say3D]] [[createSoundSource]] [[playSoundUI]]
|seealso= [[playSound3D]] [[sideRadio]] [[say]] [[playMusic]] [[say2D]] [[say3D]] [[createSoundSource]] [[playSoundUI]]
Line 102: Line 105:
<br>
<br>
This example,   
This example,   
<sqf>playSound "soundname";
<sqf>
playSound "soundname";
playSound "soundname";
playSound "soundname";
</sqf>
</sqf>
Line 108: Line 112:
Will effectively amplify the sound by a sensed 2x. The volume of the sound file itself will still affect the sound volume as it appears as though the arma engine has no normalization for sound files added to it.  
Will effectively amplify the sound by a sensed 2x. The volume of the sound file itself will still affect the sound volume as it appears as though the arma engine has no normalization for sound files added to it.  


==== Notes ====
{{Feature|informative|
 
This technique may cause issues in sound quality in large multiplayer servers. I observed multiple instances when a triggered sound amplified with this method was out of sync with each other. Timing of the individual commands sent over the network is probably the issue. Recommend you compile your amplification code into a single finished function for better syncing for clients not activating the action/far away from the activation position.
This technique may cause issues in sound quality in large multiplayer servers. I observed multiple instances when a triggered sound amplified with this method was out of sync with each other. Timing of the individual commands sent over the network is probably the issue. Recommend you compile your amplification code into a single finished function for better syncing for clients not activating the action/far away from the activation position.  
}}


</dd>
</dd>


</dl>
</dl>

Revision as of 15:38, 13 May 2022

Hover & click on the images for description

Description

Description:
Plays a sound from CfgSounds. Sound can be defined in missionConfigFile, configFile or campaignConfigFile.
Groups:
Sounds

Syntax

Syntax:
playSound soundName
Parameters:
soundName: String
Return Value:
Object - the speaker object (Nothing before Arma 3 v2.00)

Alternative Syntax

Syntax:
playSound [soundName, isSpeech, offset]
Parameters:
soundName: String
isSpeech: Boolean - true to play it as speech, fadeSpeech applies. False to play it as sound, fadeSound applies
since Arma 3 logo black.png2.00
offset: Number - (Optional, default 0) Offset in seconds. Same as playMusic
Return Value:
Object - the speaker object (Nothing before Arma 3 v2.00)

Examples

Example 1:
playSound "soundname"
Example 2:
Start a sound and then stop it after 1.2 second:
playSound "AlarmCar"; [] spawn { _sound = ASLToAGL [0,0,0] nearestObject "#soundonvehicle"; sleep 1.2; deleteVehicle _sound; }; // since Arma 3 v2.00 _source = playSound "AlarmCar"; _source spawn { sleep 1.2; deleteVehicle _this; };
Example 3:
Start a sound and wait until it is finished:
playSound "Alarm"; hint "Started!"; [] spawn { _sound = ASLToAGL [0,0,0] nearestObject "#soundonvehicle"; waitUntil {isNull _sound}; hint "Finished!"; }; // since Arma 3 v2.00 _source = playSound "Alarm"; _source spawn { waitUntil {isNull _this}; hint "Finished!"; };

Additional Information

See also:
playSound3D sideRadio say playMusic say2D say3D createSoundSource playSoundUI

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Posted on August 4, 2006 - 10:57
hardrock
Notes from before the conversion: For dialogue involving living units it is better to use say, playSound will play a sound at the location of the player, say will play a sound at the location of the unit that is speaking, and it will only play that sound if the unit is alive.
Posted on December 28, 2014 - 08:22 (UTC)
PiZZADOX
As you may have noticed, the parameter for playsound/say3d that deals with the "volume" of the sound played has little to do with the effective loudness heard in game. What it is alters is the drop off for fading the sound at a distance. A higher decibel or integer value will increase the distance before any sort of fading will take place. The actual volume of the sound file played will factor in to this, as it does throughout the playing action.

Amplifying the Sound

Modifying the effective volume of sounds played by the engine is possible by "spamming" the sounds. By quickly playing the sounds overtop of one another, you can effectively amplify the volume
This example,

playSound "soundname"; playSound "soundname";

Will effectively amplify the sound by a sensed 2x. The volume of the sound file itself will still affect the sound volume as it appears as though the arma engine has no normalization for sound files added to it.

This technique may cause issues in sound quality in large multiplayer servers. I observed multiple instances when a triggered sound amplified with this method was out of sync with each other. Timing of the individual commands sent over the network is probably the issue. Recommend you compile your amplification code into a single finished function for better syncing for clients not activating the action/far away from the activation position.