From def22386c586027a66568cbe3b935ef90e7a87c4 Mon Sep 17 00:00:00 2001 From: Date: Wed, 21 Mar 2018 00:46:00 -0700 Subject: [PATCH] Got wav music packs working! Just need to figure out the buffer size for the files now. --- .../Framework/Menus/MusicManagerMenu.cs | 1 + .../Framework/Music/MusicPackMetaData.cs | 11 ++++++++++- .../Framework/Music/WavMusicPack.cs | 15 +++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs index 17471024..d4432779 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs @@ -127,6 +127,7 @@ namespace StardewSymphonyRemastered.Framework.Menus { var info=(KeyValuePair)param[0]; StardewSymphony.ModMonitor.Log(info.ToString()); + StardewSymphony.musicManager.swapMusicPacks(info.Key); StardewSymphony.musicManager.playRandomSongFromPack(info.Key); //info.Value.playRandomSong(); } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs index dbea8807..be44030e 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs @@ -36,7 +36,7 @@ namespace StardewSymphonyRemastered.Framework this.pathToMusicPackIcon = PathToMusicPackIcon; try { - this.Icon = new Texture2DExtended(StardewSymphony.ModHelper, this.pathToMusicPackIcon); + this.Icon = new Texture2DExtended(StardewSymphony.ModHelper, this.pathToMusicPackIcon+".png"); } catch(Exception err) { @@ -59,6 +59,15 @@ namespace StardewSymphonyRemastered.Framework /// public static MusicPackMetaData readFromJson(string path) { + var meta=StardewSymphony.ModHelper.ReadJsonFile(path); + try + { + meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper, meta.pathToMusicPackIcon + ".png"); + } + catch(Exception err) + { + + } return StardewSymphony.ModHelper.ReadJsonFile(path); } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs index a1f665be..07dd897a 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs @@ -112,7 +112,7 @@ namespace StardewSymphonyRemastered.Framework byteArray = reader.ReadBytes(dataSize); dynamicSound = new DynamicSoundEffectInstance(sampleRate, (AudioChannels)channels); - count = dynamicSound.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(100)); + count = dynamicSound.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(10000)); dynamicSound.BufferNeeded += new EventHandler(DynamicSound_BufferNeeded); this.currentSong = new Song(p); @@ -120,8 +120,9 @@ namespace StardewSymphonyRemastered.Framework void DynamicSound_BufferNeeded(object sender, EventArgs e) { - dynamicSound.SubmitBuffer(byteArray, position, count / 2); - dynamicSound.SubmitBuffer(byteArray, position + count / 2, count / 2); + dynamicSound.SubmitBuffer(byteArray, position, count); + //dynamicSound.SubmitBuffer(byteArray); + //dynamicSound.SubmitBuffer(byteArray, position + count / 2, count / 2); position += count; if (position + count > byteArray.Length) @@ -197,11 +198,17 @@ namespace StardewSymphonyRemastered.Framework /// public override void stopSong() { + if (Game1.currentSong != null) Game1.currentSong.Stop(AudioStopOptions.Immediate); + if (this.currentSong == null) return; if (dynamicSound != null) { - dynamicSound.Stop(); + dynamicSound.Stop(true); + dynamicSound.BufferNeeded -= new EventHandler(DynamicSound_BufferNeeded); dynamicSound = null; this.currentSong = null; + position = 0; + count = 0; + byteArray = new byte[0]; } }