Open KiwifruitDev opened 5 months ago
In order to make the sound be marked as a "music" track, it must be non directional. i.e.:
local BackgroundMusic = CreateSound(game.GetWorld(), "#music/hl2_song29.mp3")
BackgroundMusic:SetSoundLevel(0)
// BackgroundMusic:SetDSP(1)
BackgroundMusic:Play()
I am not sure it is worth the effort to look into the DSP issue, as sounds marked as music are not meant to support DSPs anyway.
Details
When attempting to create a clientside
CSoundPatch
object that can utilize the "Music volume" setting, I tried using the "#" soundscript character.This did not work, instead it made the audio play faster with artifacting.
Audio Information
kiwifruitdev/kiwi_f1_menu/memories.mp3
is located in thesound
folder of a local addon.It plays for
6:55
, and has a size of6.32 MB
.The stats below were given by VLC media player:
Code
The code below was re-formatted for readability:
Original Code
The code below is simplified but retains the original variable structure: ```lua KIWI_F1_MENU = {} KIWI_F1_MENU.CONVARS = {} KIWI_F1_MENU.CONVARS.BackgroundMusic = CreateClientConVar("kiwi_f1_menu_bgm", "1", true, false, "Should the background music be enabled?", 0, 1) KIWI_F1_MENU.MUSIC = {"kiwifruitdev/kiwi_f1_menu/memories.mp3"} KIWI_F1_MENU.CONST = {} KIWI_F1_MENU.CONST.DSP = 1 KIWI_F1_MENU.CONST.FadeTime = 0.8 KIWI_F1_MENU.VARIABLES = {} KIWI_F1_MENU.VARIABLES.LocalPlayer = LocalPlayer() KIWI_F1_MENU.VARIABLES.MusicExtension = table.Copy(KIWI_F1_MENU.MUSIC) -- Start playback KIWI_F1_MENU.VARIABLES.BackgroundMusic = CreateSound(KIWI_F1_MENU.VARIABLES.LocalPlayer, "#"..table.Random(KIWI_F1_MENU.VARIABLES.MusicExtension)) KIWI_F1_MENU.VARIABLES.BackgroundMusic:SetDSP(KIWI_F1_MENU.CONST.DSP) if KIWI_F1_MENU.CONVARS.BackgroundMusic:GetBool() then KIWI_F1_MENU.VARIABLES.BackgroundMusic:Play() end -- End playback if KIWI_F1_MENU.VARIABLES.BackgroundMusic then if KIWI_F1_MENU.VARIABLES.BackgroundMusic:IsPlaying() and KIWI_F1_MENU.CONVARS.BackgroundMusic:GetBool() then KIWI_F1_MENU.VARIABLES.BackgroundMusic:FadeOut(KIWI_F1_MENU.CONST.FadeTime) else KIWI_F1_MENU.VARIABLES.BackgroundMusic:Stop() end end ```Demonstration
The audio is played and stopped when this menu opens and closes:
Video
[demonstration.webm](https://github.com/Facepunch/garrysmod-issues/assets/25839651/918982cc-e20f-464a-819f-9105b94e1ef9)Version
Here is what the
version
command reports: