Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extracted CON read/write for song cache #248

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Assets/Script/Audio/Bass/BassStemMixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public bool SetupMogg(bool isSpeedUp) {
return false;
}

foreach((var stem, int[] channelIndexes) in _moggData.stemMaps) {
foreach((var stem, int[] channelIndexes) in _moggData.StemMaps) {
// For every channel index in this stem, add it to the list of channels
int[] channelStreams = channelIndexes.Select(i => splitStreams[i]).ToArray();
var channel = new BassMoggStem(_manager, stem, channelStreams);
Expand All @@ -87,8 +87,8 @@ public bool SetupMogg(bool isSpeedUp) {
var matrixes = new List<float[]>();
foreach (var channelIndex in channelIndexes) {
var matrix = new float[2];
matrix[0] = _moggData.matrixRatios[channelIndex, 0];
matrix[1] = _moggData.matrixRatios[channelIndex, 1];
matrix[0] = _moggData.MatrixRatios[channelIndex, 0];
matrix[1] = _moggData.MatrixRatios[channelIndex, 1];
matrixes.Add(matrix);
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private IEnumerator StartSong() {
private void LoadChart() {
// Add main file
var files = new List<string> {
song.NotesFile
Path.Combine(song.Location, song.NotesFile)
};

// Look for upgrades and add
Expand All @@ -202,7 +202,7 @@ private void LoadChart() {
MoonSong moonSong = null;
if (song.NotesFile.EndsWith(".chart")) {
Debug.Log("Reading .chart file");
moonSong = ChartReader.ReadChart(Path.Combine(song.Location, song.NotesFile));
moonSong = ChartReader.ReadChart(files[0]);
}

chart = new YargChart(moonSong);
Expand Down
5 changes: 3 additions & 2 deletions Assets/Script/Serialization/Xbox/XboxImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public class XboxImage {
public int Format { get; set; }
public short Width { get; set; }
public short Height { get; set; }
private uint ImgSize;
private uint[] ImgOffsets;
public uint ImgSize { get; }
public uint[] ImgOffsets { get; }

private bool isFromCON = false;

[JsonIgnore]
Expand Down
97 changes: 49 additions & 48 deletions Assets/Script/Serialization/Xbox/XboxMoggData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class XboxMoggData {
public int ChannelCount { get; set; }
public int Header { get; set; }

private uint MoggSize = 0;
private uint[] MoggOffsets = null;
public uint MoggSize { get; }
public uint[] MoggOffsets { get; }

private bool isFromCON = false;

public int MoggAddressAudioOffset { get; set; }
Expand All @@ -30,11 +31,11 @@ public class XboxMoggData {
public float[] PanData { get; set; }
public float[] VolumeData { get; set; }

public Dictionary<string, int[]> tracks;
public int[] crowdChannels;
public Dictionary<string, int[]> Tracks { get; set; }
public int[] CrowdChannels { get; set; }

public Dictionary<SongStem, int[]> stemMaps;
public float[,] matrixRatios;
public Dictionary<SongStem, int[]> StemMaps { get; set; }
public float[,] MatrixRatios { get; set; }

public XboxMoggData(string str) {
MoggPath = str;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void ParseFromDta(DataArray dta) {
switch (dtaArray[0].ToString()) {
case "tracks":
var trackArray = (DataArray) dtaArray[1];
tracks = new Dictionary<string, int[]>();
Tracks = new Dictionary<string, int[]>();

for (int x = 0; x < trackArray.Count; x++) {
if (trackArray[x] is not DataArray instrArray) continue;
Expand All @@ -98,11 +99,11 @@ public void ParseFromDta(DataArray dta) {
val = new int[trackNums.Count];
for (int y = 0; y < trackNums.Count; y++)
val[y] = ((DataAtom) trackNums[y]).Int;
tracks.Add(key, val);
Tracks.Add(key, val);
} else if (instrArray[1] is DataAtom trackNum) {
val = new int[1];
val[0] = trackNum.Int;
tracks.Add(key, val);
Tracks.Add(key, val);
}
}
break;
Expand All @@ -118,17 +119,17 @@ public void ParseFromDta(DataArray dta) {
for (int v = 0; v < volArray.Count; v++) VolumeData[v] = ((DataAtom) volArray[v]).Float;
break;
case "crowd_channels":
crowdChannels = new int[dtaArray.Count - 1];
CrowdChannels = new int[dtaArray.Count - 1];
for (int cc = 1; cc < dtaArray.Count; cc++)
crowdChannels[cc - 1] = ((DataAtom) dtaArray[cc]).Int;
CrowdChannels[cc - 1] = ((DataAtom) dtaArray[cc]).Int;
break;
}
}
}

public override string ToString() {
string debugTrackStr = "";
foreach (var kvp in tracks) {
foreach (var kvp in Tracks) {
debugTrackStr += $"{kvp.Key}, ({string.Join(", ", kvp.Value)}) ";
}

Expand All @@ -142,39 +143,39 @@ public override string ToString() {
}

public void CalculateMoggBassInfo() {
stemMaps = new Dictionary<SongStem, int[]>();
StemMaps = new Dictionary<SongStem, int[]>();
var mapped = new bool[ChannelCount];

// BEGIN BASS Stem Mapping ----------------------------------------------------------------------

if (tracks.TryGetValue("drum", out var drumArray)) {
if (Tracks.TryGetValue("drum", out var drumArray)) {
switch (drumArray.Length) {
//drum (0 1): stereo kit --> (0 1)
case 2:
stemMaps[SongStem.Drums] = new[] { drumArray[0], drumArray[1] };
StemMaps[SongStem.Drums] = new[] { drumArray[0], drumArray[1] };
break;
//drum (0 1 2): mono kick, stereo snare/kit --> (0) (1 2)
case 3:
stemMaps[SongStem.Drums1] = new[] { drumArray[0] };
stemMaps[SongStem.Drums2] = new[] { drumArray[1], drumArray[2] };
StemMaps[SongStem.Drums1] = new[] { drumArray[0] };
StemMaps[SongStem.Drums2] = new[] { drumArray[1], drumArray[2] };
break;
//drum (0 1 2 3): mono kick, mono snare, stereo kit --> (0) (1) (2 3)
case 4:
stemMaps[SongStem.Drums1] = new[] { drumArray[0] };
stemMaps[SongStem.Drums2] = new[] { drumArray[1] };
stemMaps[SongStem.Drums3] = new[] { drumArray[2], drumArray[3] };
StemMaps[SongStem.Drums1] = new[] { drumArray[0] };
StemMaps[SongStem.Drums2] = new[] { drumArray[1] };
StemMaps[SongStem.Drums3] = new[] { drumArray[2], drumArray[3] };
break;
//drum (0 1 2 3 4): mono kick, stereo snare, stereo kit --> (0) (1 2) (3 4)
case 5:
stemMaps[SongStem.Drums1] = new[] { drumArray[0] };
stemMaps[SongStem.Drums2] = new[] { drumArray[1], drumArray[2] };
stemMaps[SongStem.Drums3] = new[] { drumArray[3], drumArray[4] };
StemMaps[SongStem.Drums1] = new[] { drumArray[0] };
StemMaps[SongStem.Drums2] = new[] { drumArray[1], drumArray[2] };
StemMaps[SongStem.Drums3] = new[] { drumArray[3], drumArray[4] };
break;
//drum (0 1 2 3 4 5): stereo kick, stereo snare, stereo kit --> (0 1) (2 3) (4 5)
case 6:
stemMaps[SongStem.Drums1] = new[] { drumArray[0], drumArray[1] };
stemMaps[SongStem.Drums2] = new[] { drumArray[2], drumArray[3] };
stemMaps[SongStem.Drums3] = new[] { drumArray[4], drumArray[5] };
StemMaps[SongStem.Drums1] = new[] { drumArray[0], drumArray[1] };
StemMaps[SongStem.Drums2] = new[] { drumArray[2], drumArray[3] };
StemMaps[SongStem.Drums3] = new[] { drumArray[4], drumArray[5] };
break;
}

Expand All @@ -183,58 +184,58 @@ public void CalculateMoggBassInfo() {
}
}

if (tracks.TryGetValue("bass", out var bassArray)) {
stemMaps[SongStem.Bass] = new int[bassArray.Length];
if (Tracks.TryGetValue("bass", out var bassArray)) {
StemMaps[SongStem.Bass] = new int[bassArray.Length];
for (int i = 0; i < bassArray.Length; i++) {
stemMaps[SongStem.Bass][i] = bassArray[i];
StemMaps[SongStem.Bass][i] = bassArray[i];
mapped[bassArray[i]] = true;
}
}

if (tracks.TryGetValue("guitar", out var gtrArray)) {
stemMaps[SongStem.Guitar] = new int[gtrArray.Length];
if (Tracks.TryGetValue("guitar", out var gtrArray)) {
StemMaps[SongStem.Guitar] = new int[gtrArray.Length];
for (int i = 0; i < gtrArray.Length; i++) {
stemMaps[SongStem.Guitar][i] = gtrArray[i];
StemMaps[SongStem.Guitar][i] = gtrArray[i];
mapped[gtrArray[i]] = true;
}
}

if (tracks.TryGetValue("vocals", out var voxArray)) {
stemMaps[SongStem.Vocals] = new int[voxArray.Length];
if (Tracks.TryGetValue("vocals", out var voxArray)) {
StemMaps[SongStem.Vocals] = new int[voxArray.Length];
for (int i = 0; i < voxArray.Length; i++) {
stemMaps[SongStem.Vocals][i] = voxArray[i];
StemMaps[SongStem.Vocals][i] = voxArray[i];
mapped[voxArray[i]] = true;
}
}

if (tracks.TryGetValue("keys", out var keysArray)) {
stemMaps[SongStem.Keys] = new int[keysArray.Length];
if (Tracks.TryGetValue("keys", out var keysArray)) {
StemMaps[SongStem.Keys] = new int[keysArray.Length];
for (int i = 0; i < keysArray.Length; i++) {
stemMaps[SongStem.Keys][i] = keysArray[i];
StemMaps[SongStem.Keys][i] = keysArray[i];
mapped[keysArray[i]] = true;
}
}

if (crowdChannels != null) {
stemMaps[SongStem.Crowd] = new int[crowdChannels.Length];
for (int i = 0; i < crowdChannels.Length; i++) {
stemMaps[SongStem.Crowd][i] = crowdChannels[i];
mapped[crowdChannels[i]] = true;
if (CrowdChannels != null) {
StemMaps[SongStem.Crowd] = new int[CrowdChannels.Length];
for (int i = 0; i < CrowdChannels.Length; i++) {
StemMaps[SongStem.Crowd][i] = CrowdChannels[i];
mapped[CrowdChannels[i]] = true;
}
}

// every index in mapped that is still false, goes in the backing
var fakeIndices = Enumerable.Range(0, mapped.Length).Where(i => !mapped[i]).ToList();
stemMaps[SongStem.Song] = new int[fakeIndices.Count];
StemMaps[SongStem.Song] = new int[fakeIndices.Count];
for (int i = 0; i < fakeIndices.Count; i++) {
stemMaps[SongStem.Song][i] = fakeIndices[i];
StemMaps[SongStem.Song][i] = fakeIndices[i];
}

// END BASS Stem Mapping ------------------------------------------------------------------------

// BEGIN BASS Matrix calculation ----------------------------------------------------------------

matrixRatios = new float[PanData.Length, 2];
MatrixRatios = new float[PanData.Length, 2];

Parallel.For(0, PanData.Length, i => {
float theta = PanData[i] * ((float) Math.PI / 4);
Expand All @@ -243,8 +244,8 @@ public void CalculateMoggBassInfo() {

float volRatio = (float) Math.Pow(10, VolumeData[i] / 20);

matrixRatios[i, 0] = volRatio * ratioL;
matrixRatios[i, 1] = volRatio * ratioR;
MatrixRatios[i, 0] = volRatio * ratioL;
MatrixRatios[i, 1] = volRatio * ratioR;
});

// END BASS Matrix calculation ------------------------------------------------------------------
Expand Down
Loading