Skip to content

Commit

Permalink
TAG726 2024/03/04
Browse files Browse the repository at this point in the history
  Core:XGM2:Lコマンド実装
  • Loading branch information
kumatan committed Mar 4, 2024
1 parent 430832f commit efc25c2
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 27 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����
TAG726 2024/03/04
Core:XGM2:L�R�}���h����

TAG725 2024/03/03
Core:XGM2:DCSG�̃m�C�Y�ɑΉ��B
PCM�̍Đ��X�s�[�h��؂�ւ��”\�ɂ����B
Expand Down
111 changes: 85 additions & 26 deletions mml2vgm/Core/XGM2maker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class XGM2maker
private Action<string> disp;
private Dictionary<int, int> fmFrameLengthDic;
private Dictionary<int, int> psgFrameLengthDic;
private int fmWaitCounter = 0;
private int psgWaitCounter = 0;
private int fmLoopPtr = -1;
private int psgLoopPtr = -1;

public XGM2maker(Action<string> disp=null)
{
Expand All @@ -63,7 +67,12 @@ public outDatum[] Build(ClsVgm mmlInfo,bool outVgmFile,bool writeFileMode)
psgFrameLength = 0;
psgFrameLengthDic = new Dictionary<int, int>();

makeAndOutHeaderDiv();
fmWaitCounter = 0;
psgWaitCounter = 0;
fmLoopPtr = -1;
psgLoopPtr = -1;

makeAndOutHeaderDiv();
headData = mmlInfo.dat;
mmlInfo.dat = new List<outDatum>();
makePCMData();
Expand All @@ -76,22 +85,32 @@ public outDatum[] Build(ClsVgm mmlInfo,bool outVgmFile,bool writeFileMode)
mmlInfo.dat.Clear();
mmlInfo.chips = getChips(true, bd);
fmData = makeFMtrack();
fmData = ShapingFMDat(fmData);

mmlInfo.dat.Clear();
mmlInfo.chips = getChips(false, bd);
psgData = makePSGtrack();

fmData = ShapingFMDat(fmData);
psgData = ShapingPSGDat(psgData);

if (mmlInfo.loopSamples != -1)
{
//LOOP有り
}

PaddingFM();
PaddingPSG();

CheckFrameLength();

mmlInfo.chips = bd;
makeFooterDiv();

Disp("FM frame(s) : {0}", fmFrameCounter);
Disp("PSG frame(s) : {0}", psgFrameCounter);
Disp("FM frame(s) : {0}", fmFrameCounter);
Disp("PSG frame(s) : {0}", psgFrameCounter);
Disp("FM wait count : {0} frame(s)", fmWaitCounter);
Disp("PSG wait count : {0} frame(s)", psgWaitCounter);
Disp("Loop point : {0}", mmlInfo.loopSamples != -1 ? (mmlInfo.loopSamples.ToString()+ " frame(s)") : "no loop");
Disp("Finish xgm2 build.");

return mmlInfo.dat.ToArray();
Expand Down Expand Up @@ -367,12 +386,10 @@ private List<outDatum> makeFMtrack()
}

//end mark
o = new outDatum();
o.val = 0xff;
dat.Add(o);
dat.Add(o);
dat.Add(o);
dat.Add(o);
dat.Add(new outDatum(0xff));
dat.Add(new outDatum(0xff));
dat.Add(new outDatum(0xff));
dat.Add(new outDatum(0xff));

return dat;
}
Expand Down Expand Up @@ -509,6 +526,12 @@ private List<outDatum> ShapingFMDat(List<outDatum> src)
break;
case 0xff://loop/end mark
ret.Add(src[i]);
if (fmLoopPtr >= 0)
{
src[i + 1].val = (byte)fmLoopPtr;
src[i + 2].val = (byte)(fmLoopPtr >> 8);
src[i + 3].val = (byte)(fmLoopPtr >> 16);
}
ret.Add(src[++i]);
ret.Add(src[++i]);
ret.Add(src[++i]);
Expand All @@ -530,6 +553,15 @@ private void PaddingFM()
if (pad != 256) for (int i = 0; i < pad; i++) fmData.Add(p);
}

private void PaddingPSG()
{
//padding
int pad = 256 - (psgData.Count % 256);
outDatum p = new outDatum();
p.val = 0x00;
if (pad != 256) for (int i = 0; i < pad; i++) psgData.Add(p);
}

private List<outDatum> makePSGtrack()
{
log.Write("PSG Data division");
Expand Down Expand Up @@ -599,14 +631,10 @@ private List<outDatum> makePSGtrack()
}

//end mark
o = new outDatum();
o.val = 0x0f;
dat.Add(o);
o = new outDatum();
o.val = 0xff;
dat.Add(o);
dat.Add(o);
dat.Add(o);
dat.Add(new outDatum(0x0f));
dat.Add(new outDatum(0xff));
dat.Add(new outDatum(0xff));
dat.Add(new outDatum(0xff));

return dat;
}
Expand Down Expand Up @@ -710,6 +738,12 @@ private List<outDatum> ShapingPSGDat(List<outDatum> src)
fmData.Add(loopEndMark[2]);
fmData.Add(loopEndMark[3]);
}
if (psgLoopPtr >= 0)
{
src[i + 1].val = (byte)psgLoopPtr;
src[i + 2].val = (byte)(psgLoopPtr >> 8);
src[i + 3].val = (byte)(psgLoopPtr >> 16);
}
ret.Add(src[i]);
ret.Add(src[++i]);
ret.Add(src[++i]);
Expand All @@ -718,16 +752,26 @@ private List<outDatum> ShapingPSGDat(List<outDatum> src)
}
}

//padding
int pad = 256 - (ret.Count % 256);
outDatum p = new outDatum();
p.val = 0x00;
if (pad != 256) for (int i = 0; i < pad; i++) ret.Add(p);

return ret;
}

private List<outDatum> AddWaitFM(List<outDatum> ret, int w)
{
fmWaitCounter += w;
if (mmlInfo.loopSamples > fmWaitCounter || mmlInfo.loopSamples == -1 || fmLoopPtr >= 0)
{
AddWaitFM2(ret, w);
return ret;
}

int loop = (int)(fmWaitCounter - mmlInfo.loopSamples);
AddWaitFM2(ret, w - loop);
fmLoopPtr = ret.Count;
AddWaitFM2(ret, loop);
return ret;
}

private static void AddWaitFM2(List<outDatum> ret, int w)
{
while (w > 0)
{
Expand Down Expand Up @@ -760,10 +804,25 @@ private List<outDatum> AddWaitFM(List<outDatum> ret, int w)
}
}
}
}

private List<outDatum> AddWaitPSG(List<outDatum> ret, int w)
{
psgWaitCounter += w;
if (mmlInfo.loopSamples > psgWaitCounter || mmlInfo.loopSamples == -1 || psgLoopPtr >= 0)
{
AddWaitPSG2(ret, w);
return ret;
}

int loop = (int)(psgWaitCounter - mmlInfo.loopSamples);
AddWaitPSG2(ret, w - loop);
psgLoopPtr = ret.Count;
AddWaitPSG2(ret, loop);
return ret;
}

private List<outDatum> AddWaitPSG(List<outDatum> ret,int w)
private static void AddWaitPSG2(List<outDatum> ret, int w)
{
while (w > 0)
{
Expand Down Expand Up @@ -796,7 +855,7 @@ private List<outDatum> AddWaitPSG(List<outDatum> ret,int w)
}
}
}
return ret;

}

private void CheckFrameLength()
Expand Down
2 changes: 2 additions & 0 deletions mml2vgm/mml2vgmIDEx64/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ public static bool Play(Setting setting, bool doSkipStop = false, Action started
errMsg = "";
Stop(SendMode.Both);

NAudioWrap.reinit();

if (doSkipStop)
{
sm.SetMode(SendMode.RealTime);
Expand Down
10 changes: 10 additions & 0 deletions mml2vgm/mml2vgmIDEx64/NAudioWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,15 @@ public static int getAsioLatency()

return asioOut.PlaybackLatency;
}

public static void reinit()
{
try
{
//Stop();
//Start(setting);
}
catch { }
}
}
}
2 changes: 1 addition & 1 deletion mml2vgm/mml2vgmIDEx64/SoundManager/SoundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void RequestStart(SendMode mode, bool useEmu, bool useReal)
}
}

int timeout = 2000;
int timeout = 1000;
while (!dataSender.IsRunning() && timeout > 0)
{
dataSender.RequestStart();
Expand Down

0 comments on commit efc25c2

Please sign in to comment.