Add MP3 extract option to DiscoHawk
This commit is contained in:
parent
46e06d5e59
commit
8556906f2c
|
@ -0,0 +1,67 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using BizHawk.DiscSystem;
|
||||||
|
using WaveLibrary;
|
||||||
|
using System.IO;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace BizHawk
|
||||||
|
{
|
||||||
|
class AudioExtractor
|
||||||
|
{
|
||||||
|
public static string FFmpegPath;
|
||||||
|
|
||||||
|
public static void Extract(Disc disc, string path, string filebase)
|
||||||
|
{
|
||||||
|
var tracks = disc.TOC.Sessions[0].Tracks;
|
||||||
|
foreach (var track in tracks)
|
||||||
|
{
|
||||||
|
if (track.TrackType != ETrackType.Audio)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var wave = new WaveFile(2, 16, 44100);
|
||||||
|
var waveData = new byte[track.length_aba * 2352];
|
||||||
|
int startLba = track.Indexes[1].LBA;
|
||||||
|
for (int sector = 0; sector < track.length_aba; sector++)
|
||||||
|
disc.ReadLBA_2352(startLba + sector, waveData, sector * 2352);
|
||||||
|
|
||||||
|
wave.SetData(waveData, waveData.Length / 4);
|
||||||
|
string waveFilePath = Path.Combine(path, "__temp.wav");
|
||||||
|
wave.WriteFile(waveFilePath);
|
||||||
|
|
||||||
|
Encode(waveFilePath, string.Format("{0} - Track {1:D2}.mp3", Path.Combine(path, filebase), track.num));
|
||||||
|
|
||||||
|
File.Delete(waveFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Encode(string wavePath, string mp3Path)
|
||||||
|
{
|
||||||
|
var args = Escape("-i", wavePath, "-ab", "192k", mp3Path);
|
||||||
|
|
||||||
|
StringBuilder sbCmdline = new StringBuilder();
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
sbCmdline.Append(args[i]);
|
||||||
|
if (i != args.Length - 1) sbCmdline.Append(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessStartInfo oInfo = new ProcessStartInfo(FFmpegPath, sbCmdline.ToString());
|
||||||
|
oInfo.UseShellExecute = false;
|
||||||
|
oInfo.CreateNoWindow = true;
|
||||||
|
oInfo.RedirectStandardOutput = true;
|
||||||
|
oInfo.RedirectStandardError = true;
|
||||||
|
|
||||||
|
Process proc = System.Diagnostics.Process.Start(oInfo);
|
||||||
|
proc.WaitForExit();
|
||||||
|
string result = proc.StandardError.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
static string[] Escape(params string[] args)
|
||||||
|
{
|
||||||
|
return args.Select(s => s.Contains(" ") ? string.Format("\"{0}\"", s) : s).ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,9 @@ namespace BizHawk
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
DiscSystem.FFMpeg.FFMpegPath = Path.Combine(GetExeDirectoryAbsolute(), "ffmpeg.exe");
|
var ffmpegPath = Path.Combine(GetExeDirectoryAbsolute(), "ffmpeg.exe");
|
||||||
|
DiscSystem.FFMpeg.FFMpegPath = ffmpegPath;
|
||||||
|
AudioExtractor.FFmpegPath = ffmpegPath;
|
||||||
new DiscoHawk().Run(args);
|
new DiscoHawk().Run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="AudioExtractor.cs" />
|
||||||
<Compile Include="DiscoHawk.cs" />
|
<Compile Include="DiscoHawk.cs" />
|
||||||
<Compile Include="DiscoHawkDialog.cs">
|
<Compile Include="DiscoHawkDialog.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
|
@ -92,6 +93,10 @@
|
||||||
<Compile Include="ProgressDialog.Designer.cs">
|
<Compile Include="ProgressDialog.Designer.cs">
|
||||||
<DependentUpon>ProgressDialog.cs</DependentUpon>
|
<DependentUpon>ProgressDialog.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Wave\WavedataSubChunk.cs" />
|
||||||
|
<Compile Include="Wave\WaveFile.cs" />
|
||||||
|
<Compile Include="Wave\WavefmtSubChunk.cs" />
|
||||||
|
<Compile Include="Wave\WaveHeader.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
@ -136,14 +141,6 @@
|
||||||
<Project>{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}</Project>
|
<Project>{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}</Project>
|
||||||
<Name>BizHawk.Emulation</Name>
|
<Name>BizHawk.Emulation</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\BizHawk.MultiClient\BizHawk.MultiClient.csproj">
|
|
||||||
<Project>{DD448B37-BA3F-4544-9754-5406E8094723}</Project>
|
|
||||||
<Name>BizHawk.MultiClient</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\BizHawk.Util\BizHawk.Util.csproj">
|
|
||||||
<Project>{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}</Project>
|
|
||||||
<Name>BizHawk.Util</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="corphawk.ico" />
|
<Content Include="corphawk.ico" />
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace BizHawk
|
||||||
if (ofd.ShowDialog() != DialogResult.OK)
|
if (ofd.ShowDialog() != DialogResult.OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Disc disc = DiscSystem.Disc.FromCuePath(ofd.FileName);
|
Disc disc = Disc.FromCuePath(ofd.FileName);
|
||||||
|
|
||||||
string baseName = Path.GetFileName(ofd.FileName);
|
string baseName = Path.GetFileName(ofd.FileName);
|
||||||
ListViewItem lvi = new ListViewItem(baseName);
|
ListViewItem lvi = new ListViewItem(baseName);
|
||||||
|
@ -99,7 +99,7 @@ namespace BizHawk
|
||||||
|
|
||||||
CueBinPrefs GetCuePrefs()
|
CueBinPrefs GetCuePrefs()
|
||||||
{
|
{
|
||||||
var prefs = new DiscSystem.CueBinPrefs();
|
var prefs = new CueBinPrefs();
|
||||||
prefs.AnnotateCue = checkCueProp_Annotations.Checked;
|
prefs.AnnotateCue = checkCueProp_Annotations.Checked;
|
||||||
prefs.OneBlobPerTrack = checkCueProp_OneBlobPerTrack.Checked;
|
prefs.OneBlobPerTrack = checkCueProp_OneBlobPerTrack.Checked;
|
||||||
prefs.ReallyDumpBin = false;
|
prefs.ReallyDumpBin = false;
|
||||||
|
|
|
@ -28,59 +28,86 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainDiscoForm));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainDiscoForm));
|
||||||
this.ExitButton = new System.Windows.Forms.Button();
|
this.ExitButton = new System.Windows.Forms.Button();
|
||||||
this.lblMagicDragArea = new System.Windows.Forms.Panel();
|
this.lblMagicDragArea = new System.Windows.Forms.Panel();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
this.lblMagicDragArea.SuspendLayout();
|
this.lblMp3ExtractMagicArea = new System.Windows.Forms.Panel();
|
||||||
this.SuspendLayout();
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
//
|
this.lblMagicDragArea.SuspendLayout();
|
||||||
// ExitButton
|
this.lblMp3ExtractMagicArea.SuspendLayout();
|
||||||
//
|
this.SuspendLayout();
|
||||||
this.ExitButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
//
|
||||||
this.ExitButton.Location = new System.Drawing.Point(281, 316);
|
// ExitButton
|
||||||
this.ExitButton.Name = "ExitButton";
|
//
|
||||||
this.ExitButton.Size = new System.Drawing.Size(75, 23);
|
this.ExitButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.ExitButton.TabIndex = 0;
|
this.ExitButton.Location = new System.Drawing.Point(281, 316);
|
||||||
this.ExitButton.Text = "E&xit";
|
this.ExitButton.Name = "ExitButton";
|
||||||
this.ExitButton.UseVisualStyleBackColor = true;
|
this.ExitButton.Size = new System.Drawing.Size(75, 23);
|
||||||
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);
|
this.ExitButton.TabIndex = 0;
|
||||||
//
|
this.ExitButton.Text = "E&xit";
|
||||||
// lblMagicDragArea
|
this.ExitButton.UseVisualStyleBackColor = true;
|
||||||
//
|
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);
|
||||||
this.lblMagicDragArea.AllowDrop = true;
|
//
|
||||||
this.lblMagicDragArea.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
// lblMagicDragArea
|
||||||
this.lblMagicDragArea.Controls.Add(this.label1);
|
//
|
||||||
this.lblMagicDragArea.Location = new System.Drawing.Point(84, 12);
|
this.lblMagicDragArea.AllowDrop = true;
|
||||||
this.lblMagicDragArea.Name = "lblMagicDragArea";
|
this.lblMagicDragArea.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||||
this.lblMagicDragArea.Size = new System.Drawing.Size(200, 100);
|
this.lblMagicDragArea.Controls.Add(this.label1);
|
||||||
this.lblMagicDragArea.TabIndex = 1;
|
this.lblMagicDragArea.Location = new System.Drawing.Point(84, 12);
|
||||||
this.lblMagicDragArea.DragDrop += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragDrop);
|
this.lblMagicDragArea.Name = "lblMagicDragArea";
|
||||||
this.lblMagicDragArea.DragEnter += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragEnter);
|
this.lblMagicDragArea.Size = new System.Drawing.Size(200, 100);
|
||||||
//
|
this.lblMagicDragArea.TabIndex = 1;
|
||||||
// label1
|
this.lblMagicDragArea.DragDrop += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragDrop);
|
||||||
//
|
this.lblMagicDragArea.DragEnter += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragEnter);
|
||||||
this.label1.AutoSize = true;
|
//
|
||||||
this.label1.Location = new System.Drawing.Point(47, 10);
|
// label1
|
||||||
this.label1.Name = "label1";
|
//
|
||||||
this.label1.Size = new System.Drawing.Size(106, 13);
|
this.label1.AutoSize = true;
|
||||||
this.label1.TabIndex = 0;
|
this.label1.Location = new System.Drawing.Point(47, 10);
|
||||||
this.label1.Text = "Drag here for MAGIC";
|
this.label1.Name = "label1";
|
||||||
//
|
this.label1.Size = new System.Drawing.Size(106, 13);
|
||||||
// MainDiscoForm
|
this.label1.TabIndex = 0;
|
||||||
//
|
this.label1.Text = "Drag here for MAGIC";
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
//
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
// lblMp3ExtractMagicArea
|
||||||
this.ClientSize = new System.Drawing.Size(368, 351);
|
//
|
||||||
this.Controls.Add(this.lblMagicDragArea);
|
this.lblMp3ExtractMagicArea.AllowDrop = true;
|
||||||
this.Controls.Add(this.ExitButton);
|
this.lblMp3ExtractMagicArea.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.lblMp3ExtractMagicArea.Controls.Add(this.label2);
|
||||||
this.Name = "MainDiscoForm";
|
this.lblMp3ExtractMagicArea.Location = new System.Drawing.Point(84, 167);
|
||||||
this.Text = "DiscoHawk";
|
this.lblMp3ExtractMagicArea.Name = "lblMp3ExtractMagicArea";
|
||||||
this.Load += new System.EventHandler(this.MainDiscoForm_Load);
|
this.lblMp3ExtractMagicArea.Size = new System.Drawing.Size(200, 100);
|
||||||
this.lblMagicDragArea.ResumeLayout(false);
|
this.lblMp3ExtractMagicArea.TabIndex = 2;
|
||||||
this.lblMagicDragArea.PerformLayout();
|
this.lblMp3ExtractMagicArea.DragDrop += new System.Windows.Forms.DragEventHandler(this.lblMp3ExtractMagicArea_DragDrop);
|
||||||
this.ResumeLayout(false);
|
this.lblMp3ExtractMagicArea.DragEnter += new System.Windows.Forms.DragEventHandler(this.lblMagicDragArea_DragEnter);
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(17, 25);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(151, 39);
|
||||||
|
this.label2.TabIndex = 0;
|
||||||
|
this.label2.Text = "Drag cue here to extract audio\ntracks to MP3 for listening\npleasure!";
|
||||||
|
//
|
||||||
|
// MainDiscoForm
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(368, 351);
|
||||||
|
this.Controls.Add(this.lblMp3ExtractMagicArea);
|
||||||
|
this.Controls.Add(this.lblMagicDragArea);
|
||||||
|
this.Controls.Add(this.ExitButton);
|
||||||
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
|
this.Name = "MainDiscoForm";
|
||||||
|
this.Text = "DiscoHawk";
|
||||||
|
this.Load += new System.EventHandler(this.MainDiscoForm_Load);
|
||||||
|
this.lblMagicDragArea.ResumeLayout(false);
|
||||||
|
this.lblMagicDragArea.PerformLayout();
|
||||||
|
this.lblMp3ExtractMagicArea.ResumeLayout(false);
|
||||||
|
this.lblMp3ExtractMagicArea.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,5 +116,7 @@
|
||||||
private System.Windows.Forms.Button ExitButton;
|
private System.Windows.Forms.Button ExitButton;
|
||||||
private System.Windows.Forms.Panel lblMagicDragArea;
|
private System.Windows.Forms.Panel lblMagicDragArea;
|
||||||
private System.Windows.Forms.Label label1;
|
private System.Windows.Forms.Label label1;
|
||||||
|
private System.Windows.Forms.Panel lblMp3ExtractMagicArea;
|
||||||
|
private System.Windows.Forms.Label label2;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -124,5 +124,18 @@ namespace BizHawk
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void lblMp3ExtractMagicArea_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
var files = validateDrop(e.Data);
|
||||||
|
if (files.Count == 0) return;
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var disc = Disc.FromCuePath(file);
|
||||||
|
var path = Path.GetDirectoryName(file);
|
||||||
|
var filename = Path.GetFileNameWithoutExtension(file);
|
||||||
|
AudioExtractor.Extract(disc, path, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue