+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+
+This file is part of Lugaru.
+
+Lugaru 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.
+
+This program 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 this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
#if USE_OPENAL
#include <stdlib.h>
#include <string.h>
+#ifdef _MSC_VER
+#include <alloca.h>
+#endif
+
#include "MacCompatibility.h"
#include "fmod.h"
signed char F_API OPENAL_3D_SetAttributes(int channel, const float *pos, const float *vel)
{
- if (!initialized) return FALSE;
- if ((channel < 0) || (channel >= num_channels)) return FALSE;
+ if (!initialized) return false;
+ if ((channel < 0) || (channel >= num_channels)) return false;
if (pos != NULL)
set_channel_position(channel, pos[0], pos[1], -pos[2]);
// we ignore velocity, since doppler's broken in the Linux AL at the moment...
- return TRUE;
+ return true;
}
void F_API OPENAL_3D_SetDopplerFactor(float scale)
signed char F_API OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned int flags)
{
- if (initialized) return FALSE;
- if (maxsoftwarechannels == 0) return FALSE;
+ if (initialized) return false;
+ if (maxsoftwarechannels == 0) return false;
if (flags != 0) // unsupported.
- return FALSE;
+ return false;
if (!lookup_all_alsyms("./openal.so")) // !!! FIXME: linux specific lib name
{
if (!lookup_all_alsyms("openal.so.1")) // !!! FIXME: linux specific lib name
{
if (!lookup_all_alsyms("openal.so")) // !!! FIXME: linux specific lib name
- return FALSE;
+ return false;
}
}
ALCdevice *dev = alcOpenDevice(NULL);
if (!dev)
- return FALSE;
+ return false;
ALint caps[] = { ALC_FREQUENCY, mixrate, 0 };
ALCcontext *ctx = alcCreateContext(dev, caps);
if (!ctx)
{
alcCloseDevice(dev);
- return FALSE;
+ return false;
}
alcMakeContextCurrent(ctx);
alGenSources(1, &channels[i].sid); // !!! FIXME: verify this didn't fail!
initialized = true;
- return TRUE;
+ return true;
}
void F_API OPENAL_Close()
signed char F_API OPENAL_GetPaused(int channel)
{
- if (!initialized) return FALSE;
- if ((channel < 0) || (channel >= num_channels)) return FALSE;
+ if (!initialized) return false;
+ if ((channel < 0) || (channel >= num_channels)) return false;
if (channels[channel].startpaused)
- return(TRUE);
+ return(true);
ALint state = 0;
alGetSourceiv(channels[channel].sid, AL_SOURCE_STATE, &state);
- return((state == AL_PAUSED) ? TRUE : FALSE);
+ return((state == AL_PAUSED) ? true : false);
}
unsigned int F_API OPENAL_GetLoopMode(int channel)
signed char F_API OPENAL_IsPlaying(int channel)
{
- if (!initialized) return FALSE;
- if ((channel < 0) || (channel >= num_channels)) return FALSE;
+ if (!initialized) return false;
+ if ((channel < 0) || (channel >= num_channels)) return false;
ALint state = 0;
alGetSourceiv(channels[channel].sid, AL_SOURCE_STATE, &state);
- return((state == AL_PLAYING) ? TRUE : FALSE);
+ return((state == AL_PLAYING) ? true : false);
}
int F_API OPENAL_PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused)
signed char F_API OPENAL_Sample_SetMode(FSOUND_SAMPLE *sptr, unsigned int mode)
{
- if (!initialized) return FALSE;
- if ((mode != FSOUND_LOOP_NORMAL) && (mode != FSOUND_LOOP_OFF)) return FALSE;
- if (!sptr) return FALSE;
+ if (!initialized) return false;
+ if ((mode != FSOUND_LOOP_NORMAL) && (mode != FSOUND_LOOP_OFF)) return false;
+ if (!sptr) return false;
sptr->mode = mode;
- return TRUE;
+ return true;
}
signed char F_API OPENAL_Sample_SetMinMaxDistance(FSOUND_SAMPLE *sptr, float mindist, float maxdist)
{
- if (!initialized) return FALSE;
- if (sptr == NULL) return FALSE;
+ if (!initialized) return false;
+ if (sptr == NULL) return false;
sptr->min_distance = mindist;
// we ignore maxdist. It's not really important to this game, and the
// FMOD docs suggest that it's worthless anyhow.
signed char F_API OPENAL_SetFrequency(int channel, int freq)
{
- if (!initialized) return FALSE;
+ if (!initialized) return false;
if (channel == FSOUND_ALL)
{
for (int i = 0; i < num_channels; i++)
OPENAL_SetFrequency(i, freq);
- return TRUE;
+ return true;
}
- if ((channel < 0) || (channel >= num_channels)) return FALSE;
+ if ((channel < 0) || (channel >= num_channels)) return false;
if (freq == 8012) // hack
alSourcef(channels[channel].sid, AL_PITCH, 8012.0f / 44100.0f);
else
alSourcef(channels[channel].sid, AL_PITCH, 1.0f);
- return TRUE;
+ return true;
}
signed char F_API OPENAL_SetVolume(int channel, int vol)
{
- if (!initialized) return FALSE;
+ if (!initialized) return false;
if (channel == FSOUND_ALL)
{
for (int i = 0; i < num_channels; i++)
OPENAL_SetVolume(i, vol);
- return TRUE;
+ return true;
}
- if ((channel < 0) || (channel >= num_channels)) return FALSE;
+ if ((channel < 0) || (channel >= num_channels)) return false;
if (vol < 0) vol = 0;
else if (vol > 255) vol = 255;
ALfloat gain = ((ALfloat) vol) / 255.0f;
alSourcef(channels[channel].sid, AL_GAIN, gain);
- return TRUE;
+ return true;
}
signed char F_API OPENAL_SetPaused(int channel, signed char paused)
{
- if (!initialized) return FALSE;
+ if (!initialized) return false;
if (channel == FSOUND_ALL)
{
for (int i = 0; i < num_channels; i++)
OPENAL_SetPaused(i, paused);
- return TRUE;
+ return true;
}
- if ((channel < 0) || (channel >= num_channels)) return FALSE;
+ if ((channel < 0) || (channel >= num_channels)) return false;
ALint state = 0;
if (channels[channel].startpaused)
alSourcePlay(channels[channel].sid);
channels[channel].startpaused = false;
}
- return TRUE;
+ return true;
}
void F_API OPENAL_SetSFXMasterVolume(int volume)
signed char F_API OPENAL_StopSound(int channel)
{
- if (!initialized) return FALSE;
+ if (!initialized) return false;
if (channel == FSOUND_ALL)
{
for (int i = 0; i < num_channels; i++)
OPENAL_StopSound(i);
- return TRUE;
+ return true;
}
- if ((channel < 0) || (channel >= num_channels)) return FALSE;
+ if ((channel < 0) || (channel >= num_channels)) return false;
alSourceStop(channels[channel].sid);
channels[channel].startpaused = false;
- return TRUE;
+ return true;
}
FSOUND_STREAM * F_API OPENAL_Stream_Open(const char *name_or_data, unsigned int mode, int offset, int length)
signed char F_API OPENAL_Stream_Stop(FSOUND_STREAM *stream)
{
- if (!initialized) return FALSE;
+ if (!initialized) return false;
for (int i = 0; i < num_channels; i++)
{
if (channels[i].sample == (FSOUND_SAMPLE *) stream)
channels[i].startpaused = false;
}
}
- return TRUE;
+ return true;
}
signed char F_API OPENAL_Stream_SetMode(FSOUND_STREAM *stream, unsigned int mode)
signed char F_API OPENAL_SetOutput(int outputtype)
{
- return TRUE;
+ return true;
}
#endif