A nearly dependency-free package for custom positional sounds.
Built with WEB AUDIO API
PREVIEW
·
Report Bug
·
Request Feature
Table of Contents
It started as test project to understand scripting for gta-server more. Since I didn't find any resources that feature a real 3d sound, I've started creating my own resource.
I tried my best to make it as simple as possible for potential user of this resource.
You might experience some "crackling" but it should not be the norm. That crackling is a chromium bug that is under investigation: https://bugs.chromium.org/p/chromium/issues/detail?id=1242647 I've tested a lot and with all the background noises of the game, I've heared very little crackings that weren't that loud.
If you have bigger issue with that cracklings than I'm sorry to say that you have to wait for a bugfix.
- Positional sound
- Positional sound attached to an entity.
- Server-side created sounds are time-synced on every client
- create and use custom Filter/Effects
- Underwater effect
- If the sound source and/or the listener are underwater the sound gets muffled
You have an idea? Submit it here.
- Take a look into the release section and download the newest version of sounity
- Unzip the Zip-file in your resource folder
- Add `ensure sounity" to your server.cfg
- Play sounds
Basic example of using this library. For a detailed list of all methods scroll down to #API
-- create a sound instance
local soundId = exports.sounity:CreateSound("URL TO MP3 nui:// supported!", json.encode({
posX = 3,
posY = 5,
posZ = 8,
}));
-- start playback of that sound
exports.sounity:StartSound(soundId);
-- create a sound instance
local soundId = exports.sounity:CreateSound("URL TO MP3 nui:// supported!");
-- attach it to the player ped
local ped = GetPlayerPed(source);
local pedId = NetworkGetNetworkIdFromEntity(ped);
exports.sounity:AttachSound(soundId, pedId)
-- start playback of that sound
exports.sounity:StartSound(soundId);
The API is nearly identical on server and client.
The biggest difference is, that on client side there is no sync to other players.
For the most cases I recommend a server side usage.
All Methods are available through exports
Creates a new sound instance and returns the sound's identifier.
name(key) | description | possible values | default value |
---|---|---|---|
volume |
Defines volume in percent | positive numbers |
1 |
outputType |
Choose which volume setting will be used | 'sfx' | 'music' |
'sfx' |
loop |
If true the sound will repeat until you stop it | bool |
false |
posX |
position on x axis | float |
0 |
posY |
position on y axis | float |
0 |
posZ |
position on z axis | float |
0 |
rotX |
rotation on x axis | float |
0 |
rotY |
rotation on y axis | float |
0 |
rotZ |
rotation on z axis | float |
0 |
panningModel |
defines the spatialisation algorithm read more here | 'equalpower' | 'HRTF' |
'HRTF' |
distanceModel |
defines the algorithm reducing the volume on distance read more here | 'linear' | 'inverse' | 'exponential' |
'inverse' |
maxDistance |
this value is only used by the linear distanceModel read more here | positive numbers |
500 |
refDistance |
this value is used by all distance models read more here | positive numbers |
3 |
rolloffFactor |
this value is used by all distance models read more here | on linear: 0-1, others: 0-INFINITY |
1 |
coneInnerAngle |
inner angle of sound without sound reduction here | float (degree) |
360 |
coneOuterAngle |
outer angle with a volume set to a defined constant here | float (degree) |
0 |
coneOuterGain |
volume in outer angle (0 means no sound at all) here | 0-1 |
0 |
Starts the playback of a sound
Set a new location for a sound This does not work if an entity is attached!
Set a orientation for a sound This does not work if an entity is attached!
Stops playback of a sound
Attachs a sound to an entity
Detachs a sound from an entity
Destroys a sound
[CLIENT ONLY] CreateFilter(filterName: string, filterType: 'biquad' | 'convolver', options: json_string)
Create a filter with a unique name.
You can choose between a biquad filter or a convolver filter.
Biquad is a low-order filter. The options are identical to the official documentation
A more complex filter type is the convolver. This filter is often used to get a reverb-effect. You need a impulse-response file.
- url: string
- url to impulse response
- disableNormalization: bool
- A boolean value controlling whether the impulse response from the buffer will be scaled by an equal-power normalization, or not. The default is 'false'.
Add a filter to a sound
Remove a filter from a sound
Add filter to listener. (Global Filter on client)
Remove filter from listener.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.