2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
//*
|
|
|
|
//
|
2006-11-06 06:40:07 -08:00
|
|
|
#include <string.h>
|
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 AUDIO_CALLBACK g_pStopTrackCallback = NULL;
|
|
|
|
|
|
|
|
//*
|
|
|
|
//
|
2007-01-10 14:50:09 -08:00
|
|
|
// Function prototypes
|
|
|
|
static void sound_CheckSample( AUDIO_SAMPLE *psSample );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-04-01 09:50:19 -08:00
|
|
|
BOOL sound_Init( SDWORD iMaxSameSamples )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
SDWORD i;
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
g_iMaxSameSamples = iMaxSameSamples;
|
|
|
|
g_iCurTracks = 0;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_SetTrackVals
|
|
|
|
(
|
|
|
|
TRACK *psTrack,
|
|
|
|
BOOL bLoop,
|
|
|
|
SDWORD iTrack,
|
|
|
|
SDWORD iVol,
|
|
|
|
SDWORD iPriority,
|
2006-11-26 03:45:04 -08:00
|
|
|
SDWORD iAudibleRadius
|
2007-06-28 10:47:08 -07:00
|
|
|
)
|
|
|
|
{
|
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
|
|
|
|
2007-04-05 11:43:42 -07:00
|
|
|
if ( !(iTrack < MAX_TRACKS) )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ( g_apTrack[iTrack] != NULL )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-05 11:43:42 -07:00
|
|
|
debug( LOG_ERROR, "sound_SetTrackVals: track %i already set\n", iTrack );
|
|
|
|
abort();
|
|
|
|
return FALSE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-04-05 11:43:42 -07:00
|
|
|
// set track members
|
|
|
|
psTrack->bLoop = bLoop;
|
|
|
|
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;
|
|
|
|
|
|
|
|
// set global
|
|
|
|
g_apTrack[iTrack] = psTrack;
|
|
|
|
|
|
|
|
// increment current sound
|
|
|
|
g_iCurTracks++;
|
|
|
|
|
|
|
|
return TRUE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-09-19 11:45:48 -07:00
|
|
|
static BOOL sound_AddTrack( TRACK *pTrack )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-05 11:43:42 -07:00
|
|
|
if ( !(g_iCurTracks < MAX_TRACKS) )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
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;
|
|
|
|
}
|
2007-04-05 11:43:42 -07:00
|
|
|
|
|
|
|
// add to sound array
|
|
|
|
// set pointer in table
|
|
|
|
g_apTrack[g_iCurTracks] = pTrack;
|
|
|
|
|
|
|
|
// increment current sound
|
|
|
|
g_iCurTracks++;
|
|
|
|
|
|
|
|
return TRUE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
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;
|
|
|
|
}
|
|
|
|
|
2007-02-18 13:30:51 -08:00
|
|
|
pTrack->bMemBuffer = TRUE;
|
|
|
|
|
|
|
|
// Set filename in struct
|
|
|
|
pTrack->pName = (char*)MALLOC( strlen(GetLastResourceFilename()) + 1 );
|
|
|
|
if ( pTrack->pName == NULL )
|
|
|
|
{
|
|
|
|
debug( LOG_ERROR, "sound_LoadTrackFromBuffer: couldn't allocate memory\n" );
|
|
|
|
abort();
|
|
|
|
FREE( pTrack );
|
|
|
|
return NULL;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
2007-02-18 13:30:51 -08:00
|
|
|
strcpy( pTrack->pName, GetLastResourceFilename() );
|
|
|
|
|
|
|
|
if ( sound_ReadTrackFromBuffer(pTrack, pBuffer, udwSize) == FALSE )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pTrack;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
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) );
|
2007-04-05 11:43:42 -07:00
|
|
|
if ( pTrack == NULL )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pTrack->bMemBuffer = FALSE;
|
|
|
|
pTrack->pName = (char*)MALLOC( strlen((char*) szFileName) + 1 );
|
|
|
|
if ( pTrack->pName == NULL )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-05 11:43:42 -07:00
|
|
|
debug( LOG_ERROR, "sound_LoadTrackFromFile: Out of memory" );
|
|
|
|
abort();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy( pTrack->pName, (char*) szFileName );
|
|
|
|
if ( sound_ReadTrackFromFile(pTrack, szFileName) == FALSE )
|
|
|
|
{
|
|
|
|
return FALSE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-04-05 11:43:42 -07:00
|
|
|
return sound_AddTrack( pTrack );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2007-02-19 13:52:27 -08:00
|
|
|
void sound_ReleaseTrack( TRACK *psTrack )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//~~~~~~~~~~~
|
|
|
|
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 );
|
2007-02-19 13:52:27 -08:00
|
|
|
FREE( psTrack );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2007-01-10 14:50:09 -08:00
|
|
|
static void sound_CheckSample( AUDIO_SAMPLE *psSample )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-03 06:20:41 -07:00
|
|
|
ASSERT( psSample != NULL, "sound_CheckSample: sample pointer invalid\n" );
|
2007-03-16 09:20:16 -07:00
|
|
|
ASSERT( psSample->iSample >= 0 || psSample->iSample == (ALuint)SAMPLE_NOT_ALLOCATED, "sound_CheckSample: sample %i out of range\n", psSample->iSample );
|
|
|
|
// FIXME iSample always >= 0 !
|
|
|
|
// FIXME Leaving as is because if this is not always true it asserts too often
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_CheckTrack( SDWORD iTrack )
|
|
|
|
{
|
|
|
|
if ( iTrack < 0 || iTrack > g_iCurTracks - 1 )
|
|
|
|
{
|
2006-11-04 13:05:31 -08:00
|
|
|
debug( LOG_SOUND, "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-11-04 13:05:31 -08:00
|
|
|
debug( LOG_SOUND, "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
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_Play2DTrack( AUDIO_SAMPLE *psSample, BOOL bQueued )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
TRACK *psTrack;
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
|
2006-11-04 13:05:31 -08:00
|
|
|
if (!sound_CheckTrack(psSample->iTrack))
|
|
|
|
return FALSE;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
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
|
|
|
return sound_Play2DSample( psTrack, psSample, bQueued );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_Play3DTrack( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
TRACK *psTrack;
|
|
|
|
//~~~~~~~~~~~~~
|
|
|
|
|
2006-11-04 13:05:31 -08:00
|
|
|
if (!sound_CheckTrack(psSample->iTrack))
|
|
|
|
return FALSE;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
psTrack = g_apTrack[psSample->iTrack];
|
|
|
|
return sound_Play3DSample( psTrack, psSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_StopTrack( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
sound_CheckSample( psSample );
|
2007-03-16 09:20:16 -07:00
|
|
|
if ( psSample->iSample != (ALuint)SAMPLE_NOT_ALLOCATED )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2007-03-16 09:20:16 -07:00
|
|
|
if ( psSample->iSample != (ALuint)SAMPLE_NOT_ALLOCATED )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|