Skip to content

Commit

Permalink
TAG731 2024/05/03
Browse files Browse the repository at this point in the history
  Export:muc to vgmの挙動調整
  • Loading branch information
kumatan committed May 3, 2024
1 parent ee18dcc commit 7125ef3
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 141 deletions.
3 changes: 3 additions & 0 deletions mml2vgm/CHANGE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
�X�V����
TAG731 2024/05/03
Export:muc to vgm�̋�������

TAG730 2024/03/20
mucomDotNET�̍����ւ�

Expand Down
Binary file modified mml2vgm/Core/MDSound.dll
Binary file not shown.
39 changes: 27 additions & 12 deletions mml2vgm/mml2vgmIDE/VGMWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public void Close()
dest.WriteByte((byte)(opnbMasterClock >> 0));
dest.WriteByte((byte)(opnbMasterClock >> 8));
dest.WriteByte((byte)(opnbMasterClock >> 16));
if (useChips[i] == 3) dest.WriteByte(0);
else dest.WriteByte(0x40);
if (useChips[i] == 3) dest.WriteByte(0x80 + 0x00);//bit31:OPNB2 bit30:dualchip
else dest.WriteByte(0x80 + 0x40);
break;
case 5:
dest.Position = 0x30;
Expand Down Expand Up @@ -588,10 +588,13 @@ public void useChipsFromMub(byte[] buf)
{
if (partCount[0] > 0)
{
uint n = 0;
int n = 0;
for (int i = 0; i < partCount[0]; i++)
{
n += pageCount[0][i];
for (int j = 0; j < pageLength[0][i].Length; j++)
{
n += pageLength[0][i][j] > 1 ? 1 : 0;
}
}
if (n > 0) ret[0] = 1;
}
Expand All @@ -601,10 +604,13 @@ public void useChipsFromMub(byte[] buf)
{
if (partCount[1] > 0)
{
uint n = 0;
int n = 0;
for (int i = 0; i < partCount[1]; i++)
{
n += pageCount[1][i];
for (int j = 0; j < pageLength[1][i].Length; j++)
{
n += pageLength[1][i][j] > 1 ? 1 : 0;
}
}
if (n > 0)
{
Expand All @@ -618,10 +624,13 @@ public void useChipsFromMub(byte[] buf)
{
if (partCount[2] > 0)
{
uint n = 0;
int n = 0;
for (int i = 0; i < partCount[2]; i++)
{
n += pageCount[2][i];
for (int j = 0; j < pageLength[2][i].Length; j++)
{
n += pageLength[2][i][j] > 1 ? 1 : 0;
}
}
if (n > 0) ret[2] = 3;
}
Expand All @@ -631,10 +640,13 @@ public void useChipsFromMub(byte[] buf)
{
if (partCount[3] > 0)
{
uint n = 0;
int n = 0;
for (int i = 0; i < partCount[3]; i++)
{
n += pageCount[3][i];
for (int j = 0; j < pageLength[3][i].Length; j++)
{
n += pageLength[3][i][j] > 1 ? 1 : 0;
}
}
if (n > 0) ret[3] = 4;
}
Expand All @@ -644,10 +656,13 @@ public void useChipsFromMub(byte[] buf)
{
if (partCount[4] > 0)
{
uint n = 0;
int n = 0;
for (int i = 0; i < partCount[4]; i++)
{
n += pageCount[4][i];
for (int j = 0; j < pageLength[4][i].Length; j++)
{
n += pageLength[4][i][j] > 1 ? 1 : 0;
}
}
if (n > 0) ret[4] = 5;
}
Expand Down
2 changes: 1 addition & 1 deletion mml2vgm/mml2vgmIDEx64/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5654,7 +5654,7 @@ public static void Close()
//sm.Release();
NAudioWrap.Stop();

sm.Release();
//sm.Release();
}
catch (Exception ex)
{
Expand Down
261 changes: 148 additions & 113 deletions mml2vgm/mml2vgmIDEx64/NAudioWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,137 +58,172 @@ public static void Start(Setting setting)
switch (setting.outputDevice.DeviceType)
{
case 0:
log.ForcedWrite("NAudioWrap:Start:Start Wave Init.");
waveOut = new WaveOutEvent();
waveOut.DeviceNumber = 0;
waveOut.DesiredLatency = setting.outputDevice.Latency;
for (int i = 0; i < WaveOut.DeviceCount; i++)
{
if (setting.outputDevice.WaveOutDeviceName == WaveOut.GetCapabilities(i).ProductName)
{
waveOut.DeviceNumber = i;
break;
}
}
waveOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Wave Init.");
waveOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call Wave Play.");
waveOut.Play();
StartWaveOut(setting);
break;
case 1:
log.ForcedWrite("NAudioWrap:Start:Start Directsound Init.");
System.Guid g = System.Guid.Empty;
foreach (DirectSoundDeviceInfo d in DirectSoundOut.Devices)
{
if (setting.outputDevice.DirectSoundDeviceName == d.Description)
{
g = d.Guid;
break;
}
}
if (g == System.Guid.Empty)
{
dsOut = new DirectSoundOut(setting.outputDevice.Latency);
}
else
{
dsOut = new DirectSoundOut(g, setting.outputDevice.Latency);
}
dsOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Directsound Init.");
dsOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call Directsound Play.");
dsOut.Play();
StartDirectSound(setting);
break;
case 2:
log.ForcedWrite("NAudioWrap:Start:Start Wasapi Init.");
MMDevice dev = null;
var enumerator = new MMDeviceEnumerator();
var endPoints = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
foreach (var endPoint in endPoints)
{
if (setting.outputDevice.WasapiDeviceName == string.Format("{0} ({1})", endPoint.FriendlyName, endPoint.DeviceFriendlyName))
{
dev = endPoint;
break;
}
}
if (dev == null)
{
wasapiOut = new WasapiOut(setting.outputDevice.WasapiShareMode ? AudioClientShareMode.Shared : AudioClientShareMode.Exclusive, setting.outputDevice.Latency);
}
else
{
wasapiOut = new WasapiOut(dev, setting.outputDevice.WasapiShareMode ? AudioClientShareMode.Shared : AudioClientShareMode.Exclusive, false, setting.outputDevice.Latency);
}
wasapiOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Wasapi Init.");
wasapiOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call Wasapi Play.");
wasapiOut.Play();
StartWasapi(setting);
break;
case 3:
log.ForcedWrite("NAudioWrap:Start:Start ASIO Init.");
if (AsioOut.isSupported())
{
int i = 0;
foreach (string s in AsioOut.GetDriverNames())
{
if (setting.outputDevice.AsioDeviceName == s)
{
break;
}
i++;
}
int retry = 1;
do
{
try
{
asioOut = new AsioOut(i);
}
catch
{
asioOut = null;
Thread.Sleep(1000);
retry--;
}
} while (asioOut == null && retry > 0);
asioOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call ASIO Init.");
asioOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call ASIO Play.");
asioOut.Play();
}
StartASIO(setting);
break;

case 5:
log.ForcedWrite("NAudioWrap:Start:Start NULLDevice Init.");
nullOut = new NullOut(true);
nullOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call NULLDevice Init.");
nullOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call NULLDevice Play.");
nullOut.Play();
StartNULL();
break;
}
}
catch (Exception ex)
{
log.ForcedWrite("NAudioWrap:Start:Start Wave Init.(reinit)");
log.ForcedWrite(ex);
waveOut = new WaveOutEvent();
waveOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Wave Init.(reinit)");
waveOut.Init(waveProvider);
waveOut.DeviceNumber = 0;
log.ForcedWrite("NAudioWrap:Start:Call Wave Play.(reinit)");
waveOut.Play();
StartWave_reinit(ex);
}

}

private static void StartNULL()
{
log.ForcedWrite("NAudioWrap:Start:Start NULLDevice Init.");
nullOut = new NullOut(true);
nullOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call NULLDevice Init.");
nullOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call NULLDevice Play.");
nullOut.Play();
}

private static void StartASIO(Setting setting)
{
log.ForcedWrite("NAudioWrap:Start:Start ASIO Init.");
if (AsioOut.isSupported())
{
int i = 0;
foreach (string s in AsioOut.GetDriverNames())
{
if (setting.outputDevice.AsioDeviceName == s)
{
break;
}
i++;
}
int retry = 1;
do
{
try
{
asioOut = new AsioOut(i);
}
catch
{
asioOut = null;
retry--;
if (retry > 0) Thread.Sleep(1000);
}
} while (asioOut == null && retry > 0);
if (asioOut == null) throw new Exception("Not found ASIO device.");
asioOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call ASIO Init.");
asioOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call ASIO Play.");
asioOut.Play();
}
}

private static void StartWasapi(Setting setting)
{
log.ForcedWrite("NAudioWrap:Start:Start Wasapi Init.");
MMDevice dev = null;
var enumerator = new MMDeviceEnumerator();
var endPoints = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
foreach (var endPoint in endPoints)
{
if (setting.outputDevice.WasapiDeviceName == string.Format("{0} ({1})", endPoint.FriendlyName, endPoint.DeviceFriendlyName))
{
dev = endPoint;
break;
}
}
if (dev == null)
{
wasapiOut = new WasapiOut(setting.outputDevice.WasapiShareMode ? AudioClientShareMode.Shared : AudioClientShareMode.Exclusive, setting.outputDevice.Latency);
}
else
{
wasapiOut = new WasapiOut(dev, setting.outputDevice.WasapiShareMode ? AudioClientShareMode.Shared : AudioClientShareMode.Exclusive, false, setting.outputDevice.Latency);
}
wasapiOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Wasapi Init.");
wasapiOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call Wasapi Play.");
wasapiOut.Play();
}

private static void StartDirectSound(Setting setting)
{
log.ForcedWrite("NAudioWrap:Start:Start Directsound Init.");
System.Guid g = System.Guid.Empty;
foreach (DirectSoundDeviceInfo d in DirectSoundOut.Devices)
{
if (setting.outputDevice.DirectSoundDeviceName == d.Description)
{
g = d.Guid;
break;
}
}
if (g == System.Guid.Empty)
{
dsOut = new DirectSoundOut(setting.outputDevice.Latency);
}
else
{
dsOut = new DirectSoundOut(g, setting.outputDevice.Latency);
}
dsOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Directsound Init.");
dsOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call Directsound Play.");
dsOut.Play();
}

private static void StartWaveOut(Setting setting)
{
log.ForcedWrite("NAudioWrap:Start:Start Wave Init.");
waveOut = new WaveOutEvent();
waveOut.DeviceNumber = 0;
waveOut.DesiredLatency = setting.outputDevice.Latency;
for (int i = 0; i < WaveOut.DeviceCount; i++)
{
if (setting.outputDevice.WaveOutDeviceName == WaveOut.GetCapabilities(i).ProductName)
{
waveOut.DeviceNumber = i;
break;
}
}
waveOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Wave Init.");
waveOut.Init(waveProvider);
log.ForcedWrite("NAudioWrap:Start:Call Wave Play.");
waveOut.Play();
}

private static void StartWave_reinit(Exception ex)
{
log.ForcedWrite("NAudioWrap:Start:Start Wave Init.(reinit)");
log.ForcedWrite(ex);
waveOut = new WaveOutEvent();
waveOut.PlaybackStopped += DeviceOut_PlaybackStopped;
log.ForcedWrite("NAudioWrap:Start:Call Wave Init.(reinit)");
waveOut.Init(waveProvider);
waveOut.DeviceNumber = 0;
log.ForcedWrite("NAudioWrap:Start:Call Wave Play.(reinit)");
waveOut.Play();
}





public static void ShowControlPanel(string asioDriverName)
{
if (asioOut != null)
Expand Down
Loading

0 comments on commit 7125ef3

Please sign in to comment.