private static DdrDatabaseEntry GetOldRecord(DdrPs2MetadataTableEntry item) { var record = item.Data.AsSpan(); var id = Encodings.CP437.GetStringWithoutNulls(record.Slice(0x00, 5)); if (id == string.Empty) { return(null); } return(new DdrDatabaseEntry { Index = item.Index, Id = id, Type = record[0x06], CdTitle = record[0x07], InternalId = Bitter.ToInt16(record, 0x08), MaxBpm = Bitter.ToInt16(record, 0x10), MinBpm = Bitter.ToInt16(record, 0x12), Unknown014 = Bitter.ToInt16(record, 0x14), SonglistOrder = Bitter.ToInt16(record, 0x16), UnlockNumber = Bitter.ToInt16(record, 0x18), Difficulties = new int[0], Flags = Bitter.ToInt32(record, 0x1C), // Radar0 = Bitter.ToInt16Array(record, 0x20, 6), // Radar1 = Bitter.ToInt16Array(record, 0x2C, 6), // Radar2 = Bitter.ToInt16Array(record, 0x38, 6), // Radar3 = Bitter.ToInt16Array(record, 0x44, 6), // Radar4 = Bitter.ToInt16Array(record, 0x50, 6) }); }
public MicrosoftAdpcmFormat(byte[] data) { SamplesPerBlock = Bitter.ToInt16(data, 2); var coefficientCount = Bitter.ToInt16(data, 4); Coefficients = new int[coefficientCount * 2]; for (var i = 0; i < Coefficients.Length; i++) { Coefficients[i] = Bitter.ToInt16(data, 6 + i * 2); } }
public WaveFmtChunk Decode(IRiffChunk chunk) { var data = chunk.Data; return(new WaveFmtChunk { Format = Bitter.ToInt16(data, 0), Channels = Bitter.ToInt16(data, 2), SampleRate = Bitter.ToInt32(data, 4), ByteRate = Bitter.ToInt32(data, 8), BlockAlign = Bitter.ToInt16(data, 12), BitsPerSample = Bitter.ToInt16(data, 14), ExtraData = data.Length > 16 ? data.AsSpan(16).ToArray() : new byte[0] }); }
public IList <DdrDatabaseEntry> Decode(ReadOnlySpan <byte> database) { var offset = 0; var length = database.Length; var result = new List <DdrDatabaseEntry>(); var shortNameOffsets = new Dictionary <int, int>(); var longNameOffsets = new Dictionary <int, int>(); var index = 0; // Read database entries while (offset < length) { var raw = database.Slice(offset, 0x80); var id = Encodings.CP437.GetStringWithoutNulls(raw.Slice(0x00, 5)); if (id == string.Empty) { break; } var entry = new DdrDatabaseEntry { Index = index, Id = id, Type = raw[0x06], CdTitle = raw[0x07], InternalId = Bitter.ToInt16(raw, 0x08), MaxBpm = Bitter.ToInt16(raw, 0x10), MinBpm = Bitter.ToInt16(raw, 0x12), Unknown014 = Bitter.ToInt16(raw, 0x14), SonglistOrder = Bitter.ToInt16(raw, 0x16), UnlockNumber = Bitter.ToInt16(raw, 0x18), Difficulties = new[] { raw[0x1C] & 0xF, raw[0x1C] >> 4, raw[0x1D] & 0xF, raw[0x1D] >> 4, raw[0x20] & 0xF, raw[0x20] >> 4, raw[0x21] & 0xF, raw[0x21] >> 4, }, Unknown01E = Bitter.ToInt16(raw, 0x1E), Unknown022 = Bitter.ToInt16(raw, 0x22), Flags = Bitter.ToInt32(raw, 0x24), Radar0 = Bitter.ToInt16Array(raw, 0x28, 8), Radar1 = Bitter.ToInt16Array(raw, 0x38, 8), Radar2 = Bitter.ToInt16Array(raw, 0x48, 8), Radar3 = Bitter.ToInt16Array(raw, 0x58, 8), Radar4 = Bitter.ToInt16Array(raw, 0x68, 8) }; longNameOffsets[index] = Bitter.ToInt32(raw, 0x78); shortNameOffsets[index] = Bitter.ToInt32(raw, 0x7C); result.Add(entry); offset += 0x80; index++; } offset += 0x80; // Read string table var strings = database.Slice(offset); foreach (var kv in longNameOffsets) { result[kv.Key].LongName = Encodings.CP437.GetStringWithoutNulls(strings.Slice(kv.Value)); } foreach (var kv in shortNameOffsets) { result[kv.Key].ShortName = Encodings.CP437.GetStringWithoutNulls(strings.Slice(kv.Value)); } return(result); }
private static DdrDatabaseEntry GetNewRecord(DdrPs2MetadataTableEntry records) { var record = records.Data.AsSpan(); var id = Encodings.CP437.GetStringWithoutNulls(record.Slice(0x00, 5)); var mdbIndex = 0; var difficultyOffset = 0; int[] difficulties; if (id == string.Empty) { return(null); } var bpmOffset = 0; var isXDifficulties = Bitter.ToInt16(record, 0x06) == Bitter.ToInt16(record, 0x08) && record.Slice(0x25, 10).ToArray().All(x => x <= 20) && record.Slice(0x25, 10).ToArray().Any(x => x != 0x00); if (isXDifficulties) { mdbIndex = Bitter.ToInt16(record, 0x08); bpmOffset += 0x0C; } else { if (Bitter.ToInt16(record, 0x10) != 0 && Bitter.ToInt16(record, 0x12) == 0) { if (record[0x06] == 0x05 && Bitter.ToInt16(record, 0x08) == Bitter.ToInt16(record, 0x0A)) { // SN JP, SN US, SN2 US mdbIndex = Bitter.ToInt16(record, 0x0C); bpmOffset += 0x10; difficultyOffset += 0x10; } else { // SN2 JP mdbIndex = Bitter.ToInt16(record, 0x08); bpmOffset += 0x0C; } } if (Bitter.ToInt32(record, 0x14 + bpmOffset) != -1) { // SN, SN2 while (Bitter.ToInt32(record, 0x10 + bpmOffset) == 0) { bpmOffset += 4; difficultyOffset += 4; } } if (bpmOffset > 0) { while (Bitter.ToInt32(record, 0x24 + difficultyOffset) == 0) { difficultyOffset += 4; } } } if (isXDifficulties) { difficulties = new[] { record[0x26], record[0x27], record[0x28], record[0x29], record[0x25], 0, 0, 0, record[0x2B], record[0x2C], record[0x2D], record[0x2E], record[0x2A], 0, 0, 0, }; } else { difficulties = new[] { record[0x24 + difficultyOffset] & 0xF, record[0x24 + difficultyOffset] >> 4, record[0x25 + difficultyOffset] & 0xF, record[0x25 + difficultyOffset] >> 4, record[0x26 + difficultyOffset] & 0xF, record[0x26 + difficultyOffset] >> 4, record[0x27 + difficultyOffset] & 0xF, record[0x27 + difficultyOffset] >> 4, record[0x28 + difficultyOffset] & 0xF, record[0x28 + difficultyOffset] >> 4, record[0x29 + difficultyOffset] & 0xF, record[0x29 + difficultyOffset] >> 4, record[0x2A + difficultyOffset] & 0xF, record[0x2A + difficultyOffset] >> 4, record[0x2B + difficultyOffset] & 0xF, record[0x2B + difficultyOffset] >> 4 }; } return(new DdrDatabaseEntry { Index = records.Index, Id = id, Type = record[0x06], CdTitle = record[0x07], InternalId = Bitter.ToInt16(record, 0x08), MaxBpm = Bitter.ToInt16(record, 0x10 + bpmOffset), MinBpm = Bitter.ToInt16(record, 0x12 + bpmOffset), Unknown014 = Bitter.ToInt16(record, 0x14 + bpmOffset), SonglistOrder = Bitter.ToInt16(record, 0x16 + bpmOffset), UnlockNumber = Bitter.ToInt16(record, 0x18 + bpmOffset), Difficulties = difficulties, Flags = Bitter.ToInt32(record, 0x2C + difficultyOffset), AudioTrack = mdbIndex // Radar0 = Bitter.ToInt16Array(record, 0x30, 6), // Radar1 = Bitter.ToInt16Array(record, 0x3C, 6), // Radar2 = Bitter.ToInt16Array(record, 0x48, 6), // Radar3 = Bitter.ToInt16Array(record, 0x54, 6), // Radar4 = Bitter.ToInt16Array(record, 0x60, 6) }); }
public ImaAdpcmFormat(byte[] data) { SamplesPerBlock = Bitter.ToInt16(data, 2); }