Volume of sounds attached through trigger dialog

Posted by Seriley on Tue 01 Jun 2010 03:52 PM — 3 posts, 15,181 views.

#0
Is there a way to adjust the default volume of these sounds? I know I could always use PlaySound in a script to do this. I would like to continue to attach sounds to triggers in the manner provided.
Australia Forum Administrator #1
There is no direct way, as the trigger-based sounds were developed long before I had heard about DirectSound.

However if you just want to play all sounds more quietly, the plugin below will do it:

Template:saveplugin=Sound_Volume_Reducer
To save and install the Sound_Volume_Reducer plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as Sound_Volume_Reducer.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Sound_Volume_Reducer.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Sound_Volume_Reducer"
   author="Nick Gammon"
   id="b1308ed1e6d5e4facdaf7bdd"
   language="Lua"
   purpose="Plays trigger sounds more quietly"
   date_written="2010-06-02 06:33:40"
   requires="4.40"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Install this to play trigger sounds at reduced volume.
]]>
</description>

</plugin>


<!--  Script  -->


<script>
<![CDATA[
function OnPluginPlaySound (sound)
  PlaySound (0, sound, false, -12)  -- play supplied sound 12 db softer
end -- function

]]>
</script>


</muclient>


That detects attempts to play sounds and plays the same file itself 12 db more softly (obviously you can change the -12 to something else).

If you want to play individual sounds in different ways (eg. some more softly than others, or some from the left speaker and some from the right speaker) then you could use string.match (or a simple test for string equal) on the file name, and choose your volume level from a table lookup.

For example:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Sound_Volume_Reducer"
   author="Nick Gammon"
   id="b1308ed1e6d5e4facdaf7bdd"
   language="Lua"
   purpose="Plays trigger sounds more quietly"
   date_written="2010-06-02 06:33:40"
   requires="4.40"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Install this to play trigger sounds at reduced volume.
]]>
</description>

</plugin>


<!--  Script  -->


<script>
<![CDATA[

volumes = {
  ["west"] = { volume = -6, pan = -100} ,
  ["east"] = { volume = -15, pan = 100} ,

  -- add more here

  }  -- end of volumes table
  
function OnPluginPlaySound (sound)

  -- defaults
  local volume = -12
  local pan = 0
  
  -- search file name for a keyword that affects its volume
  for k, v in pairs (volumes) do
    if string.match (sound, k) then
      volume = v.volume
      pan = v.pan
      break
    end -- if matched part of sound name
  end -- for
  
  PlaySound (0, sound, false, volume, pan)  -- play supplied sound as required
end -- function

]]>
</script>


</muclient>


In this case a sound with the word "east" in its filename will be played from the right speaker at -15 db, and a sound with the word "west" in its name will be played at -6 db from the left speaker. Other sounds will be played at -12 db centered.
Amended on Tue 01 Jun 2010 08:54 PM by Nick Gammon
#2
Many thanks, Nick.