Got wav music packs working! Just need to figure out the buffer size for the files now.

This commit is contained in:
2018-03-21 00:46:00 -07:00
parent 1bbf3f2503
commit def22386c5
3 changed files with 22 additions and 5 deletions

View File

@ -127,6 +127,7 @@ namespace StardewSymphonyRemastered.Framework.Menus
{
var info=(KeyValuePair<string, MusicPack>)param[0];
StardewSymphony.ModMonitor.Log(info.ToString());
StardewSymphony.musicManager.swapMusicPacks(info.Key);
StardewSymphony.musicManager.playRandomSongFromPack(info.Key);
//info.Value.playRandomSong();
}

View File

@ -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
/// <returns></returns>
public static MusicPackMetaData readFromJson(string path)
{
var meta=StardewSymphony.ModHelper.ReadJsonFile<MusicPackMetaData>(path);
try
{
meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper, meta.pathToMusicPackIcon + ".png");
}
catch(Exception err)
{
}
return StardewSymphony.ModHelper.ReadJsonFile<MusicPackMetaData>(path);
}

View File

@ -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<EventArgs>(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
/// </summary>
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<EventArgs>(DynamicSound_BufferNeeded);
dynamicSound = null;
this.currentSong = null;
position = 0;
count = 0;
byteArray = new byte[0];
}
}