- Changed MUS playback to use MIDI streams, like it did during the early days

of ZDoom, except now the entire song isn't prebuffered in large chunks, so
  I can insert MIDI events into the playback with fairly low latency. This
  should offer more precise timing than the combination of low-level MIDI and
  WaitForSingleObject timeouts.


SVN r783 (trunk)
This commit is contained in:
Randy Heit 2008-03-04 06:36:23 +00:00
commit 69cebb7e57
6 changed files with 342 additions and 172 deletions

View file

@ -62,6 +62,7 @@
#include "templates.h"
#include "gameconfigfile.h"
#include "v_font.h"
#include "i_musicinterns.h"
#include "stats.h"
@ -85,6 +86,7 @@ UINT TimerPeriod;
UINT TimerEventID;
UINT MillisecondsPerTic;
HANDLE NewTicArrived;
HANDLE MusicEvent;
uint32 LanguageIDs[4];
void CalculateCPUSpeed ();
@ -173,7 +175,15 @@ int I_WaitForTicEvent (int prevtic)
{
while (prevtic >= tics)
{
WaitForSingleObject (NewTicArrived, 1000/TICRATE);
HANDLE handles[2] = { NewTicArrived, MusicEvent };
switch(WaitForMultipleObjects(1 + (MusicEvent != NULL), handles, FALSE, 1000/TICRATE))
{
case WAIT_OBJECT_0 + 1:
if (currSong != NULL)
{
currSong->ServiceEvent();
}
}
}
return tics;
@ -435,6 +445,11 @@ void I_Init (void)
I_WaitForTic = I_WaitForTicPolled;
}
if ((MusicEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL)
{
Printf ("Creation of music event failed.");
}
atterm (I_ShutdownSound);
I_InitSound ();
}
@ -500,6 +515,8 @@ void I_Quit (void)
timeKillEvent (TimerEventID);
if (NewTicArrived)
CloseHandle (NewTicArrived);
if (MusicEvent)
CloseHandle (MusicEvent);
timeEndPeriod (TimerPeriod);