Skip to content

Commit

Permalink
[xgmtool] Recognize and don't skip RF4C68 commands
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Jun 10, 2024
1 parent 1655e92 commit d86d7f8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tools/xgmtool/inc/vgmcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define VGM_LOOP_START 0x30
#define VGM_LOOP_END 0x31

#define VGM_WRITE_RF5C68 0xB0

typedef struct
{
Expand Down Expand Up @@ -92,6 +93,7 @@ int VGMCommand_getStreamFrenquency(VGMCommand* source);
int VGMCommand_getStreamSampleAddress(VGMCommand* source);
int VGMCommand_getStreamSampleSize(VGMCommand* source);
bool VGMCommand_isSame(VGMCommand* source, VGMCommand* com);
bool VGMCommand_isRF5C68Control(VGMCommand* source);

bool VGMCommand_contains(LList* commands, VGMCommand* command);
VGMCommand* VGMCommand_getKeyOnCommand(LList* commands, int channel);
Expand Down
2 changes: 1 addition & 1 deletion tools/xgmtool/inc/xgmtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ extern bool verbose;
extern bool sampleIgnore;
extern bool sampleRateFix;
extern bool delayKeyOff;

extern bool keepRF5C68Cmds;

#endif // XGMTOOL_H_
2 changes: 1 addition & 1 deletion tools/xgmtool/src/vgm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ void VGM_cleanCommands(VGM* vgm)
command = com->element;

// keep data block, stream commands and other misc commands
if (VGMCommand_isDataBlock(command) || VGMCommand_isStream(command) || VGMCommand_isLoopStart(command) || VGMCommand_isLoopEnd(command))
if (VGMCommand_isDataBlock(command) || VGMCommand_isStream(command) || VGMCommand_isLoopStart(command) || VGMCommand_isLoopEnd(command) || (keepRF5C68Cmds && VGMCommand_isRF5C68Control(command)))
{
optimizedCommands = insertAfterLList(optimizedCommands, command);
// loop start ? -->
Expand Down
5 changes: 5 additions & 0 deletions tools/xgmtool/src/vgmcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ bool VGMCommand_isSame(VGMCommand* source, VGMCommand* com)
return !memcmp(&(source->data[source->offset]), &(com->data[com->offset]), source->size);
}

bool VGMCommand_isRF5C68Control(VGMCommand* source)
{
return source->command == VGM_WRITE_RF5C68;
}

bool VGMCommand_contains(LList* commands, VGMCommand* command)
{
LList* l = commands;
Expand Down
6 changes: 5 additions & 1 deletion tools/xgmtool/src/xgmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool verbose;
bool sampleRateFix;
bool sampleIgnore;
bool delayKeyOff;

bool keepRF5C68Cmds;

int main(int argc, char *argv[ ])
{
Expand Down Expand Up @@ -80,6 +80,7 @@ int main(int argc, char *argv[ ])
printf("-di\tdisable PCM sample auto ignore (it can help when PCM are not properly extracted).\n");
printf("-dr\tdisable PCM sample rate auto fix (it can help when PCM are not properly extracted).\n");
printf("-dd\tdisable delayed KEY OFF event when we have KEY ON/OFF in a single frame (it can fix incorrect instrument sound).\n");
printf("-r\tkeep RF5C68 register write commands.\n");

exit(1);
}
Expand All @@ -90,6 +91,7 @@ int main(int argc, char *argv[ ])
sampleIgnore = true;
sampleRateFix = true;
delayKeyOff = true;
keepRF5C68Cmds = false;

// Open source for binary read (will fail if file does not exist)
if ((infile = fopen(argv[1], "rb")) == NULL)
Expand Down Expand Up @@ -130,6 +132,8 @@ int main(int argc, char *argv[ ])
sys = SYSTEM_NTSC;
else if (!strcasecmp(argv[i], "-p"))
sys = SYSTEM_PAL;
else if (!strcasecmp(argv[i], "-r"))
keepRF5C68Cmds = true;
else
printf("Warning: option %s not recognized (ignored)\n", argv[i]);
}
Expand Down

0 comments on commit d86d7f8

Please sign in to comment.