Skip to content

Commit

Permalink
Change mogg loading stuff (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
RileyTheFox authored May 8, 2023
1 parent 1930fa6 commit a5e12c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
16 changes: 12 additions & 4 deletions Assets/Script/Audio/Bass/BassAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,26 @@ public void LoadSong(ICollection<string> stems, bool isSpeedUp) {
IsAudioLoaded = true;
}

public void LoadMogg(byte[] moggArray,
Dictionary<SongStem, int[]> stemMaps, float[,] matrixRatios, bool isSpeedUp) {
public void LoadMogg(ExtractedConSongEntry exConSong, bool isSpeedUp) {
Debug.Log("Loading mogg song");
UnloadSong();

byte[] moggArray;

if (exConSong is ConSongEntry conSong) {
moggArray = XboxCONInnerFileRetriever.RetrieveFile(conSong.Location, conSong.MoggPath,
conSong.MoggFileSize, conSong.MoggFileMemBlockOffsets)[conSong.MoggAddressAudioOffset..];
} else {
moggArray = File.ReadAllBytes(exConSong.MoggPath)[exConSong.MoggAddressAudioOffset..];
}

int moggStreamHandle = Bass.CreateStream(moggArray, 0, moggArray.Length, BassFlags.Prescan | BassFlags.Decode | BassFlags.AsyncFile);
if (moggStreamHandle == 0) {
Debug.LogError($"Failed to load mogg file or position: {Bass.LastError}");
return;
}

_mixer = new BassStemMixer(this, moggStreamHandle, stemMaps, matrixRatios);
_mixer = new BassStemMixer(this, moggStreamHandle, exConSong.StemMaps, exConSong.MatrixRatios);
if (!_mixer.Create()) {
throw new Exception($"Failed to create mixer: {Bass.LastError}");
}
Expand Down Expand Up @@ -244,7 +252,7 @@ public void UnloadSong() {

public void LoadPreviewAudio(SongEntry song) {
if (song is ExtractedConSongEntry conSong) {
LoadMogg(conSong.MoggInfo, false);
LoadMogg(conSong, false);
} else {
LoadSong(AudioHelpers.GetSupportedStems(song.Location), false);
}
Expand Down
3 changes: 1 addition & 2 deletions Assets/Script/Audio/Interfaces/IAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public interface IAudioManager {
public void LoadSfx();

public void LoadSong(ICollection<string> stems, bool isSpeedUp);
// public void LoadMogg(XboxMoggData moggData, bool isSpeedUp);
public void LoadMogg(byte[] moggArray, Dictionary<SongStem, int[]> stemMaps, float[,] matrixRatios, bool isSpeedUp);
public void LoadMogg(ExtractedConSongEntry exConSong, bool isSpeedUp);
public void UnloadSong();

public void LoadPreviewAudio(SongEntry song);
Expand Down
10 changes: 1 addition & 9 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,7 @@ private void StartSong() {
if (song is ExtractedConSongEntry rawConSongEntry) {
Debug.Log(rawConSongEntry.MatrixRatios.GetLength(0));

GameManager.AudioManager.LoadMogg(File.ReadAllBytes(rawConSongEntry.MoggPath)[rawConSongEntry.MoggAddressAudioOffset..],
rawConSongEntry.StemMaps, rawConSongEntry.MatrixRatios, isSpeedUp);
}
else if(song is ConSongEntry conSongEntry){
Debug.Log(conSongEntry.MatrixRatios.GetLength(0));

GameManager.AudioManager.LoadMogg(XboxCONInnerFileRetriever.RetrieveFile(conSongEntry.Location, conSongEntry.MoggPath,
conSongEntry.MoggFileSize, conSongEntry.MoggFileMemBlockOffsets)[conSongEntry.MoggAddressAudioOffset..],
conSongEntry.StemMaps, conSongEntry.MatrixRatios, isSpeedUp);
GameManager.AudioManager.LoadMogg(rawConSongEntry, isSpeedUp);
}
else {
var stems = AudioHelpers.GetSupportedStems(song.Location);
Expand Down

0 comments on commit a5e12c6

Please sign in to comment.