Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve loading a DLS file and searching for instruments in it #4

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion arm-wt-22k/lib_src/eas_mdls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,17 @@ static EAS_RESULT Parse_insh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_
if (bank & 0x7fff8080)
{
{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS bank number is out of range: %08lx\n", bank); */ }
bank &= 0xff7f;
}
if (bank & 0x80000000u)
{
/* drum instrument */
bank &= 0x7f7f;
bank |= 0x10000;
}
else
{
/* melodic instrument */
bank &= 0x7f7f;
}
if (program > 127)
{
Expand Down
90 changes: 89 additions & 1 deletion arm-wt-22k/lib_src/eas_voicemgt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,94 @@ static EAS_RESULT VMFindDLSProgram (const S_DLS *pDLS, EAS_U32 bank, EAS_U8 prog
}
}

/* also search bank 0 when default bank (MSB) is used */
if (((bank & 0xFF00) == DEFAULT_MELODY_BANK_NUMBER) || ((bank & 0xFF00) == DEFAULT_RHYTHM_BANK_NUMBER))
{
/* establish locale */
locale = ((bank & 0x100FF) << 8) | programNum;

/* search for program */
for (i = 0, p = pDLS->pDLSPrograms; i < pDLS->numDLSPrograms; i++, p++)
{
if (p->locale == locale)
{
*pRegionIndex = p->regionIndex;
return EAS_SUCCESS;
}
}
}

/* fall back to default bank */
if ((bank != DEFAULT_MELODY_BANK_NUMBER) && (bank != (0x10000 | DEFAULT_RHYTHM_BANK_NUMBER)))
{
/* establish locale */
if (bank & 0x10000)
{
locale = ((0x10000 | DEFAULT_RHYTHM_BANK_NUMBER) << 8) | programNum;
}
else
{
locale = (DEFAULT_MELODY_BANK_NUMBER << 8) | programNum;
}

/* search for program */
for (i = 0, p = pDLS->pDLSPrograms; i < pDLS->numDLSPrograms; i++, p++)
{
if (p->locale == locale)
{
*pRegionIndex = p->regionIndex;
return EAS_SUCCESS;
}
}

/* also search bank 0 */

/* establish locale */
locale = ((bank & 0x10000) << 8) | programNum;

/* search for program */
for (i = 0, p = pDLS->pDLSPrograms; i < pDLS->numDLSPrograms; i++, p++)
{
if (p->locale == locale)
{
*pRegionIndex = p->regionIndex;
return EAS_SUCCESS;
}
}
}

/* switch to program 0 in the default bank, when searching for drum instrument */
if ((bank & 0x10000) && programNum)
{
/* establish locale */
locale = ((0x10000 | DEFAULT_RHYTHM_BANK_NUMBER) << 8);

/* search for program */
for (i = 0, p = pDLS->pDLSPrograms; i < pDLS->numDLSPrograms; i++, p++)
{
if (p->locale == locale)
{
*pRegionIndex = p->regionIndex;
return EAS_SUCCESS;
}
}

/* also search bank 0 */

/* establish locale */
locale = (0x10000 << 8);

/* search for program */
for (i = 0, p = pDLS->pDLSPrograms; i < pDLS->numDLSPrograms; i++, p++)
{
if (p->locale == locale)
{
*pRegionIndex = p->regionIndex;
return EAS_SUCCESS;
}
}
}

return EAS_FAILURE;
}
#endif
Expand Down Expand Up @@ -2729,7 +2817,7 @@ void VMProgramChange (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, EAS_U8 channel, E

#ifdef DLS_SYNTHESIZER
/* first check for DLS program that may overlay the internal instrument */
if (VMFindDLSProgram(pSynth->pDLS, bank, program, &regionIndex) != EAS_SUCCESS)
if (VMFindDLSProgram(pSynth->pDLS, bank | ((pChannel->channelFlags & CHANNEL_FLAG_RHYTHM_CHANNEL) ? 0x10000 : 0), program, &regionIndex) != EAS_SUCCESS)
#endif

/* braces to support 'if' clause above */
Expand Down