Skip to content

Commit

Permalink
STBL482 2024/11/10
Browse files Browse the repository at this point in the history
  PianoRoll:Driver:HES追加
  PianoRoll:Chip:HuC6280追加
  YM2612(XGM):演奏開始時に直前のPCMのミュート状態が反映されないバグを修正
  • Loading branch information
kumatan committed Nov 9, 2024
1 parent 5c11a9c commit 4b43962
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
�X�V����
STBL482 2024/11/10
PianoRoll:Driver:HES�lj�
PianoRoll:Chip:HuC6280�lj�
YM2612(XGM):���t�J�n���ɒ��O��PCM�̃~���[�g��Ԃ����f����Ȃ��o�O���C��

STBL481 2024/11/09
PianoRoll:Driver:NRTDRV,MXDRV,MNDRV,FMP,PMD,S98�lj�
PianoRoll:���������������鉹�����������m�[�g��������o�O���C��
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayer_InstKit/02info.nsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!define NAME "MDPlayer"
!define VERSION "STBL480"
!define VERSION "STBL481"
!define PUBLISHER "Kumata"
!define PACKAGE "${NAME} ${VERSION}"
15 changes: 15 additions & 0 deletions MDPlayer/MDPlayerx64/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,14 @@ public static bool Play(Setting setting)
// driverReal = new hes();
// driverReal.setting = setting;
//}
DriverPianoRoll = null;
if (setting.pianoRoll.usePianoRoll)
{
DriverPianoRoll = new hes()
{
setting = setting
};
}
return HesPlay(setting);
}

Expand Down Expand Up @@ -7141,6 +7149,13 @@ public static bool HesPlay(Setting setting)
, (uint)(setting.outputDevice.SampleRate * setting.LatencySCCI / 1000)
, (uint)(setting.outputDevice.SampleRate * setting.outputDevice.WaitTime / 1000))) return false;
}
if (DriverPianoRoll != null)
{
((hes)DriverPianoRoll).song = (byte)SongNo;
if (!DriverPianoRoll.init(vgmBuf, chipRegister, EnmModel.PianoRollModel, new EnmChip[] { EnmChip.Unuse }
, (uint)(setting.outputDevice.SampleRate * setting.LatencySCCI / 1000)
, (uint)(setting.outputDevice.SampleRate * setting.outputDevice.WaitTime / 1000))) return false;
}
//Play

Paused = false;
Expand Down
10 changes: 7 additions & 3 deletions MDPlayer/MDPlayerx64/ChipRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2235,9 +2235,13 @@ public void resetYMF278BFMKeyON(int chipID)
fmRegisterYMF278BFM[chipID] = 0;
}

public void setHuC6280Register(int chipID, int dAddr, int dData, EnmModel model)
public void setHuC6280Register(int chipID, int dAddr, int dData, EnmModel model,long vgmFrameCounter)
{
if (model == EnmModel.PianoRollModel) return;
if (model == EnmModel.PianoRollModel)
{
pianoRollMng.SetRegister(EnmChip.HuC6280,chipID,dAddr,dData,vgmFrameCounter);
return;
}

if (ctHuC6280 == null) return;

Expand Down Expand Up @@ -5018,7 +5022,7 @@ public void setMaskYM2612(int chipID, int ch, bool mask)

if (ch > 8)
{
if(Audio.PlayingFileFormat== EnmFileFormat.XGM)
if (Audio.PlayingFileFormat == EnmFileFormat.XGM && chipID == 0)
{
if (Audio.DriverVirtual != null && Audio.DriverVirtual is xgm)
{
Expand Down
7 changes: 2 additions & 5 deletions MDPlayer/MDPlayerx64/Driver/HES/hes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override bool init(byte[] vgmBuf, ChipRegister chipRegister, EnmModel mod

GD3 = getGD3Info(vgmBuf, 0);

m_hes = new m_hes();
m_hes = new m_hes(this,model);
m_hes.chipRegister = chipRegister;
m_hes.ld = ld;
nez_play = new m_hes.NEZ_PLAY();
Expand All @@ -80,10 +80,7 @@ public override void oneFrameProc()
m_hes.ExecuteHES(nez_play);
Counter++;
}
else
{
vgmFrameCounter++;
}
vgmFrameCounter++;
}
//Stopped = !IsPlaying();
}
Expand Down
11 changes: 8 additions & 3 deletions MDPlayer/MDPlayerx64/Driver/HES/m_hes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ namespace MDPlayer
{
public class m_hes
{
public m_hes()
public m_hes(baseDriver driver, EnmModel model)
{
this.driver = driver;
this.model = model;
}

private kmevent kmevent = new kmevent();
private km6280 km6280 = new km6280();
private baseDriver driver = null;
private EnmModel model = EnmModel.VirtualModel;

public class NEZ_PLAY
{
public HESHES heshes;
Expand Down Expand Up @@ -338,7 +343,7 @@ public void write_io(HESHES THIS_, UInt32 a, UInt32 v)
// (Int32)v
// );
if (!disableSendChip)
chipRegister.setHuC6280Register(0, (Int32)(a & 0xf), (Int32)v, EnmModel.VirtualModel);
chipRegister.setHuC6280Register(0, (Int32)(a & 0xf), (Int32)v, model, driver.vgmFrameCounter);
ld.Write((UInt32)(a & 0xf), (UInt32)v, 0);
//THIS_.hessnd.write(THIS_.hessnd.ctx, a & 0xf, v);
break;
Expand Down Expand Up @@ -625,7 +630,7 @@ private void reset(NEZ_PLAY pNezPlay)
km6280_exec(THIS_.ctx, HES_BASECYCLES >> 8);

disableSendChip = false;
chipRegister.setHuC6280Register(0, 1, 0xff, EnmModel.VirtualModel);
chipRegister.setHuC6280Register(0, 1, 0xff, model, driver.vgmFrameCounter);

if (THIS_.breaked != 0)
{
Expand Down
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayerx64/Driver/vgm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ private void VcYM3812()

private void VcHuC6280()
{
chipRegister.setHuC6280Register((vgmBuf[vgmAdr + 1] & 0x80) == 0 ? 0 : 1, vgmBuf[vgmAdr + 1] & 0x7f, vgmBuf[vgmAdr + 2], model);
chipRegister.setHuC6280Register((vgmBuf[vgmAdr + 1] & 0x80) == 0 ? 0 : 1, vgmBuf[vgmAdr + 1] & 0x7f, vgmBuf[vgmAdr + 2], model, vgmFrameCounter);
vgmAdr += 3;
}

Expand Down
166 changes: 166 additions & 0 deletions MDPlayer/MDPlayerx64/PianoRoll/HuC6280.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using MDPlayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace MDPlayerx64.PianoRoll
{
public class HuC6280(List<PrNote> lstPrNote, int MAXChip = 2) : BaseChip(lstPrNote, MAXChip)
{
private List<uint> crntChannel;
private List<uint[]> frq;
private List<uint[]> volume;
private List<uint[]> volumeL;
private List<uint[]> volumeR;
private List<uint[]> outVolumeL;
private List<uint[]> outVolumeR;
private List<PrNote[]> Note;

public override void Clear()
{
crntChannel = [];
frq = [];
volume = [];
volumeL = [];
volumeR = [];
outVolumeL = [];
outVolumeR = [];
Note = [];

for (int i = 0; i < MAXChip; i++)
{
crntChannel.Add(0);
frq.Add([0, 0, 0, 0, 0, 0]);
volume.Add([0, 0, 0, 0, 0, 0]);
volumeL.Add([0, 0, 0, 0, 0, 0]);
volumeR.Add([0, 0, 0, 0, 0, 0]);
outVolumeL.Add([0, 0, 0, 0, 0, 0]);
outVolumeR.Add([0, 0, 0, 0, 0, 0]);
Note.Add(new PrNote[6]);
}
}

public override void Analyze(int chipID, int dAdr, int dData, long vgmFrameCounter)
{
switch (dAdr & 15)
{
case 0: // register select
crntChannel[chipID] = (uint)(dData & 7);
break;

case 1: // main volume
//MainVolumeL = (uint)((dData >> 4) & 0x0F);
//MainVolumeR = (uint)(dData & 0x0F);
break;

case 2: // frequency low
frq[chipID][crntChannel[chipID]] &= ~(uint)0xFF;
frq[chipID][crntChannel[chipID]] |= (uint)dData;
break;

case 3: // frequency high
frq[chipID][crntChannel[chipID]] &= ~(uint)0xF00;
frq[chipID][crntChannel[chipID]] |= (uint)((dData & 0x0F) << 8);
break;

case 4: // ON, DDA, AL
volume[chipID][crntChannel[chipID]] = (uint)(dData & 0x1F);
break;

case 5: // LAL, RAL
volumeL[chipID][crntChannel[chipID]] = (uint)((dData >> 4) & 0xF);
volumeR[chipID][crntChannel[chipID]] = (uint)(dData & 0xF);
break;

case 6: // wave data
break;
case 7: // noise on, noise frq
break;
case 8: // LFO frequency
break;
case 9: // LFO control
break;
default: // invalid write
break;
}


for (int ch = 0; ch < 6; ch++)
{
uint outVolumeL = volume[chipID][ch] * volumeL[chipID][ch];
uint outVolumeR = volume[chipID][ch] * volumeR[chipID][ch];

int tp = (int)frq[chipID][ch];
if (tp == 0) tp = 1;
float ftone = 3579545.0f / 32.0f / (float)tp;
int note = (95-Common.searchSSGNote(ftone));
if (outVolumeL == 0 && outVolumeR == 0) note = -1;

if (note != -1)
{
if (Note[chipID][ch] == null)
{
//keyONした!
Note[chipID][ch] = MakeNote(ch, vgmFrameCounter, note, (int)ftone);
lstPrNote.Add(Note[chipID][ch]);
}
else
{
//keyON中!
if (Note[chipID][ch].key != note)
{
//音程が異なる場合は新たなノートとする
Note[chipID][ch].endTick = vgmFrameCounter;
Note[chipID][ch] = MakeNote(ch, vgmFrameCounter, note, (int)ftone);
lstPrNote.Add(Note[chipID][ch]);
}
}
continue;
}

//keyOFF
if (Note[chipID][ch] == null) continue;

//keyOFFした!
Note[chipID][ch].endTick = vgmFrameCounter;
Note[chipID][ch] = null;

//keyOFF中は何もしない

}

}

private static PrNote MakeNote(int ch, long startTick, int note, int freq)
{
PrNote ret = new()
{
ch = ch,
startTick = startTick,
endTick = -1,//長さ未確定
key = note,
freq = freq
};

ret.noteColor1[0] = 0x40;
ret.noteColor1[1] = 0x00;
ret.noteColor1[2] = 0x78;
ret.noteColor1[3] = 0x60;
ret.noteColor1[4] = 0x00;
ret.noteColor1[5] = 0x98;

ret.noteColor2[0] = 0x70;
ret.noteColor2[1] = 0x30;
ret.noteColor2[2] = 0xA0;
ret.noteColor2[3] = 0x90;
ret.noteColor2[4] = 0x30;
ret.noteColor2[5] = 0xC0;

return ret;
}

}
}
14 changes: 8 additions & 6 deletions MDPlayer/MDPlayerx64/PianoRollMng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static MDPlayer.MDChipParams;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace MDPlayer
Expand All @@ -17,12 +18,13 @@ public class PianoRollMng

public PianoRollMng()
{
chipList.Add(EnmChip.AY8910, new AY8910(lstPrNote));
chipList.Add(EnmChip.YM2151, new YM2151(lstPrNote));
chipList.Add(EnmChip.YM2608, new YM2608(lstPrNote));
chipList.Add(EnmChip.YM2610, new YM2610(lstPrNote));
chipList.Add(EnmChip.YM2612, new YM2612(lstPrNote));
chipList.Add(EnmChip.SN76489, new SN76489(lstPrNote));
chipList.Add(EnmChip.AY8910, new MDPlayerx64.PianoRoll.AY8910(lstPrNote));
chipList.Add(EnmChip.HuC6280, new MDPlayerx64.PianoRoll.HuC6280(lstPrNote));
chipList.Add(EnmChip.YM2151, new MDPlayerx64.PianoRoll.YM2151(lstPrNote));
chipList.Add(EnmChip.YM2608, new MDPlayerx64.PianoRoll.YM2608(lstPrNote));
chipList.Add(EnmChip.YM2610, new MDPlayerx64.PianoRoll.YM2610(lstPrNote));
chipList.Add(EnmChip.YM2612, new MDPlayerx64.PianoRoll.YM2612(lstPrNote));
chipList.Add(EnmChip.SN76489, new MDPlayerx64.PianoRoll.SN76489(lstPrNote));
}

public void Clear()
Expand Down
2 changes: 1 addition & 1 deletion MDPlayer/MDPlayerx64/dacControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ private void chip_reg_write(byte ChipType2, byte ChipID, byte Port, byte Offset,
chipRegister.writeOKIM6258(ChipID, Offset, Data, model);
break;
case 0x1b: // HuC6280
chipRegister.setHuC6280Register(ChipID, Offset, Data, model);
chipRegister.setHuC6280Register(ChipID, Offset, Data, model, 0);
break;
}
}
Expand Down
36 changes: 18 additions & 18 deletions MDPlayer/MDPlayerx64/form/KB/WF/frmHuC6280.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void screenChangeParams()
if (tp == 0) tp = 1;

float ftone = 3579545.0f / 32.0f / (float)tp;
channel.note = searchSSGNote(ftone);
channel.note = Common.searchSSGNote(ftone);
if (channel.volumeL == 0 && channel.volumeR == 0) channel.note = -1;

if (ch < 4) continue;
Expand Down Expand Up @@ -223,23 +223,23 @@ private void pbScreen_MouseClick(object sender, MouseEventArgs e)

}

private int searchSSGNote(float freq)
{
float m = float.MaxValue;
int n = 0;
for (int i = 0; i < 12 * 8; i++)
{
//if (freq < Tables.freqTbl[i]) break;
//n = i;
float a = Math.Abs(freq - Tables.freqTbl[i]);
if (m > a)
{
m = a;
n = i;
}
}
return n;
}
//private int searchSSGNote(float freq)
//{
// float m = float.MaxValue;
// int n = 0;
// for (int i = 0; i < 12 * 8; i++)
// {
// //if (freq < Tables.freqTbl[i]) break;
// //n = i;
// float a = Math.Abs(freq - Tables.freqTbl[i]);
// if (m > a)
// {
// m = a;
// n = i;
// }
// }
// return n;
//}

public void screenInit()
{
Expand Down

0 comments on commit 4b43962

Please sign in to comment.