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
|
|
|
//*
|
|
|
|
//
|
|
|
|
// Sound library-specific functions
|
|
|
|
//*
|
|
|
|
//
|
|
|
|
|
|
|
|
// this has to be first
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2007-04-09 05:16:31 -07:00
|
|
|
#include "lib/framework/frameresource.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-04-18 05:40:50 -07:00
|
|
|
#ifdef WZ_OS_MAC
|
2007-04-17 20:10:53 -07:00
|
|
|
#include <OpenAL/al.h>
|
|
|
|
#include <OpenAL/alc.h>
|
2006-08-12 03:45:49 -07:00
|
|
|
#else
|
2007-06-28 10:47:08 -07:00
|
|
|
#include <AL/al.h>
|
|
|
|
#include <AL/alc.h>
|
2006-08-12 03:45:49 -07:00
|
|
|
#endif
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-06-16 12:10:23 -07:00
|
|
|
#include <physfs.h>
|
2006-11-06 06:40:07 -08:00
|
|
|
#include <string.h>
|
2006-06-16 12:10:23 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "tracklib.h"
|
|
|
|
#include "audio.h"
|
2007-04-30 10:58:27 -07:00
|
|
|
#include "oggvorbis.h"
|
2007-01-24 11:42:20 -08:00
|
|
|
|
2006-09-20 12:46:33 -07:00
|
|
|
#define ATTENUATION_FACTOR 0.0003f
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
ALuint current_queue_sample = -1;
|
|
|
|
|
|
|
|
typedef struct SAMPLE_LIST
|
|
|
|
{
|
|
|
|
struct AUDIO_SAMPLE *curr;
|
|
|
|
struct SAMPLE_LIST *next;
|
|
|
|
} SAMPLE_LIST;
|
|
|
|
|
|
|
|
static SAMPLE_LIST *active_samples = NULL;
|
|
|
|
|
|
|
|
static ALfloat sfx_volume = 1.0;
|
|
|
|
static ALfloat sfx3d_volume = 1.0;
|
|
|
|
|
|
|
|
static ALCdevice* device = 0;
|
|
|
|
static ALCcontext* context = 0;
|
|
|
|
|
|
|
|
BOOL openal_initialized = FALSE;
|
|
|
|
|
|
|
|
BOOL cdAudio_Update( void );
|
|
|
|
|
2006-09-19 11:45:48 -07:00
|
|
|
static void PrintOpenALVersion(void)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
debug(LOG_ERROR, "OpenAL Vendor: %s\n"
|
|
|
|
"OpenAL Version: %s\n"
|
|
|
|
"OpenAL Renderer: %s\n"
|
|
|
|
"OpenAL Extensions: %s\n",
|
|
|
|
alGetString(AL_VENDOR), alGetString(AL_VERSION),
|
|
|
|
alGetString(AL_RENDERER), alGetString(AL_EXTENSIONS));
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_InitLibrary( void )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
int err=0;
|
|
|
|
ALfloat listenerVel[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
ALfloat listenerOri[6] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0 };
|
|
|
|
// int contextAttributes[] = { 0 };
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
device = alcOpenDevice(0);
|
|
|
|
if(device == 0) {
|
|
|
|
PrintOpenALVersion();
|
|
|
|
debug(LOG_ERROR, "Couldn't open audio device.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
context = alcCreateContext(device, NULL); //NULL was contextAttributes
|
|
|
|
alcMakeContextCurrent(context);
|
2006-06-02 12:34:58 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
err = alcGetError(device);
|
|
|
|
if (err != ALC_NO_ERROR) {
|
|
|
|
PrintOpenALVersion();
|
|
|
|
debug(LOG_ERROR, "Couldn't initialize audio context: %s",
|
|
|
|
alcGetString(device, err));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
openal_initialized = TRUE;
|
|
|
|
|
|
|
|
// Clear Error Codes
|
|
|
|
alGetError();
|
|
|
|
alcGetError(device);
|
|
|
|
|
|
|
|
// Check what version of Open AL we are using
|
|
|
|
debug(LOG_SOUND, "OpenAL Version : %s",alGetString(AL_VERSION));
|
|
|
|
debug(LOG_SOUND, "OpenAL Renderer : %s",alGetString(AL_RENDERER));
|
|
|
|
debug(LOG_SOUND, "OpenAL Extensions : %s",alGetString(AL_EXTENSIONS));
|
|
|
|
|
|
|
|
|
2007-01-17 13:39:38 -08:00
|
|
|
alListener3f( AL_POSITION, 0, 0, 0 );
|
2007-06-28 10:47:08 -07:00
|
|
|
alListenerfv( AL_VELOCITY, listenerVel );
|
|
|
|
alListenerfv( AL_ORIENTATION, listenerOri );
|
|
|
|
alDistanceModel( AL_NONE );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_ShutdownLibrary( void )
|
|
|
|
{
|
2006-08-23 05:58:48 -07:00
|
|
|
SAMPLE_LIST * aSample = active_samples, * tmpSample = NULL;
|
|
|
|
|
|
|
|
debug(LOG_SOUND, "sound_ShutdownLibrary: starting shutdown");
|
2007-06-28 10:47:08 -07:00
|
|
|
if(context != 0) {
|
|
|
|
#ifdef WIN32
|
|
|
|
/* Ifdef'ed out the two lines below on Linux since this caused some versions
|
|
|
|
* of OpenAL to hang on exit. - Per */
|
2006-08-23 05:58:48 -07:00
|
|
|
debug(LOG_SOUND, "sound_ShutdownLibrary: make default context NULL");
|
2007-06-28 10:47:08 -07:00
|
|
|
alcMakeContextCurrent(NULL); //this should work now -Q
|
|
|
|
#endif
|
2006-08-23 05:58:48 -07:00
|
|
|
debug(LOG_SOUND, "sound_ShutdownLibrary: destroy previous context");
|
2007-06-28 10:47:08 -07:00
|
|
|
alcDestroyContext(context); // this gives a long delay on some impl.
|
|
|
|
context = 0;
|
|
|
|
}
|
2006-08-23 05:58:48 -07:00
|
|
|
debug(LOG_SOUND, "sound_ShutdownLibrary: close device");
|
2007-06-28 10:47:08 -07:00
|
|
|
if(device != 0) {
|
|
|
|
alcCloseDevice(device);
|
|
|
|
device = 0;
|
|
|
|
}
|
2006-02-18 10:54:37 -08:00
|
|
|
|
2006-08-23 05:58:48 -07:00
|
|
|
while( aSample )
|
|
|
|
{
|
|
|
|
tmpSample = aSample->next;
|
|
|
|
free( aSample );
|
|
|
|
aSample = tmpSample;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_Update( void )
|
|
|
|
{
|
|
|
|
int err=0;
|
|
|
|
// { // <=== whats up with this ??
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
SAMPLE_LIST **tmp = &active_samples;
|
|
|
|
SAMPLE_LIST *i;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
for ( tmp = &active_samples, i = *tmp; i != NULL; i = *tmp )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~
|
2006-02-11 01:00:20 -08:00
|
|
|
ALenum state = AL_STOPPED;
|
2007-06-28 10:47:08 -07:00
|
|
|
//~~~~~~~~~~
|
|
|
|
|
|
|
|
alGetSourcei( i->curr->iSample, AL_SOURCE_STATE, &state );
|
|
|
|
switch ( state )
|
|
|
|
{
|
|
|
|
case AL_PLAYING:
|
2006-02-11 01:00:20 -08:00
|
|
|
case AL_PAUSED:
|
2007-06-28 10:47:08 -07:00
|
|
|
//
|
|
|
|
// * sound_SetObjectPosition(i->curr->iSample, i->curr->x, i->curr->y, i->curr->z);
|
|
|
|
//
|
|
|
|
tmp = &( i->next );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sound_FinishedCallback( i->curr );
|
2007-03-16 09:20:16 -07:00
|
|
|
if (i->curr->iSample != (ALuint)AL_INVALID) {
|
2006-02-11 01:00:20 -08:00
|
|
|
alDeleteSources( 1, &(i->curr->iSample) );
|
|
|
|
i->curr->iSample = AL_INVALID;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
*tmp = i->next;
|
|
|
|
free( i );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }// <=== whats up with this You trying to make those local only ??
|
|
|
|
|
|
|
|
cdAudio_Update();
|
|
|
|
alcProcessContext(context);
|
|
|
|
err = alcGetError(device);
|
|
|
|
if(err != ALC_NO_ERROR) {
|
|
|
|
debug(LOG_ERROR, "Error while processing audio context: %s",
|
|
|
|
alGetString(err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_QueueSamplePlaying( void )
|
|
|
|
{
|
2007-03-16 09:20:16 -07:00
|
|
|
if ( current_queue_sample == (ALuint)AL_INVALID )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~
|
|
|
|
ALenum state;
|
|
|
|
//~~~~~~~~~~
|
|
|
|
|
|
|
|
alGetSourcei( current_queue_sample, AL_SOURCE_STATE, &state );
|
|
|
|
if ( state == AL_PLAYING )
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-16 09:20:16 -07:00
|
|
|
if (current_queue_sample != (ALuint)AL_INVALID) {
|
2006-02-11 01:00:20 -08:00
|
|
|
alDeleteSources( 1, ¤t_queue_sample );
|
|
|
|
current_queue_sample = AL_INVALID;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
current_queue_sample = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-30 16:52:51 -07:00
|
|
|
/** Decodes an opened OggVorbis file into an OpenAL buffer
|
|
|
|
* \param psTrack pointer to object which will contain the final buffer
|
|
|
|
* \param PHYSFS_fileHandle file handle given by PhysicsFS to the opened file
|
|
|
|
* \return on success the psTrack pointer, otherwise it will be free'd and a NULL pointer is returned instead
|
|
|
|
*/
|
|
|
|
static inline TRACK* sound_DecodeOggVorbisTrack(TRACK *psTrack, PHYSFS_file* PHYSFS_fileHandle)
|
|
|
|
{
|
|
|
|
ALenum format;
|
|
|
|
ALuint buffer;
|
|
|
|
|
|
|
|
OggVorbisDecoderState* decoder = sound_CreateOggVorbisDecoder(PHYSFS_fileHandle, TRUE);
|
|
|
|
soundDataBuffer* soundBuffer;
|
|
|
|
|
2007-04-30 17:04:37 -07:00
|
|
|
soundBuffer = sound_DecodeOggVorbis(decoder, 0, NULL);
|
2007-04-30 16:52:51 -07:00
|
|
|
sound_DestroyOggVorbisDecoder(decoder);
|
|
|
|
|
|
|
|
if (soundBuffer == NULL)
|
|
|
|
{
|
|
|
|
free(psTrack);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine PCM data format
|
|
|
|
format = (soundBuffer->channelCount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
|
|
|
|
|
|
|
|
// Create an OpenAL buffer and fill it with the decoded data
|
|
|
|
alGenBuffers(1, &buffer);
|
|
|
|
alBufferData(buffer, format, soundBuffer->data, soundBuffer->size, soundBuffer->frequency);
|
|
|
|
|
|
|
|
// save buffer name in track
|
|
|
|
psTrack->iBufferName = buffer;
|
|
|
|
|
|
|
|
return psTrack;
|
|
|
|
}
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2007-04-09 05:16:31 -07:00
|
|
|
TRACK* sound_LoadTrackFromFile(const char *fileName)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-09 05:16:31 -07:00
|
|
|
TRACK* pTrack;
|
2007-04-30 09:55:53 -07:00
|
|
|
PHYSFS_file* fileHandle;
|
2007-04-03 04:15:41 -07:00
|
|
|
|
2007-02-18 13:30:51 -08:00
|
|
|
// Use PhysicsFS to open the file
|
2007-04-30 09:55:53 -07:00
|
|
|
fileHandle = PHYSFS_openRead(fileName);
|
|
|
|
if (fileHandle == NULL)
|
2007-04-08 11:51:15 -07:00
|
|
|
{
|
2007-04-30 09:55:53 -07:00
|
|
|
debug(LOG_ERROR, "sound_LoadTrackFromFile: PHYSFS_openRead(\"%s\") failed with error: %s\n", fileName, PHYSFS_getLastError());
|
2007-04-08 11:51:15 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-04-09 05:16:31 -07:00
|
|
|
// allocate track, plus the memory required to contain the filename
|
|
|
|
// one malloc call ensures only one free call is required
|
|
|
|
pTrack = (TRACK*)malloc(sizeof(TRACK) + strlen(GetLastResourceFilename()) + 1);
|
|
|
|
if (pTrack == NULL)
|
|
|
|
{
|
|
|
|
debug( LOG_ERROR, "sound_ConstructTrack: couldn't allocate memory\n" );
|
|
|
|
abort();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize everyting (except for the filename) to zero
|
|
|
|
memset(pTrack, 0, sizeof(TRACK));
|
2007-04-18 05:40:50 -07:00
|
|
|
|
2007-04-09 05:16:31 -07:00
|
|
|
// Set filename pointer and copy the filename into struct
|
|
|
|
pTrack->pName = (char*)pTrack + sizeof(TRACK);
|
2007-04-30 09:55:53 -07:00
|
|
|
strcpy(pTrack->pName, GetLastResourceFilename());
|
2007-04-09 05:16:31 -07:00
|
|
|
|
2007-02-18 13:30:51 -08:00
|
|
|
// Now use sound_ReadTrackFromBuffer to decode the file's contents
|
2007-04-30 16:52:51 -07:00
|
|
|
pTrack = sound_DecodeOggVorbisTrack(pTrack, fileHandle);
|
2007-02-18 14:16:55 -08:00
|
|
|
|
2007-04-30 09:55:53 -07:00
|
|
|
PHYSFS_close(fileHandle);
|
2007-04-09 05:16:31 -07:00
|
|
|
return pTrack;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_FreeTrack( TRACK *psTrack )
|
|
|
|
{
|
2007-04-08 11:51:15 -07:00
|
|
|
alDeleteBuffers( 1, &psTrack->iBufferName );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
int sound_GetMaxVolume( void )
|
|
|
|
{
|
|
|
|
return 32767; // Why this value? -Q
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-09-19 11:45:48 -07:00
|
|
|
static void sound_AddActiveSample( AUDIO_SAMPLE *psSample )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
SAMPLE_LIST *tmp = (SAMPLE_LIST *) malloc( sizeof(SAMPLE_LIST) );
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
tmp->curr = psSample;
|
|
|
|
tmp->next = active_samples;
|
|
|
|
active_samples = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2007-04-12 10:42:15 -07:00
|
|
|
static BOOL sound_SetupChannel( AUDIO_SAMPLE *psSample )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-12 10:42:15 -07:00
|
|
|
sound_AddActiveSample( psSample );
|
|
|
|
|
|
|
|
if (sound_TrackLooped(psSample->iTrack))
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-12 10:42:15 -07:00
|
|
|
return TRUE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-12 10:42:15 -07:00
|
|
|
return FALSE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_Play2DSample( TRACK *psTrack, AUDIO_SAMPLE *psSample, BOOL bQueued )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
ALfloat zero[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
if (sfx_volume == 0.0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
alGenSources( 1, &(psSample->iSample) );
|
|
|
|
alSourcef( psSample->iSample, AL_PITCH, 1.0f );
|
|
|
|
alSourcef( psSample->iSample, AL_GAIN, sfx_volume );
|
|
|
|
alSourcefv( psSample->iSample, AL_POSITION, zero );
|
|
|
|
alSourcefv( psSample->iSample, AL_VELOCITY, zero );
|
2006-09-24 11:53:08 -07:00
|
|
|
alSourcei( psSample->iSample, AL_BUFFER, psTrack->iBufferName );
|
2007-06-28 10:47:08 -07:00
|
|
|
alSourcei( psSample->iSample, AL_SOURCE_RELATIVE, AL_TRUE );
|
2007-04-12 10:42:15 -07:00
|
|
|
alSourcei( psSample->iSample, AL_LOOPING, (sound_SetupChannel(psSample)) ? AL_TRUE : AL_FALSE );
|
2007-06-28 10:47:08 -07:00
|
|
|
alSourcePlay( psSample->iSample );
|
|
|
|
if ( bQueued )
|
|
|
|
{
|
|
|
|
current_queue_sample = psSample->iSample;
|
|
|
|
}
|
|
|
|
else if ( current_queue_sample == psSample->iSample )
|
|
|
|
{
|
|
|
|
current_queue_sample = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_Play3DSample( TRACK *psTrack, AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
ALfloat zero[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
|
|
|
|
if (sfx3d_volume == 0.0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
alGenSources( 1, &(psSample->iSample) );
|
|
|
|
alSourcef( psSample->iSample, AL_PITCH, 1.0 );
|
|
|
|
alSourcef( psSample->iSample, AL_GAIN, sfx3d_volume );
|
|
|
|
sound_SetObjectPosition( psSample->iSample, psSample->x, psSample->y, psSample->z );
|
|
|
|
alSourcefv( psSample->iSample, AL_VELOCITY, zero );
|
2006-09-24 11:53:08 -07:00
|
|
|
alSourcei( psSample->iSample, AL_BUFFER, psTrack->iBufferName );
|
2007-04-12 10:42:15 -07:00
|
|
|
alSourcei( psSample->iSample, AL_LOOPING, (sound_SetupChannel(psSample)) ? AL_TRUE : AL_FALSE );
|
2007-06-28 10:47:08 -07:00
|
|
|
alSourcePlay( psSample->iSample );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2006-09-24 11:53:08 -07:00
|
|
|
BOOL sound_PlayStream( AUDIO_SAMPLE *psSample, const char szFileName[], SDWORD iVol )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_StopSample( UDWORD iSample )
|
|
|
|
{
|
|
|
|
alSourceStop( iSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_SetSamplePan( AUDIO_SAMPLE *psSample, SDWORD iPan )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_SetSampleVolAll( int iVol )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_SetPlayerPos( SDWORD iX, SDWORD iY, SDWORD iZ )
|
|
|
|
{
|
2007-01-17 13:39:38 -08:00
|
|
|
alListener3f( AL_POSITION, iX, iY, iZ );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
2007-01-07 08:28:54 -08:00
|
|
|
/** sets player's sound orientation
|
|
|
|
* \param iX pitch in degree (current function implementation ignores this)
|
|
|
|
* \param iY roll in degree (current function implementation ignores this)
|
|
|
|
* \param iZ yaw in degree
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
void sound_SetPlayerOrientation( SDWORD iX, SDWORD iY, SDWORD iZ )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~
|
|
|
|
float ori[6];
|
|
|
|
//~~~~~~~~~~~
|
|
|
|
|
2007-01-07 08:28:54 -08:00
|
|
|
// convert params to rad
|
2007-02-19 06:10:44 -08:00
|
|
|
// float pitch = (float)iX * M_PI / 180;
|
|
|
|
// float roll = (float)iY * M_PI / 180;
|
2007-01-07 08:28:54 -08:00
|
|
|
float yaw = (float)iZ * M_PI / 180;
|
|
|
|
|
|
|
|
ori[0] = -sin( yaw );
|
|
|
|
ori[1] = cos( yaw );
|
2007-06-28 10:47:08 -07:00
|
|
|
ori[2] = 0;
|
|
|
|
ori[3] = 0;
|
|
|
|
ori[4] = 0;
|
|
|
|
ori[5] = 1;
|
|
|
|
alListenerfv( AL_ORIENTATION, ori );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_SetObjectPosition( SDWORD iSample, SDWORD iX, SDWORD iY, SDWORD iZ )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2007-01-07 08:28:54 -08:00
|
|
|
// coordinates
|
|
|
|
float listenerX, listenerY, listenerZ, dX, dY, dZ;
|
|
|
|
|
|
|
|
// calculation results
|
|
|
|
float distance, gain;
|
2007-06-28 10:47:08 -07:00
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2007-01-07 08:28:54 -08:00
|
|
|
// compute distance
|
|
|
|
alGetListener3f( AL_POSITION, &listenerX, &listenerY, &listenerZ );
|
|
|
|
dX = iX - listenerX; // distances on all axis
|
|
|
|
dY = iY - listenerY;
|
|
|
|
dZ = iZ - listenerZ;
|
|
|
|
distance = sqrt(dX * dX + dY * dY + dZ * dZ); // Pythagorean theorem
|
|
|
|
|
|
|
|
// compute gain
|
|
|
|
gain = 1 - distance * ATTENUATION_FACTOR;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
if ( gain < 0.0 )
|
|
|
|
{
|
|
|
|
gain = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
alSourcef( iSample, AL_GAIN, gain * sfx3d_volume );
|
|
|
|
|
2007-01-08 14:35:43 -08:00
|
|
|
// the alSource3i variant would be better, if it wouldn't provide linker errors however
|
|
|
|
alSource3f( iSample, AL_POSITION, iX, iY, iZ );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_PauseSample( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
alSourcePause( psSample->iSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_ResumeSample( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
alSourcePlay( psSample->iSample );
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_PauseAll( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_ResumeAll( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
void sound_StopAll( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
BOOL sound_SampleIsFinished( AUDIO_SAMPLE *psSample )
|
|
|
|
{
|
|
|
|
//~~~~~~~~~~
|
|
|
|
ALenum state;
|
|
|
|
//~~~~~~~~~~
|
|
|
|
|
|
|
|
alGetSourcei( psSample->iSample, AL_SOURCE_STATE, &state );
|
|
|
|
if ( state == AL_PLAYING )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-16 09:20:16 -07:00
|
|
|
if (psSample->iSample != (ALuint)AL_INVALID)
|
|
|
|
{
|
|
|
|
alDeleteSources( 1, &(psSample->iSample) );
|
|
|
|
psSample->iSample = AL_INVALID;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//*
|
|
|
|
// =======================================================================================================================
|
|
|
|
// =======================================================================================================================
|
|
|
|
//
|
|
|
|
|
|
|
|
SDWORD mixer_GetWavVolume( void )
|
|
|
|
{
|
2006-11-02 12:15:08 -08:00
|
|
|
return (SDWORD)(100*sfx_volume);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void mixer_SetWavVolume( SDWORD iVol )
|
|
|
|
{
|
|
|
|
sfx_volume = iVol * 0.01;
|
|
|
|
|
|
|
|
if (sfx_volume < 0.0) {
|
|
|
|
sfx_volume = 0.0;
|
|
|
|
} else if (sfx_volume > 1.0) {
|
|
|
|
sfx_volume = 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDWORD mixer_Get3dWavVolume( void )
|
|
|
|
{
|
2006-11-02 12:15:08 -08:00
|
|
|
return (SDWORD)(100*sfx3d_volume);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void mixer_Set3dWavVolume( SDWORD iVol )
|
|
|
|
{
|
|
|
|
sfx3d_volume = iVol * 0.01;
|
|
|
|
|
|
|
|
if (sfx3d_volume < 0.0) {
|
|
|
|
sfx3d_volume = 0.0;
|
|
|
|
} else if (sfx3d_volume > 1.0) {
|
|
|
|
sfx3d_volume = 1.0;
|
|
|
|
}
|
|
|
|
}
|