Thread Tools Display Modes
10-31-10, 04:26 AM   #1
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Playing sounds at unique volume levels (theory)

Two API: PlayMusic() StopMusic()

Using the "music" track for addon sounds? i.e. set all to 25% and this to 100% to distinct certain events.

Prototype:
lua Code:
  1. local frames = {}
  2. local function Create()
  3.     local f
  4.     for i=1, 10 do -- create 10 frames
  5.         f = CreateFrame("Frame")
  6.         f:Hide()
  7.         f:SetScript("OnShow", function(self)
  8.             if not self.sound or not self.len then return end
  9.             SetCVar("musicVolume", self.volume or 1)
  10.             StopMusic()
  11.             PlayMusic(self.sound)
  12.         end)
  13.         f:SetScript("OnUpdate", function(self, elapsed)
  14.             if not self.sound or not self.len then return end
  15.             self.elapsed = (self.elapsed or 0) + elapsed
  16.             if self.elapsed >= self.len then
  17.                 StopMusic()
  18.                 self.sound = nil
  19.                 self.len = nil
  20.                 self.volume = nil
  21.                 self.elapsed = nil
  22.                 self:Hide()
  23.             end
  24.         end)
  25.         table.insert(frames, f)
  26.     end
  27. end
  28. local function GetAvailable()
  29.     for _,f in pairs(frames) do
  30.         if not f.sound and not f.len then
  31.             return f
  32.         end
  33.     end
  34. end
  35. local function GetSoundFileLength(sound)
  36.     local len = 0
  37.     -- NYI
  38.     return len
  39. end
  40. local function PlaySoundFile2(sound, volume)
  41.     local f = GetAvailable()
  42.     f.sound = sound
  43.     f.len = GetSoundFileLength(sound)
  44.     f.volume = volume
  45.     f:Show()
  46. end
  47. local function SetVolumeSettings()
  48.     -- Init. volume settings so the music channel trick works and that normal music is not playing
  49. end

Using PlaySoundFile2("1.mp3", 0.5) will store the sound, len and volume int othe frame and Show it. The onShow will from there set the music volume cvar, stop the last sound and play the current one. The OnUpdate will handle stopping the music when the sound expires, clear the temp variables and hide the frame to avoid OnUpdate performance instability.

The only problem is the GetSoundFileLength part as the game has no way of knowing how long a sound is, but for things like announcements one could run the game where sound effects and such are on 25% while the music is at 100% (and turn off the in-game music so it does not bother you). Now when a sound is played on the music channel it's louder than any other sound. Only instability is that it loops if not stopped (it is in this addon) and that it can not play multiple music files at once so it's pointless for anything but announcements that do not occur too often -perhaps something Bossmods should incorporate.
  Reply With Quote
10-31-10, 04:33 AM   #2
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Is this suggested as a workaround for the current bug with PlaySound()-volume not being independent from the Sound-volume setting (as prior to 4.0.1)?
__________________
Oh, the simulated horror!
  Reply With Quote
10-31-10, 04:42 AM   #3
eberkain
A Fallenroot Satyr
Join Date: Nov 2009
Posts: 20
unless you need to dynamically change the volume of what you are playing in-gem, wouldn't it just be easier to change the volume of the sound recording its self at this point?
  Reply With Quote
10-31-10, 05:06 AM   #4
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Originally Posted by eberkain View Post
unless you need to dynamically change the volume of what you are playing in-gem, wouldn't it just be easier to change the volume of the sound recording its self at this point?
This is more as a suggestion to be able to play specific sounds even if the player removes all normal game sounds by setting the volume to 0. I've given to understand that the PlayMusic works on the "Music" volume control yet not affected by the unchecking of "Play Music" box, i.e. you can mute the game music and use the music channel for custom sounds only played by PlayMusic.

Fixes the problem when in-game sounds are too loud but you wish to hear for example boss talk -one could make a mod to play the boss voices over this channel instead (they usually don't play more than one sound at a time -PlayMusic would have problems playing multiple files at once too).
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Playing sounds at unique volume levels (theory)

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