private XGM_HEADER readXGMHeader(BinaryReader hFile) { XGM_HEADER curHead = new XGM_HEADER(); FieldInfo[] fields = typeof(XGM_HEADER).GetFields(); foreach (FieldInfo field in fields) { if (field.FieldType == typeof(uint)) { uint val = hFile.ReadUInt32(); field.SetValue(curHead, val); } else if (field.FieldType == typeof(ushort)) { ushort val = hFile.ReadUInt16(); field.SetValue(curHead, val); } else if (field.FieldType == typeof(char)) { char val = hFile.ReadChar(); field.SetValue(curHead, val); } else if (field.FieldType == typeof(byte)) { byte val = hFile.ReadByte(); field.SetValue(curHead, val); } } return(curHead); }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <returns></returns> private bool openVGMFile(string fileName) { //Read size using (FileStream vgmFile = File.Open(fileName, FileMode.Open)) { var fileSize = (uint)vgmFile.Length; xgmReader = new BinaryReader(vgmFile); uint fccHeader; fccHeader = (uint)xgmReader.ReadUInt32(); if (fccHeader != FCC_VGM) { return(false); } for (int i = 0; i < 63; i++) { ushort adr = xgmReader.ReadUInt16(); ushort sz = xgmReader.ReadUInt16(); if (adr == 0xffff && sz == 0x1) { SampleDataTable[i] = new SampleData(this, 0, 0); } else { SampleDataTable[i] = new SampleData(this, (uint)(adr * 256), (uint)(sz * 256)); } } xgmMHead = readXGMHeader(xgmReader); //read dac dacData = xgmReader.ReadBytes(xgmMHead.shtSampleDataBlkSize * 256); uint mlen = xgmReader.ReadUInt32(); if (mlen < 0) { return(false); } //read vgm vgmData = xgmReader.ReadBytes((int)mlen); xgmReader = new BinaryReader(new MemoryStream(vgmData)); switch (Settings.Default.DCSG_IF) { case 0: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis, (PortId)Settings.Default.DCSG_Port); break; case 1: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_FTDI, (PortId)Settings.Default.DCSG_Port); break; case 2: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.SMS, (PortId)Settings.Default.DCSG_Port); break; case 3: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_Low, (PortId)Settings.Default.DCSG_Port); break; } switch (Settings.Default.OPNA2_IF) { case 0: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis, (PortId)Settings.Default.OPNA2_Port); break; case 1: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_FTDI, (PortId)Settings.Default.OPNA2_Port); break; case 2: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_Low, (PortId)Settings.Default.OPNA2_Port); break; } return(true); } }