make discohawk AudioExtractor multi-threaded

This commit is contained in:
zeromus 2021-10-03 01:24:12 -04:00
parent b14c434377
commit d3e1a6db99
1 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,5 @@
using System.Windows.Forms; using System.Windows.Forms;
using System.Threading.Tasks;
using System.IO; using System.IO;
using BizHawk.Emulation.DiscSystem; using BizHawk.Emulation.DiscSystem;
@ -16,18 +17,22 @@ namespace BizHawk.Client.DiscoHawk
bool confirmed = false; bool confirmed = false;
var tracks = disc.Session1.Tracks; var tracks = disc.Session1.Tracks;
foreach (var track in tracks) Parallel.ForEach(tracks, track =>
{ {
if (!track.IsAudio) if (!track.IsAudio)
continue; return;
if (track.NextTrack == null)
return;
int trackLength = track.NextTrack.LBA - track.LBA; int trackLength = track.NextTrack.LBA - track.LBA;
var waveData = new byte[trackLength * 2352]; var waveData = new byte[trackLength * 2352];
int startLba = track.LBA; int startLba = track.LBA;
for (int sector = 0; sector < trackLength; sector++) lock(disc)
{ for (int sector = 0; sector < trackLength; sector++)
dsr.ReadLBA_2352(startLba + sector, waveData, sector * 2352); {
} dsr.ReadLBA_2352(startLba + sector, waveData, sector * 2352);
}
string mp3Path = $"{Path.Combine(path, fileBase)} - Track {track.Number:D2}.mp3"; string mp3Path = $"{Path.Combine(path, fileBase)} - Track {track.Number:D2}.mp3";
if (File.Exists(mp3Path)) if (File.Exists(mp3Path))
@ -53,7 +58,7 @@ namespace BizHawk.Client.DiscoHawk
{ {
File.Delete(tempfile); File.Delete(tempfile);
} }
} });
} }
} }
} }