Thread Tools Display Modes
03/11/23, 05:39 AM   #1
mirrorman009
Join Date: Jun 2021
Posts: 2
Changing sound volume

Hi,

I would like to temporarily change the volume of a played sound in my addon. From https://wiki.esoui.com/Sounds I can apparently do this by:

You can also play with volume by modifying audio settings before playing your sound (settingId = AUDIO_SETTING_UI_VOLUME)


Forgive my newb-ness, but how do I change this settingId? Is it just an additional parameter to the PlaySound call?

Thanks for any help,
Mirrorman
  Reply With Quote
03/11/23, 05:52 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
If you just want to change the volume of that 1 sound just call PlaySound with the same parameters more than once. It will get louder that way but that does not work with all sounds of the SOUNDS table! So you need to test it.

Lua Code:
  1. PlaySound(SOUNDS.VOLUME_DING_ALL)
  2. PlaySound(SOUNDS.VOLUME_DING_ALL) --should make it 2times as loud as normal
  3. PlaySound(SOUNDS.VOLUME_DING_ALL) --should make it 3times as loud as normal

About your question with the settings:
Changing the overall sound volume will affect ALL sounds played and other effects too so it might make your whole game be loud, not only that 1 sound
If you want to achieve this you need to use the GetSetting* and SetSetting* API functions to set/get the correct category and index in that category.
There should be one category constant for the audio settings e.g. and then different index constants for the volumes.
You can fidn those at the vailla source code, where the settings menu is build:

https://github.com/esoui/esoui/blob/...shared.lua#L11

If I'm not wrong the main category(or system) would be SETTING_TYPE_AUDIO and the index AUDIO_SETTING_AUDIO_VOLUME

Code:
--- @param system [SettingSystemType|#SettingSystemType]
--- @param settingId integer
--- @param value string
--- @param setOptions [SetOptions|#SetOptions]
--- @return void
function SetSetting(system, settingId, value, setOptions) end

--- @param system [SettingSystemType|#SettingSystemType]
--- @param settingId integer
--- @return value string
function GetSetting(system, settingId) end

--- @param system [SettingSystemType|#SettingSystemType]
--- @param settingId integer
--- @return value bool
function GetSetting_Bool(system, settingId) end
Afaik the value you pass in to SetSetting must be a string! So convert the value you want to set via tostring(valueToSet)
and if you use GetSetting convert that value with tonumber(GetSetting(SETTING_TYPE_AUDIO, AUDIO_SETTING_AUDIO_VOLUME)) so you can do mathematics with it properly (allthough lua should accept mathematics with string numbers too I guess :-) )

Last edited by Baertram : 03/11/23 at 05:59 AM.
  Reply With Quote
03/11/23, 08:04 AM   #3
mirrorman009
Join Date: Jun 2021
Posts: 2
@Baertram, thanks very much! Your repeating the PlaySound command worked for what I needed. Now back to listening to all 500 or so sounds to find the one that I want!
  Reply With Quote
03/12/23, 04:01 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
Install merTorchbug, ingame type /tb and click on the Sounds tab. Clicking a row will play it as preview.

Is your want the user to choose a sound and your addon uses LibAddonMenu for settings, try the LibAddonMenu SoundSlider widget. You can choose a sound there and let it preview upon selection.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Changing sound volume

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off