initial commit

This commit is contained in:
what 2021-07-26 13:04:16 -07:00
commit 1b60743303
274 changed files with 25866 additions and 0 deletions

View file

@ -0,0 +1,44 @@
// Decompiled with JetBrains decompiler
// Type: SEGATools.Audio.AudioConversionSettings
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
// MVID: D631183F-57B1-40A1-B502-5364D288307A
// Assembly location: SEGATools.dll
namespace SEGATools.Audio
{
public class AudioConversionSettings
{
public bool RemovePause { get; private set; }
public short PauseDurationInSeconds => this.RemovePause ? (short) 2 : (short) 0;
public int SamplingRate { get; private set; }
public short BitsPerSample => 16;
public short NumberOfChannels { get; private set; }
private AudioConversionSettings(int SamplingRate, short NumberOfChannels, bool RemovePause)
{
this.SamplingRate = SamplingRate;
this.NumberOfChannels = NumberOfChannels;
this.RemovePause = RemovePause;
}
public static AudioConversionSettings defaultAudioConvOptions() => new AudioConversionSettings(44100, (short) 2, false);
public static AudioConversionSettings newStereoPCMSettings(
int SamplingRate,
bool RemovePause)
{
return new AudioConversionSettings(SamplingRate, (short) 2, RemovePause);
}
public static AudioConversionSettings newMonoPCMSettings(
int SamplingRate,
bool RemovePause)
{
return new AudioConversionSettings(SamplingRate, (short) 1, RemovePause);
}
}
}

View file

@ -0,0 +1,151 @@
// Decompiled with JetBrains decompiler
// Type: SEGATools.Audio.AudioConversionSettingsViewer
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
// MVID: D631183F-57B1-40A1-B502-5364D288307A
// Assembly location: SEGATools.dll
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace SEGATools.Audio
{
public class AudioConversionSettingsViewer : UserControl
{
private List<AudioConversionSettingsViewer.SamplingRateItem> samplingRates = new List<AudioConversionSettingsViewer.SamplingRateItem>();
private IContainer components;
private FlowLayoutPanel flowLayoutPanel;
private Label lbSamplingRate;
private ComboBox cbSamplingRate;
private CheckBox cbRemovePause;
[RefreshProperties(RefreshProperties.Repaint)]
[NotifyParentProperty(true)]
[Category("Appearance")]
[Description("Specifies whether the remove pause checkbox is visible.")]
[DefaultValue(typeof (bool), "true")]
public bool ShowRemovePause
{
get => this.cbRemovePause.Visible;
set => this.cbRemovePause.Visible = value;
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool RemovePause => this.cbRemovePause.Checked;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public int SamplingRate => int.Parse(this.cbSamplingRate.SelectedItem.ToString());
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public AudioConversionSettings AudioConversionSettings
{
get => AudioConversionSettings.newStereoPCMSettings((int) this.cbSamplingRate.SelectedValue, this.cbRemovePause.Checked);
set
{
this.cbSamplingRate.SelectedItem = (object) this.samplingRates.Find((Predicate<AudioConversionSettingsViewer.SamplingRateItem>) (samplingRate => samplingRate.Value == value.SamplingRate));
this.cbRemovePause.Checked = value.RemovePause;
}
}
public AudioConversionSettingsViewer()
{
this.InitializeComponent();
this.samplingRates.Add(new AudioConversionSettingsViewer.SamplingRateItem(16000));
this.samplingRates.Add(new AudioConversionSettingsViewer.SamplingRateItem(44100));
this.samplingRates.Add(new AudioConversionSettingsViewer.SamplingRateItem(48000));
this.cbSamplingRate.DataSource = (object) this.samplingRates;
this.cbSamplingRate.DisplayMember = AudioConversionSettingsViewer.SamplingRateItem.DisplayMember;
this.cbSamplingRate.ValueMember = AudioConversionSettingsViewer.SamplingRateItem.ValueMember;
this.cbSamplingRate.SelectedItem = (object) this.samplingRates.Find((Predicate<AudioConversionSettingsViewer.SamplingRateItem>) (samplingRate => samplingRate.Value == 44100));
this.cbSamplingRate.Enabled = false;
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.flowLayoutPanel = new FlowLayoutPanel();
this.lbSamplingRate = new Label();
this.cbSamplingRate = new ComboBox();
this.cbRemovePause = new CheckBox();
this.flowLayoutPanel.SuspendLayout();
this.SuspendLayout();
this.flowLayoutPanel.AutoScroll = true;
this.flowLayoutPanel.AutoSize = true;
this.flowLayoutPanel.BackColor = Color.Transparent;
this.flowLayoutPanel.Controls.Add((Control) this.lbSamplingRate);
this.flowLayoutPanel.Controls.Add((Control) this.cbSamplingRate);
this.flowLayoutPanel.Controls.Add((Control) this.cbRemovePause);
this.flowLayoutPanel.Dock = DockStyle.Fill;
this.flowLayoutPanel.Location = new Point(0, 0);
this.flowLayoutPanel.Name = "flowLayoutPanel";
this.flowLayoutPanel.Size = new Size(325, 28);
this.flowLayoutPanel.TabIndex = 0;
this.lbSamplingRate.AutoSize = true;
this.lbSamplingRate.Location = new Point(3, 3);
this.lbSamplingRate.Margin = new Padding(3);
this.lbSamplingRate.Name = "lbSamplingRate";
this.lbSamplingRate.Size = new Size(79, 13);
this.lbSamplingRate.TabIndex = 9;
this.lbSamplingRate.Text = "Sampling Rate:";
this.lbSamplingRate.TextAlign = ContentAlignment.BottomLeft;
this.cbSamplingRate.FormattingEnabled = true;
this.cbSamplingRate.Items.AddRange(new object[2]
{
(object) "44100",
(object) "48000"
});
this.cbSamplingRate.Location = new Point(85, 0);
this.cbSamplingRate.Margin = new Padding(0);
this.cbSamplingRate.Name = "cbSamplingRate";
this.cbSamplingRate.Size = new Size(75, 21);
this.cbSamplingRate.TabIndex = 10;
this.cbRemovePause.AutoSize = true;
this.cbRemovePause.CheckAlign = ContentAlignment.MiddleRight;
this.cbRemovePause.Enabled = false;
this.cbRemovePause.Location = new Point(163, 3);
this.cbRemovePause.Name = "cbRemovePause";
this.cbRemovePause.Size = new Size(150, 17);
this.cbRemovePause.TabIndex = 11;
this.cbRemovePause.Text = "Remove 2-seconds pause";
this.cbRemovePause.UseVisualStyleBackColor = true;
this.AutoScaleDimensions = new SizeF(6f, 13f);
this.AutoScaleMode = AutoScaleMode.Font;
this.BackColor = Color.Transparent;
this.Controls.Add((Control) this.flowLayoutPanel);
this.Name = nameof (AudioConversionSettingsViewer);
this.Size = new Size(325, 28);
this.flowLayoutPanel.ResumeLayout(false);
this.flowLayoutPanel.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
internal sealed class SamplingRateItem
{
public static string DisplayMember => "Name";
public static string ValueMember => "Value";
public int Value { get; set; }
public string Name { get; set; }
public SamplingRateItem(int SamplingRate)
{
this.Name = SamplingRate.ToString() + "Hz";
this.Value = SamplingRate;
}
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -0,0 +1,98 @@
// Decompiled with JetBrains decompiler
// Type: SEGATools.Audio.CanonicalWaveHeader
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
// MVID: D631183F-57B1-40A1-B502-5364D288307A
// Assembly location: SEGATools.dll
using System;
namespace SEGATools.Audio
{
internal class CanonicalWaveHeader
{
private const short HEADERSIZE = 44;
private const int _chunkID = 1179011410;
private const int _remainingSize = 20;
private const int _format = 1163280727;
private const int _subChunk1ID = 544501094;
private const int _subChunk1Size = 16;
private const short _audioFormat = 1;
private const int _subChunk2ID = 1635017060;
private int _subChunk2Size;
private bool sampleDataInitialized;
public short Size => 44;
public int ChunkID => 1179011410;
public int ChunkSize => 36 + this.SubChunk2Size;
public int Format => 1163280727;
public int SubChunk1ID => 544501094;
public int SubChunk1Size => 16;
public short AudioFormat => 1;
public short NumberOfChannels { get; private set; }
public int SampleRate { get; private set; }
public int ByteRate => this.SampleRate * (int) this.NumberOfChannels * ((int) this.BitsPerSample / 8);
public short BlockAlign => (short) ((int) this.NumberOfChannels * ((int) this.BitsPerSample / 8));
public short BitsPerSample { get; private set; }
public int SubChunk2ID => 1635017060;
public int SubChunk2Size
{
get => this._subChunk2Size;
set
{
this._subChunk2Size = value;
this.sampleDataInitialized = true;
}
}
public CanonicalWaveHeader(
short numberOfChannels,
int sampleRate,
short bitsPerSample,
int? sampleDataSize)
{
this.NumberOfChannels = numberOfChannels;
this.SampleRate = sampleRate;
this.BitsPerSample = bitsPerSample;
if (!sampleDataSize.HasValue)
return;
this.sampleDataInitialized = true;
this.SubChunk2Size = sampleDataSize.Value;
}
public byte[] ToByteArray()
{
if (!this.sampleDataInitialized)
throw new UninitialiedSampleDataSizeException("Sample data size (SubChunk2Size property) has not been initialied.");
byte[] numArray = new byte[44];
BitConverter.GetBytes(this.ChunkID).CopyTo((Array) numArray, 0);
BitConverter.GetBytes(this.ChunkSize).CopyTo((Array) numArray, 4);
BitConverter.GetBytes(this.Format).CopyTo((Array) numArray, 8);
BitConverter.GetBytes(this.SubChunk1ID).CopyTo((Array) numArray, 12);
BitConverter.GetBytes(this.SubChunk1Size).CopyTo((Array) numArray, 16);
BitConverter.GetBytes(this.AudioFormat).CopyTo((Array) numArray, 20);
BitConverter.GetBytes(this.NumberOfChannels).CopyTo((Array) numArray, 22);
BitConverter.GetBytes(this.SampleRate).CopyTo((Array) numArray, 24);
BitConverter.GetBytes(this.ByteRate).CopyTo((Array) numArray, 28);
BitConverter.GetBytes(this.BlockAlign).CopyTo((Array) numArray, 32);
BitConverter.GetBytes(this.BitsPerSample).CopyTo((Array) numArray, 34);
BitConverter.GetBytes(this.SubChunk2ID).CopyTo((Array) numArray, 36);
BitConverter.GetBytes(this.SubChunk2Size).CopyTo((Array) numArray, 40);
return numArray;
}
public static CanonicalWaveHeader FromByteArray(byte[] headerArray) => new CanonicalWaveHeader(BitConverter.ToInt16(headerArray, 22), BitConverter.ToInt32(headerArray, 24), BitConverter.ToInt16(headerArray, 34), new int?(BitConverter.ToInt32(headerArray, 40)));
}
}

View file

@ -0,0 +1,142 @@
// Decompiled with JetBrains decompiler
// Type: SEGATools.Audio.Raw2WavConverter
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
// MVID: D631183F-57B1-40A1-B502-5364D288307A
// Assembly location: SEGATools.dll
using SEGATools.UserProcess;
using SEGATools.VirtualFile;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
namespace SEGATools.Audio
{
public class Raw2WavConverter : UserProcessBase
{
private static readonly int BUFFER_SIZE = 524288;
public AudioConversionSettings AudioConversionSettings { get; set; }
public event AsyncOperationProgressChangedEventHandler ConversionProgressChanged
{
add => this.AsyncOperationProgressChanged += value;
remove => this.AsyncOperationProgressChanged -= value;
}
public event AsyncOperationCompletedEventHandler ConversionCompleted
{
add => this.AsyncOperationCompleted += value;
remove => this.AsyncOperationCompleted -= value;
}
public Raw2WavConverter() => this.AudioConversionSettings = AudioConversionSettings.defaultAudioConvOptions();
public Raw2WavConverter(IContainer container)
: base(container)
=> this.AudioConversionSettings = AudioConversionSettings.defaultAudioConvOptions();
public void ConvertAsync(IList<IVirtualFile> InputFiles, string outputPath, object taskId)
{
AsyncOperation asyncOperation = this.CreateAsyncOperation(taskId);
new Raw2WavConverter.WorkerEventHandler(this.ConvertRaw2WavWorker).BeginInvoke(InputFiles, outputPath, asyncOperation, (AsyncCallback) null, (object) null);
}
private void ConvertRaw2WavWorker(
IList<IVirtualFile> inputFiles,
string outputPath,
AsyncOperation asyncOp)
{
long TotalNumberOfBytesToWrite = 0;
Exception exception = (Exception) null;
foreach (IVirtualFile inputFile in (IEnumerable<IVirtualFile>) inputFiles)
TotalNumberOfBytesToWrite += this.ComputeAudioStreamLength(inputFile.FileInputStream, this.AudioConversionSettings.PauseDurationInSeconds);
long TotalNumberOfBytesRemainingToWrite = TotalNumberOfBytesToWrite;
try
{
foreach (IVirtualFile inputFile in (IEnumerable<IVirtualFile>) inputFiles)
{
if (!this.TaskCanceled(asyncOp))
{
IVirtualFile OutputFile = inputFiles.Count != 1 ? (IVirtualFile) VirtualFileFactory.createVirtualFile(Path.Combine(outputPath, Path.GetFileName(Path.ChangeExtension(inputFile.VirtualName, ".wav")))) : (IVirtualFile) VirtualFileFactory.createVirtualFile(outputPath);
TotalNumberOfBytesRemainingToWrite = this.ConvertStream(inputFile, OutputFile, TotalNumberOfBytesRemainingToWrite, TotalNumberOfBytesToWrite, asyncOp);
}
else
break;
}
}
catch (Exception ex)
{
exception = ex;
}
this.ReportCompletion(outputPath, exception, asyncOp);
}
private long ComputeAudioStreamLength(System.IO.Stream AudioStream, short NumberOfSecondToSubtrack) => AudioStream.Length - (long) ((int) this.AudioConversionSettings.NumberOfChannels * this.AudioConversionSettings.SamplingRate * ((int) this.AudioConversionSettings.BitsPerSample / 8) * (int) NumberOfSecondToSubtrack);
private void GenerateWaveHeader(
BinaryReader InputFileReader,
BinaryWriter OutputFileWriter,
out long BytesToWrite)
{
BytesToWrite = this.ComputeAudioStreamLength(InputFileReader.BaseStream, this.AudioConversionSettings.PauseDurationInSeconds);
CanonicalWaveHeader canonicalWaveHeader = new CanonicalWaveHeader(this.AudioConversionSettings.NumberOfChannels, this.AudioConversionSettings.SamplingRate, this.AudioConversionSettings.BitsPerSample, new int?((int) BytesToWrite));
OutputFileWriter.Write(canonicalWaveHeader.ToByteArray());
}
private long ConvertStream(
IVirtualFile InputFile,
IVirtualFile OutputFile,
long TotalNumberOfBytesRemainingToWrite,
long TotalNumberOfBytesToWrite,
AsyncOperation asyncOp)
{
long num = 0;
long BytesToWrite = 0;
using (BinaryReader InputFileReader = new BinaryReader(InputFile.FileInputStream))
{
using (BinaryWriter OutputFileWriter = new BinaryWriter(OutputFile.FileOutputStream))
{
this.GenerateWaveHeader(InputFileReader, OutputFileWriter, out BytesToWrite);
num = BytesToWrite;
while (num > 0L)
{
if (!this.TaskCanceled(asyncOp))
{
byte[] buffer = num <= (long) Raw2WavConverter.BUFFER_SIZE ? InputFileReader.ReadBytes((int) num) : InputFileReader.ReadBytes(Raw2WavConverter.BUFFER_SIZE);
OutputFileWriter.Write(buffer);
num -= (long) buffer.Length;
TotalNumberOfBytesRemainingToWrite -= (long) buffer.Length;
int progressPercentage = (int) ((double) (BytesToWrite - num) / (double) BytesToWrite * 100.0);
int totalProgressPercentage = (int) ((double) (TotalNumberOfBytesToWrite - TotalNumberOfBytesRemainingToWrite) / (double) TotalNumberOfBytesToWrite * 100.0);
this.ReportProgress(new UserProcessProgressChangedEventArgs(InputFile.VirtualName, OutputFile.OriginalFileName, progressPercentage, totalProgressPercentage, asyncOp.UserSuppliedState), asyncOp);
}
else
break;
}
}
}
if (num == 0L)
{
if (!this.TaskCanceled(asyncOp))
goto label_16;
}
try
{
File.Delete(OutputFile.OriginalFileName);
}
catch (Exception ex)
{
UserProcessBase.logger.ErrorFormat("Unable to delete the file {0}: {1}", (object) OutputFile, (object) ex.Message);
}
label_16:
return TotalNumberOfBytesRemainingToWrite;
}
private delegate void WorkerEventHandler(
IList<IVirtualFile> InputFiles,
string OutputPath,
AsyncOperation asyncOp);
}
}

View file

@ -0,0 +1,18 @@
// Decompiled with JetBrains decompiler
// Type: SEGATools.Audio.UninitialiedSampleDataSizeException
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
// MVID: D631183F-57B1-40A1-B502-5364D288307A
// Assembly location: SEGATools.dll
using System;
namespace SEGATools.Audio
{
internal class UninitialiedSampleDataSizeException : Exception
{
public UninitialiedSampleDataSizeException(string message)
: base(message)
{
}
}
}