Skip to content

Commit 5785d47

Browse files
committed
Reserve mixer channel for MIDI playback
1 parent 842edc9 commit 5785d47

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

kauai/src/sndsdl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ ASSERTNAME
1313

1414
#define AssertDoMix(x) AssertDo(x >= 0, Mix_GetError());
1515

16-
typedef int SDLChannelId;
17-
1816
// Maximum number of SDL channels that will be allocated
1917
const SDLChannelId kSDLChannelIdMac = 32;
2018
const SDLChannelId kSDLChannelIdInvalid = -1;
2119

20+
// Channel ID reserved for MIDI playback
21+
const SDLChannelId kSDLChannelIdMidi = 0;
22+
2223
// Number of milliseconds after playing a new sound that pause will be ignored.
2324
// This is a hack to work around a difference in behaviour in AudioMan.
2425
// When AudioMan plays a sound it will mix and write a chunk of the sound to the
@@ -425,6 +426,9 @@ PSNQUE SDLSoundDevice::_PsnqueNew(void)
425426
bool rgfAllocated[kSDLChannelIdMac];
426427
ClearPb(rgfAllocated, SIZEOF(rgfAllocated));
427428

429+
// Reserve channel for MIDI playback
430+
rgfAllocated[kSDLChannelIdMidi] = fTrue;
431+
428432
for (int32_t iqueue = 0; iqueue < _pglsnqd->IvMac(); iqueue++)
429433
{
430434
SNQD snqd;
@@ -438,6 +442,7 @@ PSNQUE SDLSoundDevice::_PsnqueNew(void)
438442

439443
if (ichannel >= 0 && ichannel < CvFromRgv(rgfAllocated))
440444
{
445+
Assert(!rgfAllocated[ichannel], "Mixer channel used by multiple sound queues");
441446
rgfAllocated[ichannel] = fTrue;
442447
}
443448
else

kauai/src/sndsdl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
// Custom SDL message used for notifications
1414
#define SDL_USEREVENT_SOUND_FINISHED (SDL_USEREVENT + 1)
1515

16+
typedef int SDLChannelId;
17+
18+
// Channel ID reserved for MIDI playback
19+
extern const SDLChannelId kSDLChannelIdMidi;
20+
1621
typedef class SDLSoundDevice *PSDLSoundDevice;
1722

1823
#define SDLSoundDevice_PAR SNDMQ

0 commit comments

Comments
 (0)