Skip to content

Commit

Permalink
Fix XGM2 last PCM size outbound.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fujix1 committed Dec 5, 2024
1 parent 362cf0d commit 3b8750f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
18 changes: 14 additions & 4 deletions lib/fm/fm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,13 @@ void FMChip::setYM2612(byte bank, byte addr, byte data, uint8_t chipno) {
ets_delay_us(4); // 3 は一部足りない

// data
/*if (addr >= 0x40 && addr <= 0x4e) {
dedic_gpio_bundle_write(dataBus, 0xff, 127);
} else {
dedic_gpio_bundle_write(dataBus, 0xff, data);
}*/
dedic_gpio_bundle_write(dataBus, 0xff, data);

WR_LOW;
WR_HIGH;
switch (chipno) {
Expand Down Expand Up @@ -217,13 +223,9 @@ void FMChip::setYM2612DAC(byte data, uint8_t chipno) {
switch (chipno) {
case 0:
CS0_LOW;
CS1_HIGH;
CS2_HIGH;
break;
case 1:
CS0_HIGH;
CS1_LOW;
CS2_HIGH;
break;
}

Expand All @@ -244,6 +246,14 @@ void FMChip::setYM2612DAC(byte data, uint8_t chipno) {
dedic_gpio_bundle_write(dataBus, 0xff, data);
WR_LOW;
WR_HIGH;
switch (chipno) {
case 0:
CS0_HIGH;
break;
case 1:
CS1_HIGH;
break;
}
}

// YM2203, AY-8910用レジスタ設定
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void setup() {
lcd.setFont(&fonts::Font2);
lcd.println("NANO DRIVE 6");
lcd.println("2024 [email protected]");
lcd.printf("Firmware: 1.8\n\n");
lcd.printf("Firmware: 1.82\n\n");

// PSRAM 初期化確認
if (psramInit()) {
Expand Down
35 changes: 13 additions & 22 deletions src/vgm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,18 +615,6 @@ void VGM::vgmProcess() {
while (_vgmWaitUntil - 22 > micros()) {
ets_delay_us(22);
}

/*
vgmProcessMain();
if (_vgmDelay >= 3000) {
ets_delay_us(_vgmDelay / 1000);
_vgmDelay = _vgmDelay % 1000;
const uint64_t vgmTime = _vgmSamples * 22.67573696145125f;
const uint64_t realTime = micros() - _vgmStart;
if (realTime > vgmTime) _vgmDelay -= (realTime - vgmTime);
}
*/
}

void VGM::vgmProcessMain() {
Expand Down Expand Up @@ -701,20 +689,17 @@ void VGM::vgmProcessMain() {
// Wait n samples, n can range from 0 to 65535 (approx 1.49 seconds)
case 0x61: {
u16_t w = get_ui16();
//_vgmDelay += w * ONE_CYCLE;
_vgmSamples += w;
break;
}

// wait 735 samples (60th of a second)
case 0x62:
//_vgmDelay += 735 * ONE_CYCLE;
_vgmSamples += 735;
break;

// wait 882 samples (50th of a second)
case 0x63:
//_vgmDelay += 882 * ONE_CYCLE;
_vgmSamples += 882;
break;

Expand All @@ -740,14 +725,11 @@ void VGM::vgmProcessMain() {
break;

case 0x70 ... 0x7f:
//_vgmDelay += ((command & 15) + 1) * ONE_CYCLE;
_vgmSamples += (command & 15) + 1;
break;

case 0x80 ... 0x8f:
// FM.setYM2612DAC(vgmData[_pcmpos++], 0);
FM.setYM2612(0, 0x2a, vgmData[_pcmpos++], 0);
//_vgmDelay += (command & 15) * ONE_CYCLE;
FM.setYM2612DAC(vgmData[_pcmpos++], 0);
_vgmSamples += (command & 15);
break;

Expand Down Expand Up @@ -910,9 +892,17 @@ bool VGM::XGMReady() {
XGMSampleSizeTable.push_back(0);
} else {
XGMSampleSizeTable.push_back(XGMSampleAddressTable[i + 1] - XGMSampleAddressTable[i]);

// Last sample size
if (XGMSampleSizeTable[i] > XGM_SLEN - 0x104) {
XGMSampleSizeTable[i] = XGM_SLEN - XGMSampleAddressTable[i] + 0x104;
}
}
}

for (int i = 0; i < 123; i++) {
Serial.printf("Sample: id %d, add %x, size %x\n", i, XGMSampleAddressTable[i], XGMSampleSizeTable[i]);
}
gd3Offset = 0x104 + XGM_SLEN + XGM_FMLEN + XGM_PSGLEN;

_xgm2_ym_offset = 0x104 + XGM_SLEN;
Expand Down Expand Up @@ -1127,15 +1117,16 @@ void VGM::_xgm2ProcessPCM() {

for (int i = 0; i < 3; i++) {
if (_xgmSampleOn[i]) {
if (_xgmPCMHalfTick[i] == false) {
if (_xgmPCMHalfSent[i] == false) {
samp += (s8_t)get_ui8_at(XGMSampleAddressTable[_xgmSampleId[i]] + _xgmSamplePos[i]++);
sampFlag = true;

if (_xgmSamplePos[i] >= XGMSampleSizeTable[_xgmSampleId[i]]) {
_xgmSampleOn[i] = false;
_xgmSampleId[i] = 0;
}
}
if (_xgmPCMHalfSpeed[i]) _xgmPCMHalfTick[i] = !_xgmPCMHalfTick[i];
if (_xgmPCMHalfSpeed[i]) _xgmPCMHalfSent[i] = !_xgmPCMHalfSent[i];
}
}

Expand Down Expand Up @@ -1191,7 +1182,7 @@ void VGM::_xgm2ProcessYM() {
_xgmSampleOn[ch] = true;
_xgmSamplePos[ch] = 0;
_xgmPCMHalfSpeed[ch] = halfspeed;
_xgmPCMHalfTick[ch] = false;
_xgmPCMHalfSent[ch] = false;
}
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/vgm.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class VGM {
uint32_t _xgm2_psg_pos;

t_gd3 gd3;
// int32_t _vgmDelay = 0;
uint16_t _vgmLoop;
uint64_t _vgmSamples;
uint64_t _vgmRealSamples;
Expand All @@ -155,7 +154,7 @@ class VGM {
u8_t _xgmPriorities[XGM1_MAX_PCM_CH];
bool _xgmSampleOn[XGM1_MAX_PCM_CH];
bool _xgmPCMHalfSpeed[3];
bool _xgmPCMHalfTick[3];
bool _xgmPCMHalfSent[3];
u32_t _xgmFrame;
u32_t _xgmYMSNFrame;
u32_t _xgmStartTick;
Expand Down

0 comments on commit 3b8750f

Please sign in to comment.