2007-06-28 10:47:08 -07:00
|
|
|
//*
|
|
|
|
//
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2006-09-23 11:38:12 -07:00
|
|
|
#include "lib/framework/frameresource.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "tracklib.h"
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/gamelib/priority.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
//*
|
|
|
|
//
|
|
|
|
// defines
|
|
|
|
#define MAX_TRACKS ( 600 )
|
|
|
|
|
|
|
|
//*
|
|
|
|
//
|
|
|
|
// static global variables
|
|
|
|
// array of pointers to sound effects
|
|
|
|
static TRACK **g_apTrack;
|
|
|
|
|
|
|
|
// number of tracks loaded
|
|
|
|
static SDWORD g_iCurTracks = 0;
|
|
|
|
static SDWORD g_iSamples = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// static SDWORD g_iMaxSamples;
|
|
|
|
//
|
|
|
|
static SDWORD g_iMaxSameSamples;
|
|
|
|
|
|
|
|
// flag set when system is active (for callbacks etc)
|
|
|
|
static BOOL g_bSystemActive = FALSE;
|
|
|
|
static BOOL g_bDevVolume = FALSE;
|
|
|
|
static AUDIO_CALLBACK g_pStopTrackCallback = NULL;
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-09-19 11:45:48 -07:00
|
|
|
static BOOL sound_CheckDevice( void )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// * // Bah, not needed! --Qamly. #ifdef WIN32MM WAVEOUTCAPS waveCaps;
|
|
|
|
// * MMRESULT mmRes;
|
|
|
|
// * // check wave out device(s) present if ( waveOutGetNumDevs() == 0 ) { DBPRINTF(
|
|
|
|
// * ("sound_CheckDevice: error in waveOutGetNumDevs\n") );
|
|
|
|
// * return FALSE;
|
|
|
|
// * } // default to using first device: check volume control caps mmRes =
|
|
|
|
// * waveOutGetDevCaps( 0, (LPWAVEOUTCAPS) &waveCaps, sizeof(WAVEOUTCAPS) );
|
|
|
|
// * if ( mmRes != MMSYSERR_NOERROR ) { DBPRINTF( ("sound_CheckDevice: error in
|
|
|
|
// * waveOutGetDevCaps\n") );
|
|
|
|
// * return FALSE;
|
|
|
|
// * } // verify device supports volume changes // if ( waveCaps.dwSupport &
|
|
|
|
// * WAVECAPS_VOLUME ) { return TRUE;
|
|
|
|
// * } else { DBPRINTF( ("sound_CheckDevice: wave out device doesn't support volume
|
|
|
|
// * changes\n") );
|
|
|
|
// * return FALSE;
|
|
|
|
// * } #endif Checking if needed
|
|
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-04-01 09:50:19 -08:00
|
|
|
BOOL sound_Init( SDWORD iMaxSameSamples )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
#ifdef USE_COMPRESSED_SPEECH
|
2006-09-13 02:09:05 -07:00
|
|
|
void * lpMsgBuf;
|
2007-06-28 10:47:08 -07:00
|
|
|
#endif
|
|
|
|
SDWORD i;
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
//
|
|
|
|
// hWnd;
|
|
|
|
//
|
|
|
|
g_iMaxSameSamples = iMaxSameSamples;
|
|
|
|
g_iCurTracks = 0;
|
|
|
|
g_bDevVolume = sound_CheckDevice();
|
|
|
|
#ifdef USE_COMPRESSED_SPEECH
|
|
|
|
if ( !LoadLibrary("MSACM32.DLL") )
|
|
|
|
{
|
|
|
|
FormatMessage
|
|
|
|
(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
(LPTSTR) & lpMsgBuf,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "sound_Init: couldn't load compression manager MSACM32.DLL\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !LoadLibrary("MSADP32.ACM") )
|
|
|
|
{
|
|
|
|
FormatMessage
|
|
|
|
(
|
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
(LPTSTR) & lpMsgBuf,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "sound_Init: couldn't load ADPCM codec MSADP32.ACM\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ( sound_InitLibrary() == FALSE )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "Cannot init sound library\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// init audio array
|
|
|
|
g_apTrack = (TRACK **) MALLOC( sizeof(TRACK* ) * MAX_TRACKS);
|
|
|
|
for ( i = 0; i < MAX_TRACKS; i++ )
|
|
|
|
{
|
|
|
|
g_apTrack[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set system active flag for callbacks
|
|
|
|
g_bSystemActive = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_Shutdown( void )
|
|
|
|
{
|
|
|
|
FREE( g_apTrack );
|
|
|
|
|
|
|
|
// set inactive flag to prevent callbacks coming after shutdown
|
|
|
|
g_bSystemActive = FALSE;
|
|
|
|
sound_ShutdownLibrary();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_GetSystemActive( void )
|
|
|
|
{
|
|
|
|
return g_bSystemActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
//
|
|
|
|
// Vag ID is just used on PSX szFileName just used on PC
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_SetTrackVals
|
|
|
|
(
|
|
|
|
TRACK *psTrack,
|
|
|
|
BOOL bLoop,
|
|
|
|
SDWORD iTrack,
|
|
|
|
SDWORD iVol,
|
|
|
|
SDWORD iPriority,
|
|
|
|
SDWORD iAudibleRadius,
|
|
|
|
SDWORD VagID
|
|
|
|
)
|
|
|
|
{
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( iPriority >= LOW_PRIORITY && iPriority <= HIGH_PRIORITY, "sound_CreateTrack: priority %i out of bounds\n", iPriority );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// add to sound array
|
|
|
|
if ( iTrack < MAX_TRACKS )
|
|
|
|
{
|
|
|
|
if ( g_apTrack[iTrack] != NULL )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_ERROR, "sound_SetTrackVals: track %i already set\n", iTrack );
|
|
|
|
abort();
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-06-02 12:34:58 -07:00
|
|
|
// set track members
|
|
|
|
psTrack->bLoop = bLoop;
|
2007-06-28 10:47:08 -07:00
|
|
|
psTrack->iVol = iVol;
|
|
|
|
psTrack->iPriority = iPriority;
|
|
|
|
psTrack->iAudibleRadius = iAudibleRadius;
|
|
|
|
psTrack->iTime =0; //added, since they really should init all the values. -Q
|
|
|
|
psTrack->iTimeLastFinished = 0;
|
|
|
|
psTrack->iNumPlaying = 0;
|
2006-06-02 12:34:58 -07:00
|
|
|
psTrack->bCompressed =0; //added this was the bugger that caused grief for .net. It was never defined. -Q
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// I didn't comment the below value out, so I guess NOT needed. -Q
|
|
|
|
//
|
|
|
|
// VagID;
|
|
|
|
//
|
|
|
|
// set global
|
|
|
|
g_apTrack[iTrack] = psTrack;
|
|
|
|
|
|
|
|
// increment current sound
|
|
|
|
g_iCurTracks++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-09-19 11:45:48 -07:00
|
|
|
static BOOL sound_AddTrack( TRACK *pTrack )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
// add to sound array
|
|
|
|
if ( g_iCurTracks < MAX_TRACKS )
|
|
|
|
{
|
|
|
|
// set pointer in table
|
|
|
|
g_apTrack[g_iCurTracks] = pTrack;
|
|
|
|
|
|
|
|
// increment current sound
|
|
|
|
g_iCurTracks++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_ERROR, "sound_AddTrack: all tracks used: increase MAX_TRACKS\n" );
|
|
|
|
abort();
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-09-17 13:39:25 -07:00
|
|
|
TRACK *sound_LoadTrackFromBuffer(char *pBuffer, UDWORD udwSize)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~
|
|
|
|
TRACK *pTrack;
|
|
|
|
//~~~~~~~~~~~~
|
|
|
|
|
|
|
|
// allocate track
|
|
|
|
pTrack = (TRACK *) MALLOC( sizeof(TRACK) );
|
2006-02-03 14:00:43 -08:00
|
|
|
memset(pTrack, 0, sizeof(TRACK));
|
2007-06-28 10:47:08 -07:00
|
|
|
if ( pTrack == NULL )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_ERROR, "sound_LoadTrackFromBuffer: couldn't allocate memory\n" );
|
|
|
|
abort();
|
2007-06-28 10:47:08 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pTrack->bMemBuffer = TRUE;
|
2006-11-03 13:35:50 -08:00
|
|
|
pTrack->pName = (char*)MALLOC( strlen(GetLastResourceFilename()) + 1 );
|
2007-06-28 10:47:08 -07:00
|
|
|
if ( pTrack->pName == NULL )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_ERROR, "sound_LoadTrackFromBuffer: couldn't allocate memory\n" );
|
|
|
|
abort();
|
2007-06-28 10:47:08 -07:00
|
|
|
FREE( pTrack );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy( pTrack->pName, GetLastResourceFilename() );
|
|
|
|
pTrack->resID = GetLastHashName();
|
|
|
|
if ( sound_ReadTrackFromBuffer(pTrack, pBuffer, udwSize) == FALSE )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef USE_COMPRESSED_SPEECH
|
|
|
|
// flag compressed audio load
|
|
|
|
if ( pTrack->bCompressed == TRUE )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "sound_LoadTrackFromBuffer: %s is compressed!\n", pTrack->pName );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return pTrack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-08-12 09:52:37 -07:00
|
|
|
BOOL sound_LoadTrackFromFile(char szFileName[])
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~
|
|
|
|
TRACK *pTrack;
|
|
|
|
//~~~~~~~~~~~~
|
|
|
|
|
|
|
|
// allocate track
|
|
|
|
pTrack = (TRACK *) MALLOC( sizeof(TRACK) );
|
|
|
|
if ( pTrack != NULL )
|
|
|
|
{
|
|
|
|
pTrack->bMemBuffer = FALSE;
|
2006-11-03 13:35:50 -08:00
|
|
|
pTrack->pName = (char*)MALLOC( strlen((char*) szFileName) + 1 );
|
2007-06-28 10:47:08 -07:00
|
|
|
if ( pTrack->pName == NULL )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_ERROR, "sound_LoadTrackFromFile: Out of memory" );
|
|
|
|
abort();
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy( pTrack->pName, (char*) szFileName );
|
|
|
|
pTrack->resID = HashStringIgnoreCase( (char*) szFileName );
|
|
|
|
if ( sound_ReadTrackFromFile(pTrack, szFileName) == FALSE )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sound_AddTrack( pTrack );
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_ReleaseTrack( TRACK *psTrack )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~
|
|
|
|
SDWORD iTrack;
|
|
|
|
//~~~~~~~~~~~
|
|
|
|
|
|
|
|
if ( psTrack->pName != NULL )
|
|
|
|
{
|
|
|
|
FREE( psTrack->pName );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( iTrack = 0; iTrack < g_iCurTracks; iTrack++ )
|
|
|
|
{
|
|
|
|
if ( g_apTrack[iTrack] == psTrack )
|
|
|
|
{
|
|
|
|
g_apTrack[iTrack] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sound_FreeTrack( psTrack );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_CheckAllUnloaded( void )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~
|
|
|
|
SDWORD iTrack;
|
|
|
|
//~~~~~~~~~~~
|
|
|
|
|
|
|
|
for ( iTrack = 0; iTrack < MAX_TRACKS; iTrack++ )
|
|
|
|
{
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( g_apTrack[iTrack] == NULL, "sound_CheckAllUnloaded: check audio.cfg for duplicate IDs\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_TrackLooped( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->bLoop;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_TrackAudibleRadius( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->iAudibleRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_GetNumPlaying( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->iNumPlaying;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_CheckSample( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( PTRVALID(psSample, sizeof(AUDIO_SAMPLE)), "sound_CheckSample: sample pointer invalid\n" );
|
|
|
|
ASSERT( psSample->iSample >= 0 || psSample->iSample == SAMPLE_NOT_ALLOCATED, "sound_CheckSample: sample %i out of range\n", psSample->iSample );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// psSample;
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_CheckTrack( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
if ( iTrack < 0 || iTrack > g_iCurTracks - 1 )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "sound_CheckTrack: track number %i outside max %i\n", iTrack, g_iCurTracks );
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( g_apTrack[iTrack] == NULL )
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "sound_CheckTrack: track %i NULL\n", iTrack );
|
2007-06-28 10:47:08 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_GetTrackTime( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->iTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_GetTrackPriority( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->iPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_GetTrackVolume( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->iVol;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_GetTrackAudibleRadius( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->iAudibleRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-09-17 13:39:25 -07:00
|
|
|
const char *sound_GetTrackName( SDWORD iTrack )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
if ( iTrack == SAMPLE_NOT_FOUND ) return NULL;
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( g_apTrack[iTrack] != NULL, "sound_GetTrackName: unallocated track" );
|
2006-02-03 14:00:43 -08:00
|
|
|
return g_apTrack[iTrack] ? g_apTrack[iTrack]->pName : "unallocated";
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
UDWORD sound_GetTrackHashName( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
if (iTrack == 0 || iTrack == SAMPLE_NOT_FOUND)
|
|
|
|
return 0;
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( g_apTrack[iTrack] != NULL, "sound_GetTrackName: unallocated track" );
|
2006-02-03 14:00:43 -08:00
|
|
|
return g_apTrack[iTrack] ? g_apTrack[iTrack]->resID : 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_Play2DTrack( AUDIO_SAMPLE *psSample, BOOL bQueued )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
TRACK *psTrack;
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
psTrack = g_apTrack[psSample->iTrack];
|
|
|
|
|
2005-11-29 08:20:35 -08:00
|
|
|
if (psTrack == NULL) return FALSE;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* // check only playing compressed audio on queue channel
|
|
|
|
#ifdef USE_COMPRESSED_SPEECH
|
|
|
|
if ( bQueued && !psTrack->bCompressed )
|
|
|
|
{
|
|
|
|
DBPRINTF( ("sound_PlayTrack: trying to play uncompressed speech %s!\n", psTrack->pName) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !bQueued && psTrack->bCompressed )
|
|
|
|
{
|
|
|
|
DBPRINTF( ("sound_PlayTrack: trying to play compressed audio %s!\n", psTrack->pName) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
if ( psTrack->bCompressed )
|
|
|
|
{
|
|
|
|
DBPRINTF( ("sound_PlayTrack: trying to play compressed speech %s!\n", psTrack->pName) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
return sound_Play2DSample( psTrack, psSample, bQueued );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_Play3DTrack( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
TRACK *psTrack;
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
psTrack = g_apTrack[psSample->iTrack];
|
|
|
|
/* if ( psTrack->bCompressed )
|
|
|
|
{
|
|
|
|
DBPRINTF( ("sound_PlayTrack: trying to play compressed audio %s!\n", psTrack->pName) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return sound_Play3DSample( psTrack, psSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_StopTrack( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
sound_CheckSample( psSample );
|
|
|
|
if ( psSample->iSample != SAMPLE_NOT_ALLOCATED )
|
|
|
|
{
|
|
|
|
sound_StopSample( psSample->iSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
// do stopped callback
|
|
|
|
if ( g_pStopTrackCallback != NULL && psSample->psObj != NULL )
|
|
|
|
{
|
|
|
|
( g_pStopTrackCallback ) ( psSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
// update number of samples playing
|
|
|
|
g_iSamples--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_PauseTrack( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
if ( psSample->iSample != SAMPLE_NOT_ALLOCATED )
|
|
|
|
{
|
|
|
|
sound_StopSample( psSample->iSample );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_FinishedCallback( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
sound_CheckSample( psSample );
|
|
|
|
if ( g_apTrack[psSample->iTrack] != NULL )
|
|
|
|
{
|
|
|
|
g_apTrack[psSample->iTrack]->iTimeLastFinished = sound_GetGameTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
// call user callback if specified
|
|
|
|
if ( psSample->pCallback != NULL )
|
|
|
|
{
|
|
|
|
( psSample->pCallback ) ( psSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
// set remove flag
|
|
|
|
psSample->bRemove = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_GetTrackID( TRACK *psTrack )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~
|
|
|
|
SDWORD i = 0;
|
|
|
|
//~~~~~~~~~~
|
|
|
|
|
|
|
|
// find matching track
|
|
|
|
for ( i = 0; i < MAX_TRACKS; i++ )
|
|
|
|
{
|
|
|
|
if ( (g_apTrack[i] != NULL) && (g_apTrack[i] == psTrack) )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if matching track found return it else find empty track
|
|
|
|
if ( i < MAX_TRACKS )
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return SAMPLE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
SDWORD sound_GetAvailableID( void )
|
|
|
|
{
|
|
|
|
//~~~~~~
|
|
|
|
SDWORD i;
|
|
|
|
//~~~~~~
|
|
|
|
|
|
|
|
for ( i = 0; i < MAX_TRACKS; i++ )
|
|
|
|
{
|
|
|
|
if ( g_apTrack[i] == NULL )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( i < MAX_TRACKS, "sound_GetTrackID: unused track not found!\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
if ( i < MAX_TRACKS )
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return SAMPLE_NOT_ALLOCATED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_SetStoppedCallback( AUDIO_CALLBACK pStopTrackCallback )
|
|
|
|
{
|
|
|
|
g_pStopTrackCallback = pStopTrackCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
UDWORD sound_GetTrackTimeLastFinished( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
return g_apTrack[iTrack]->iTimeLastFinished;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_SetTrackTimeLastFinished( SDWORD iTrack, UDWORD iTime )
|
|
|
|
{
|
|
|
|
sound_CheckTrack( iTrack );
|
|
|
|
g_apTrack[iTrack]->iTimeLastFinished = iTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
//
|