From 5f053d9442187f788793c1719b343ea5d79de55f Mon Sep 17 00:00:00 2001 From: Joshua Navarro Date: Sat, 5 Jan 2019 00:55:44 -0800 Subject: [PATCH] Added vorbis/ogg support to Stardew Symphony --- .../Framework/Music/WavMusicPack.cs | 40 +++++++++++++----- .../StardewSymphonyRemastered.csproj | 42 +++++++++++++++---- .../StardewSymphonyRemastered/manifest.json | 2 +- .../StardewSymphonyRemastered/packages.config | 4 ++ 4 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/packages.config diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs index 2ca2c286..15d70755 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Xna.Framework.Audio; +using NAudio.Vorbis; using NAudio.Wave; using StardewValley; @@ -87,41 +88,58 @@ namespace StardewSymphonyRemastered.Framework { List wavFiles = Directory.GetFiles(this.songsDirectory, "*.wav").ToList(); wavFiles.AddRange(Directory.GetFiles(this.songsDirectory, "*.mp3")); + wavFiles.AddRange(Directory.GetFiles(this.songsDirectory, "*.ogg")); DateTime span = DateTime.Now; foreach (string wav in wavFiles) { - MemoryStream memoryStream = new MemoryStream(); - AudioFileReader fileReader = new AudioFileReader(wav); - fileReader.CopyTo(memoryStream); - byte[] wavData = memoryStream.ToArray(); - SoundEffect eff = null; Stream waveFileStream = File.OpenRead(wav); //TitleContainer.OpenStream(file); + if (wav.Contains(".wav")) + { eff = SoundEffect.FromStream(waveFileStream); + waveFileStream.Close(); + } else if (wav.Contains(".mp3")) { using (Mp3FileReader reader = new Mp3FileReader(waveFileStream)) { - using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader)) + using (WaveStream pcmMP3Stream = WaveFormatConversionStream.CreatePcmStream(reader)) { - StardewSymphony.ModMonitor.Log("MP3 CONVERT! " + Path.GetFileNameWithoutExtension(wav) + ".wav"); - WaveFileWriter.CreateWaveFile(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav")), pcmStream); + StardewSymphony.DebugLog("Converting: " + this.songsDirectory + Path.GetFileName(wav)); + WaveFileWriter.CreateWaveFile(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav")), pcmMP3Stream); - waveFileStream = File.OpenRead((Path.GetFileNameWithoutExtension(wav) + ".wav")); //TitleContainer.OpenStream(file); + waveFileStream = File.OpenRead(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav"))); //TitleContainer.OpenStream(file); eff = SoundEffect.FromStream(waveFileStream); + waveFileStream.Close(); File.Delete(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav"))); } } } else if (wav.Contains(".ogg")) { - StardewSymphony.ModMonitor.Log("Sorry, but .ogg files are currently not supported. Keep bugging the mod author (me) for this if you want it!", StardewModdingAPI.LogLevel.Alert); - continue; + + //Credits: https://social.msdn.microsoft.com/Forums/vstudio/en-US/100a97af-2a1c-4b28-b464-d43611b9b5d6/converting-multichannel-ogg-to-stereo-wav-file?forum=csharpgeneral + + using (VorbisWaveReader vorbisStream = new VorbisWaveReader(wav)) + { + + StardewSymphony.DebugLog("Converting: " + this.songsDirectory+Path.GetFileName(wav)); + WaveFileWriter.CreateWaveFile(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav")), vorbisStream.ToWaveProvider16()); + + //WaveFileReader reader = new WaveFileReader(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav"))); + + waveFileStream = File.OpenRead(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav"))); //TitleContainer.OpenStream(file); + eff = SoundEffect.FromStream(waveFileStream); + + waveFileStream.Close(); + + File.Delete(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav"))); + } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj index d9fef139..e043e023 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,6 +11,8 @@ StardewSymphonyRemastered v4.5 512 + + true @@ -66,10 +68,18 @@ MinimumRecommendedRules.ruleset - - - - + + ..\..\..\..\..\..\..\..\Desktop\NAudio.dll + + + ..\..\..\..\..\..\..\..\Desktop\NAudioVorbis\NAudio.Vorbis\obj\Debug\NAudio.Vorbis.dll + + + ..\..\..\..\..\..\..\..\Desktop\NAudioVorbis\bin\NVorbis.dll + + + ..\..\StardustCore\bin\Release\StardustCore.dll + @@ -213,6 +223,7 @@ Always + @@ -233,11 +244,24 @@ - - {0756d36a-95c8-480d-8ea6-4584c03010c6} - StardustCore - + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json index 131da877..84679222 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json @@ -1,7 +1,7 @@ { "Name": "Stardew Symphony Remastered", "Author": "Alpha_Omegasis", - "Version": "2.2.0", + "Version": "2.3.0", "Description": "Adding more music to the game one beep at a time. Now with streaming!", "UniqueID": "Omegasis.StardewSymphonyRemastered", "EntryDll": "StardewSymphonyRemastered.dll", diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/packages.config b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/packages.config new file mode 100644 index 00000000..af793ad3 --- /dev/null +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file