Skip to content

Commit e930188

Browse files
committed
Reserve mixer channel for MIDI playback
1 parent b8ce6fa commit e930188

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,15 +13,16 @@ 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

2220
const int32_t klwFrequency = 44100;
2321
const int32_t klwChunkSize = 1024;
2422

23+
// Channel ID reserved for MIDI playback
24+
const SDLChannelId kSDLChannelIdMidi = 0;
25+
2526
// Number of milliseconds after playing a new sound that pause will be ignored.
2627
// This is a hack to work around a difference in behaviour in AudioMan.
2728
// When AudioMan plays a sound it will mix and write a chunk of the sound to the
@@ -492,6 +493,9 @@ PSNQUE SDLSoundDevice::_PsnqueNew(void)
492493
bool rgfAllocated[kSDLChannelIdMac];
493494
ClearPb(rgfAllocated, SIZEOF(rgfAllocated));
494495

496+
// Reserve channel for MIDI playback
497+
rgfAllocated[kSDLChannelIdMidi] = fTrue;
498+
495499
for (int32_t iqueue = 0; iqueue < _pglsnqd->IvMac(); iqueue++)
496500
{
497501
SNQD snqd;
@@ -505,6 +509,7 @@ PSNQUE SDLSoundDevice::_PsnqueNew(void)
505509

506510
if (ichannel >= 0 && ichannel < CvFromRgv(rgfAllocated))
507511
{
512+
Assert(!rgfAllocated[ichannel], "Mixer channel used by multiple sound queues");
508513
rgfAllocated[ichannel] = fTrue;
509514
}
510515
else

kauai/src/sndsdl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
// Kauai command ID used to indicate that a sound finished playing
1414
#define cidSDLSoundChannelFinished 110001
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
typedef class SDLSoundNotifier *PSDLSoundNotifier;
1823

0 commit comments

Comments
 (0)