some random code cleanup on BizHawk.Emulation.DiscSystem

This commit is contained in:
adelikat 2013-11-15 00:49:19 +00:00
parent 030f30628d
commit 00308de99a
10 changed files with 55 additions and 48 deletions

View File

@ -31,9 +31,9 @@ using BizHawk.Common;
namespace BizHawk.Emulation.DiscSystem namespace BizHawk.Emulation.DiscSystem
{ {
partial class Disc sealed partial class Disc
{ {
class Blob_ECM : IBlob private class Blob_ECM : IBlob
{ {
FileStream stream; FileStream stream;
@ -44,7 +44,7 @@ namespace BizHawk.Emulation.DiscSystem
stream = null; stream = null;
} }
class IndexEntry private class IndexEntry
{ {
public int Type; public int Type;
public uint Number; public uint Number;

View File

@ -8,6 +8,7 @@ namespace BizHawk.Emulation.DiscSystem
{ {
class Blob_WaveFile : IBlob class Blob_WaveFile : IBlob
{ {
[Serializable]
public class Blob_WaveFile_Exception : Exception public class Blob_WaveFile_Exception : Exception
{ {
public Blob_WaveFile_Exception(string message) public Blob_WaveFile_Exception(string message)

View File

@ -2,7 +2,6 @@
using System.IO; using System.IO;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.DiscSystem;
// The state of the cd player is quantized to the frame level. // The state of the cd player is quantized to the frame level.
// This isn't ideal. But life's too short. // This isn't ideal. But life's too short.
@ -42,7 +41,7 @@ namespace BizHawk.Emulation.DiscSystem
public int CurrentSector, SectorOffset; // Offset is in SAMPLES, not bytes. Sector is 588 samples long. public int CurrentSector, SectorOffset; // Offset is in SAMPLES, not bytes. Sector is 588 samples long.
int CachedSector; int CachedSector;
byte[] SectorCache = new byte[2352]; readonly byte[] SectorCache = new byte[2352];
public int FadeOutOverFrames = 0; public int FadeOutOverFrames = 0;
public int FadeOutFramesRemaining = 0; public int FadeOutFramesRemaining = 0;

View File

@ -53,8 +53,7 @@ namespace BizHawk.Emulation.DiscSystem
{ {
//TODO - add cue directory to CueBinPrefs???? could make things cleaner... //TODO - add cue directory to CueBinPrefs???? could make things cleaner...
var session = new DiscTOC.Session(); var session = new DiscTOC.Session {num = 1};
session.num = 1;
TOC.Sessions.Add(session); TOC.Sessions.Add(session);
var pregap_sector = new Sector_Zero(); var pregap_sector = new Sector_Zero();
@ -254,8 +253,7 @@ namespace BizHawk.Emulation.DiscSystem
bool is_last_index = index == num_indexes - 1; bool is_last_index = index == num_indexes - 1;
//install index into hierarchy //install index into hierarchy
var toc_index = new DiscTOC.Index(); var toc_index = new DiscTOC.Index {num = index};
toc_index.num = index;
toc_track.Indexes.Add(toc_index); toc_track.Indexes.Add(toc_index);
if (index == 0) if (index == 0)
{ {
@ -310,9 +308,11 @@ namespace BizHawk.Emulation.DiscSystem
{ {
//ECM needs to know the sector number so we have to record that here //ECM needs to know the sector number so we have to record that here
int curr_disc_aba = Sectors.Count; int curr_disc_aba = Sectors.Count;
var sector_2048 = new Sector_Mode1_2048(curr_disc_aba + 150); var sector_2048 = new Sector_Mode1_2048(curr_disc_aba + 150)
sector_2048.Blob = new ECMCacheBlob(cue_blob); {
sector_2048.Offset = blob_cursor; Blob = new ECMCacheBlob(cue_blob),
Offset = blob_cursor
};
blob_cursor += 2048; blob_cursor += 2048;
Sectors.Add(new SectorEntry(sector_2048)); Sectors.Add(new SectorEntry(sector_2048));
break; break;
@ -472,6 +472,7 @@ namespace BizHawk.Emulation.DiscSystem
public Timestamp Timestamp; public Timestamp Timestamp;
} }
[Serializable]
public class CueBrokenException : Exception public class CueBrokenException : Exception
{ {
public CueBrokenException(string why) public CueBrokenException(string why)
@ -576,9 +577,10 @@ namespace BizHawk.Emulation.DiscSystem
if (indexnum < 0 || indexnum > 99) throw new CueBrokenException("`All index numbers must be between 0 and 99 inclusive.`"); if (indexnum < 0 || indexnum > 99) throw new CueBrokenException("`All index numbers must be between 0 and 99 inclusive.`");
if (indexnum != 1 && indexnum != last_index_num + 1) throw new CueBrokenException("`The first index must be 0 or 1 with all other indexes being sequential to the first one.`"); if (indexnum != 1 && indexnum != last_index_num + 1) throw new CueBrokenException("`The first index must be 0 or 1 with all other indexes being sequential to the first one.`");
last_index_num = indexnum; last_index_num = indexnum;
CueTrackIndex cti = new CueTrackIndex(indexnum); CueTrackIndex cti = new CueTrackIndex(indexnum)
cti.Timestamp = new Timestamp(str_timestamp); {
cti.IndexNum = indexnum; Timestamp = new Timestamp(str_timestamp), IndexNum = indexnum
};
currTrack.Indexes[indexnum] = cti; currTrack.Indexes[indexnum] = cti;
break; break;
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -16,12 +17,12 @@ namespace BizHawk.Emulation.DiscSystem
public bool IsAudio; public bool IsAudio;
} }
static string[] Escape(string[] args) private static string[] Escape(IEnumerable<string> args)
{ {
return args.Select(s => s.Contains(" ") ? string.Format("\"{0}\"", s) : s).ToArray(); return args.Select(s => s.Contains(" ") ? string.Format("\"{0}\"", s) : s).ToArray();
} }
static Regex rxHasAudio = new Regex(@"Stream \#(\d*\.\d*)\: Audio", RegexOptions.Compiled); static readonly Regex rxHasAudio = new Regex(@"Stream \#(\d*\.\d*)\: Audio", RegexOptions.Compiled);
public AudioQueryResult QueryAudio(string path) public AudioQueryResult QueryAudio(string path)
{ {
var ret = new AudioQueryResult(); var ret = new AudioQueryResult();
@ -56,11 +57,13 @@ namespace BizHawk.Emulation.DiscSystem
if (i != args.Length - 1) sbCmdline.Append(' '); if (i != args.Length - 1) sbCmdline.Append(' ');
} }
ProcessStartInfo oInfo = new ProcessStartInfo(FFMpegPath, sbCmdline.ToString()); ProcessStartInfo oInfo = new ProcessStartInfo(FFMpegPath, sbCmdline.ToString())
oInfo.UseShellExecute = false; {
oInfo.CreateNoWindow = true; UseShellExecute = false,
oInfo.RedirectStandardOutput = true; CreateNoWindow = true,
oInfo.RedirectStandardError = true; RedirectStandardOutput = true,
RedirectStandardError = true
};
Process proc = Process.Start(oInfo); Process proc = Process.Start(oInfo);
string result = proc.StandardError.ReadToEnd(); string result = proc.StandardError.ReadToEnd();
@ -89,6 +92,7 @@ namespace BizHawk.Emulation.DiscSystem
class AudioDecoder class AudioDecoder
{ {
[Serializable]
public class AudioDecoder_Exception : Exception public class AudioDecoder_Exception : Exception
{ {
public AudioDecoder_Exception(string message) public AudioDecoder_Exception(string message)
@ -130,7 +134,9 @@ namespace BizHawk.Emulation.DiscSystem
if (Path.GetFileNameWithoutExtension(fi.FullName).ToUpper() == basePath.ToUpper()) if (Path.GetFileNameWithoutExtension(fi.FullName).ToUpper() == basePath.ToUpper())
{ {
if (CheckForAudio(fi.FullName)) if (CheckForAudio(fi.FullName))
{
return fi.FullName; return fi.FullName;
}
} }
} }
return null; return null;
@ -143,8 +149,7 @@ namespace BizHawk.Emulation.DiscSystem
{ {
throw new AudioDecoder_Exception("Could not find source audio for: " + Path.GetFileName(audioPath)); throw new AudioDecoder_Exception("Could not find source audio for: " + Path.GetFileName(audioPath));
} }
FFMpeg ffmpeg = new FFMpeg(); return new FFMpeg().DecodeAudio(path);
return ffmpeg.DecodeAudio(path);
} }
} }

View File

@ -7,6 +7,7 @@ using BizHawk.Common;
namespace BizHawk.Emulation.DiscSystem namespace BizHawk.Emulation.DiscSystem
{ {
[Serializable]
public class DiscReferenceException : Exception public class DiscReferenceException : Exception
{ {
public DiscReferenceException(string fname, Exception inner) public DiscReferenceException(string fname, Exception inner)
@ -136,7 +137,7 @@ namespace BizHawk.Emulation.DiscSystem
public override void Write(byte[] buffer, int offset, int count) { throw new NotImplementedException(); } public override void Write(byte[] buffer, int offset, int count) { throw new NotImplementedException(); }
} }
public partial class Disc sealed public partial class Disc
{ {
/// <summary> /// <summary>
/// Main API to read a 2352-byte sector from a disc. /// Main API to read a 2352-byte sector from a disc.

View File

@ -37,7 +37,7 @@ namespace BizHawk.Emulation.DiscSystem
TurboCD TurboCD
} }
public partial class Disc sealed public partial class Disc
{ {
/// <summary> /// <summary>
/// Attempts to determine the type of the disc. /// Attempts to determine the type of the disc.

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
@ -97,7 +96,7 @@ namespace BizHawk.Emulation.DiscSystem
int Read(long byte_pos, byte[] buffer, int offset, int count); int Read(long byte_pos, byte[] buffer, int offset, int count);
} }
public class Blob_ZeroPadAdapter : IBlob public sealed class Blob_ZeroPadAdapter : IBlob
{ {
public Blob_ZeroPadAdapter(IBlob baseBlob, long padFrom, long padLen) public Blob_ZeroPadAdapter(IBlob baseBlob, long padFrom, long padLen)
{ {
@ -152,15 +151,18 @@ namespace BizHawk.Emulation.DiscSystem
baseBlob.Dispose(); baseBlob.Dispose();
} }
IBlob baseBlob; private readonly IBlob baseBlob;
long padFrom; private long padFrom;
long padLen; private long padLen;
} }
class Blob_RawFile : IBlob private class Blob_RawFile : IBlob
{ {
public string PhysicalPath { public string PhysicalPath {
get { return physicalPath; } get
{
return physicalPath;
}
set set
{ {
physicalPath = value; physicalPath = value;
@ -319,7 +321,7 @@ namespace BizHawk.Emulation.DiscSystem
static byte[] TempSector = new byte[2352]; static byte[] TempSector = new byte[2352];
} }
protected static byte BCD_Byte(byte val) private static byte BCD_Byte(byte val)
{ {
byte ret = (byte)(val % 10); byte ret = (byte)(val % 10);
ret += (byte)(16 * (val / 10)); ret += (byte)(16 * (val / 10));
@ -481,13 +483,13 @@ namespace BizHawk.Emulation.DiscSystem
void FromIsoPathInternal(string isoPath) void FromIsoPathInternal(string isoPath)
{ {
//make a fake cue file to represent this iso file //make a fake cue file to represent this iso file
string isoCueWrapper = @" const string isoCueWrapper = @"
FILE ""xarp.barp.marp.farp"" BINARY FILE ""xarp.barp.marp.farp"" BINARY
TRACK 01 MODE1/2048 TRACK 01 MODE1/2048
INDEX 01 00:00:00 INDEX 01 00:00:00
"; ";
string cueDir = ""; string cueDir = String.Empty;
var cue = new Cue(); var cue = new Cue();
CueFileResolver["xarp.barp.marp.farp"] = isoPath; CueFileResolver["xarp.barp.marp.farp"] = isoPath;
cue.LoadFromString(isoCueWrapper); cue.LoadFromString(isoCueWrapper);
@ -542,8 +544,7 @@ FILE ""xarp.barp.marp.farp"" BINARY
{ {
//this is the preferred mode of dumping things. we will always write full sectors. //this is the preferred mode of dumping things. we will always write full sectors.
string cue = TOC.GenerateCUE_OneBin(prefs); string cue = TOC.GenerateCUE_OneBin(prefs);
var bfd = new CueBin.BinFileDescriptor(); var bfd = new CueBin.BinFileDescriptor {name = baseName + ".bin"};
bfd.name = baseName + ".bin";
ret.cue = string.Format("FILE \"{0}\" BINARY\n", bfd.name) + cue; ret.cue = string.Format("FILE \"{0}\" BINARY\n", bfd.name) + cue;
ret.bins.Add(bfd); ret.bins.Add(bfd);
bfd.SectorSize = 2352; bfd.SectorSize = 2352;
@ -563,9 +564,11 @@ FILE ""xarp.barp.marp.farp"" BINARY
for (int i = 0; i < TOC.Sessions[0].Tracks.Count; i++) for (int i = 0; i < TOC.Sessions[0].Tracks.Count; i++)
{ {
var track = TOC.Sessions[0].Tracks[i]; var track = TOC.Sessions[0].Tracks[i];
var bfd = new CueBin.BinFileDescriptor(); var bfd = new CueBin.BinFileDescriptor
bfd.name = baseName + string.Format(" (Track {0:D2}).bin", track.num); {
bfd.SectorSize = Cue.BINSectorSizeForTrackType(track.TrackType); name = baseName + string.Format(" (Track {0:D2}).bin", track.num),
SectorSize = Cue.BINSectorSizeForTrackType(track.TrackType)
};
ret.bins.Add(bfd); ret.bins.Add(bfd);
int aba = 0; int aba = 0;
@ -740,9 +743,7 @@ FILE ""xarp.barp.marp.farp"" BINARY
/// </summary> /// </summary>
public static BCD2 FromDecimal(int d) public static BCD2 FromDecimal(int d)
{ {
BCD2 ret = new BCD2(); return new BCD2 {DecimalValue = d};
ret.DecimalValue = d;
return ret;
} }
@ -769,7 +770,7 @@ FILE ""xarp.barp.marp.farp"" BINARY
/// </summary> /// </summary>
public Timestamp(string value) public Timestamp(string value)
{ {
this.Value = value; Value = value;
MIN = int.Parse(value.Substring(0, 2)); MIN = int.Parse(value.Substring(0, 2));
SEC = int.Parse(value.Substring(3, 2)); SEC = int.Parse(value.Substring(3, 2));
FRAC = int.Parse(value.Substring(6, 2)); FRAC = int.Parse(value.Substring(6, 2));

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.DiscSystem namespace BizHawk.Emulation.DiscSystem

View File

@ -66,7 +66,7 @@ namespace BizHawk.Emulation.DiscSystem
// Px ^= (long)bit << (i + j); // Px ^= (long)bit << (i + j);
// } // }
//uint edc_poly = (uint)Px; //uint edc_poly = (uint)Px;
uint edc_poly = (uint)0x8001801B; const uint edc_poly = 0x8001801B;
//generate the CRC table //generate the CRC table
uint reverse_edc_poly = Bitrev.reverse_32(edc_poly); uint reverse_edc_poly = Bitrev.reverse_32(edc_poly);