-Smaxx' patch: checks for initialized openal + disables sound options if openal init fails
-other minor changes to lib
--- a/QTfrontend/SDLs.h Tue Jun 30 15:59:02 2009 +0000
+++ b/QTfrontend/SDLs.h Tue Jun 30 17:02:41 2009 +0000
@@ -21,18 +21,20 @@
#include <QStringList>
-extern "C" int openal_init (int memorysize);
+extern "C" int openal_init (unsigned int memorysize);
extern "C" int openal_close (void);
+extern "C" int openal_ready (void);
extern "C" int openal_loadfile (const char *filename);
-extern "C" int openal_toggleloop (int index);
-extern "C" int openal_setvolume (int index, unsigned char percentage);
+extern "C" int openal_toggleloop (unsigned int index);
+extern "C" int openal_setvolume (unsigned int index, unsigned char percentage);
extern "C" int openal_setglobalvolume (unsigned char percentage);
extern "C" int openal_togglemute (void);
-extern "C" int openal_fadeout (int index, unsigned int quantity);
-extern "C" int openal_fadein (int index, unsigned int quantity);
-extern "C" int openal_playsound (int index);
-extern "C" int openal_stopsound (int index);
-extern "C" int openal_pausesound (int index);
+extern "C" int openal_fadeout (unsigned int index, unsigned short int quantity);
+extern "C" int openal_fadein (unsigned int index, unsigned short int quantity);
+extern "C" int openal_fade (unsigned int index, unsigned short int quantity, unsigned char direction);
+extern "C" int openal_playsound (unsigned int index);
+extern "C" int openal_stopsound (unsigned int index);
+extern "C" int openal_pausesound (unsigned int index);
class SDLInteraction : public QObject
{
--- a/QTfrontend/gameuiconfig.cpp Tue Jun 30 15:59:02 2009 +0000
+++ b/QTfrontend/gameuiconfig.cpp Tue Jun 30 17:02:41 2009 +0000
@@ -46,8 +46,8 @@
Form->ui.pageOptions->CBReduceQuality->setChecked(value("video/reducequality", false).toBool());
Form->ui.pageOptions->CBFrontendEffects->setChecked(frontendEffects);
- Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
- Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool());
+ Form->ui.pageOptions->CBEnableSound->setChecked(openal_ready() && value("audio/sound", true).toBool());
+ Form->ui.pageOptions->CBEnableMusic->setChecked(openal_ready() && value("audio/music", true).toBool());
Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt());
Form->ui.pageOptions->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString());
--- a/QTfrontend/pages.cpp Tue Jun 30 15:59:02 2009 +0000
+++ b/QTfrontend/pages.cpp Tue Jun 30 17:02:41 2009 +0000
@@ -195,6 +195,7 @@
}
hbox->addWidget(CBVoicepack, 100);
BtnTestSound = addButton(":/res/PlaySound.png", hbox, 1, true);
+ BtnTestSound->setEnabled(openal_ready());
hbox->setStretchFactor(BtnTestSound, 1);
connect(BtnTestSound, SIGNAL(clicked()), this, SLOT(testSound()));
GBTLayout->addLayout(hbox);
@@ -425,10 +426,12 @@
CBEnableSound = new QCheckBox(AGGroupBox);
CBEnableSound->setText(QCheckBox::tr("Enable sound"));
+ CBEnableSound->setEnabled(openal_ready());
GBAlayout->addWidget(CBEnableSound);
CBEnableMusic = new QCheckBox(AGGroupBox);
CBEnableMusic->setText(QCheckBox::tr("Enable music"));
+ CBEnableMusic->setEnabled(openal_ready());
GBAlayout->addWidget(CBEnableMusic);
QHBoxLayout * GBAvollayout = new QHBoxLayout(0);
@@ -439,6 +442,7 @@
volumeBox = new QSpinBox(AGGroupBox);
volumeBox->setRange(0, 100);
volumeBox->setSingleStep(5);
+ volumeBox->setEnabled(openal_ready());
GBAvollayout->addWidget(volumeBox);
--- a/hedgewars/uSound.pas Tue Jun 30 15:59:02 2009 +0000
+++ b/hedgewars/uSound.pas Tue Jun 30 17:02:41 2009 +0000
@@ -56,18 +56,19 @@
function ChangeVolume(voldelta: LongInt): LongInt;
function AskForVoicepack(name: shortstring): Pointer;
-
+{*remember: LongInt = 32bit; integer = 16bit; byte = 8bit*}
function openal_init (memsize: LongInt) : boolean; cdecl; external OpenALBridge;
function openal_close : boolean; cdecl; external OpenALBridge;
function openal_loadfile (filename: PChar) : LongInt; cdecl; external OpenALBridge;
function openal_toggleloop (index: LongInt) : boolean; cdecl; external OpenALBridge;
-function openal_setvolume (index: LongInt; percentage: byte) : boolean; cdecl; external OpenALBridge;
-function openal_fadeout (index: LongInt; quantity: LongInt) : boolean; cdecl; external OpenALBridge;
-function openal_fadein (index: LongInt; quantity: LongInt) : boolean; cdecl; external OpenALBridge;
+function openal_setvolume (index: LongInt; percentage: byte) : boolean; cdecl; external OpenALBridge;
+function openal_setglobalvolume (percentage: byte) : boolean; cdecl; external OpenALBridge;
+function openal_fadeout (index: LongInt; quantity: integer) : boolean; cdecl; external OpenALBridge;
+function openal_fadein (index: LongInt; quantity: integer) : boolean; cdecl; external OpenALBridge;
+function openal_fade (index: LongInt; quantity: integer; direction: byte) : boolean; cdecl; external OpenALBridge;
function openal_playsound (index: LongInt) : boolean; cdecl; external OpenALBridge;
function openal_pausesound (index: LongInt) : boolean; cdecl; external OpenALBridge;
function openal_stopsound (index: LongInt) : boolean; cdecl; external OpenALBridge;
-function openal_setglobalvolume (percentage: byte) : boolean; cdecl; external OpenALBridge;
var MusicFN: shortstring = '';
--- a/openalbridge/CMakeLists.txt Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/CMakeLists.txt Tue Jun 30 17:02:41 2009 +0000
@@ -23,7 +23,7 @@
if(MSVC)
#workaround for visualstudio (wants headers in the source list)
set(openal_src
- openalwrap.h loaders.h endianness.h wrappers.h winstdint.h globals.h oggvorbis.h ${openal_src}
+ openalwrap.h loaders.h endianness.h wrappers.h globals.h oggvorbis.h ${openal_src}
)
#deps for the shared library
link_libraries(${OPENAL_LIBRARY})
--- a/openalbridge/endianness.c Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/endianness.c Tue Jun 30 17:02:41 2009 +0000
@@ -23,10 +23,10 @@
#endif
/*from big endian to little endian*/
- int invert_endianness(int number){
+ int invert_endianness(uint32_t number){
return bswap_32(number);
}
#ifdef __CPLUSPLUS
}
-#endif
\ No newline at end of file
+#endif
--- a/openalbridge/endianness.h Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/endianness.h Tue Jun 30 17:02:41 2009 +0000
@@ -28,7 +28,7 @@
#pragma once
- int invert_endianness(int number);
+ int invert_endianness(uint32_t number);
#ifdef __CPLUSPLUS
}
--- a/openalbridge/globals.h Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/globals.h Tue Jun 30 17:02:41 2009 +0000
@@ -94,10 +94,12 @@
#pragma pack()
/*data type for passing data between threads*/
+#pragma pack(1)
typedef struct _fade_t {
- int index;
- unsigned int quantity;
+ uint32_t index;
+ uint16_t quantity;
} fade_t;
+#pragma pack()
/*other defines*/
#define FADE_IN 11
--- a/openalbridge/loaders.c Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/loaders.c Tue Jun 30 17:02:41 2009 +0000
@@ -25,7 +25,8 @@
int load_WavPcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) {
WAV_header_t WAVHeader;
FILE *wavfile;
- int t, n = 0;
+ int32_t t;
+ uint32_t n = 0;
wavfile = Fopen(filename, "rb");
@@ -75,7 +76,7 @@
fprintf(stderr, "Subchunk2Size: %d\n", WAVHeader.Subchunk2Size);
#endif
- *data = (char*) malloc (sizeof(char) * WAVHeader.Subchunk2Size);
+ *data = (char*) Malloc (sizeof(char) * WAVHeader.Subchunk2Size);
/*this could be improved*/
do {
@@ -148,20 +149,20 @@
vorbisComment = ov_comment(&oggStream, -1);
fprintf(stderr, "Version: %d\n", vorbisInfo->version);
fprintf(stderr, "Channels: %d\n", vorbisInfo->channels);
- fprintf(stderr, "Rate (Hz): %d\n", vorbisInfo->rate);
- fprintf(stderr, "Bitrate Upper: %d\n", vorbisInfo->bitrate_upper);
- fprintf(stderr, "Bitrate Nominal: %d\n", vorbisInfo->bitrate_nominal);
- fprintf(stderr, "Bitrate Lower: %d\n", vorbisInfo->bitrate_lower);
- fprintf(stderr, "Bitrate Windows: %d\n", vorbisInfo->bitrate_window);
+ fprintf(stderr, "Rate (Hz): %ld\n", vorbisInfo->rate);
+ fprintf(stderr, "Bitrate Upper: %ld\n", vorbisInfo->bitrate_upper);
+ fprintf(stderr, "Bitrate Nominal: %ld\n", vorbisInfo->bitrate_nominal);
+ fprintf(stderr, "Bitrate Lower: %ld\n", vorbisInfo->bitrate_lower);
+ fprintf(stderr, "Bitrate Windows: %ld\n", vorbisInfo->bitrate_window);
fprintf(stderr, "Vendor: %s\n", vorbisComment->vendor);
- fprintf(stderr, "PCM data size: %d\n", pcm_length);
+ fprintf(stderr, "PCM data size: %ld\n", pcm_length);
fprintf(stderr, "# comment: %d\n", vorbisComment->comments);
for (i = 0; i < vorbisComment->comments; i++)
fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]);
#endif
/*allocates enough room for the decoded data*/
- *data = (char*) malloc (sizeof(char) * pcm_length);
+ *data = (char*) Malloc (sizeof(char) * pcm_length);
/*there *should* not be ogg at 8 bits*/
if (vorbisInfo->channels == 1)
--- a/openalbridge/openalbridge.def Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/openalbridge.def Tue Jun 30 17:02:41 2009 +0000
@@ -2,6 +2,7 @@
EXPORTS
openal_init
openal_close
+ openal_ready
openal_loadfile
openal_toggleloop
openal_setvolume
--- a/openalbridge/openalwrap.c Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/openalwrap.c Tue Jun 30 17:02:41 2009 +0000
@@ -37,12 +37,19 @@
/*Velocity of the source sound*/
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };
+ ALint openalReady = AL_FALSE;
ALint openal_close(void) {
/*Stop all sounds, deallocate all memory and close OpenAL */
ALCcontext *context;
ALCdevice *device;
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
alSourceStopv (globalsize, Sources);
alDeleteSources (globalsize, Sources);
alDeleteBuffers (globalsize, Buffers);
@@ -56,9 +63,15 @@
alcMakeContextCurrent(NULL);
alcDestroyContext(context);
alcCloseDevice(device);
+
+ openalReady = AL_FALSE;
+
return AL_TRUE;
}
+ ALint openal_ready(void) {
+ return openalReady;
+ }
ALint openal_init(uint32_t memorysize) {
/*Initialize an OpenAL contex and allocate memory space for data and buffers*/
@@ -72,7 +85,13 @@
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
/*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
-
+
+ if(openalReady == AL_TRUE)
+ {
+ fprintf(stderr, "ERROR: OpenAL already initialized\n");
+ return AL_FALSE;
+ }
+
default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
fprintf(stderr, "Using default device: %s\n", default_device);
@@ -103,6 +122,8 @@
if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE)
return AL_FALSE;
+ openalReady = AL_TRUE;
+
alGetError(); /* clear any AL errors beforehand */
return AL_TRUE;
}
@@ -121,7 +142,7 @@
}
- uint32_t openal_loadfile (const char *filename){
+ int openal_loadfile (const char *filename){
/*Open a file, load into memory and allocate the Source buffer for playing*/
ALenum format;
ALsizei bitsize;
@@ -131,6 +152,11 @@
ALenum error;
FILE *fp;
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
/*when the buffers are all used, we can expand memory to accept new files*/
if (globalindex == globalsize)
@@ -201,6 +227,12 @@
/*Set or unset looping mode*/
ALint loop;
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
if (index >= globalsize) {
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
return AL_FALSE;
@@ -218,6 +250,12 @@
ALint openal_setvolume (uint32_t index, uint8_t percentage) {
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
/*Set volume for sound number index*/
if (index >= globalindex) {
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
@@ -237,6 +275,12 @@
ALint openal_setglobalvolume (uint8_t percentage) {
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
/*Set volume for all sounds*/
if (percentage > 100)
percentage = 100;
@@ -254,6 +298,12 @@
/*Mute or unmute sound*/
ALfloat mute;
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
alGetListenerf (AL_GAIN, &mute);
if (mute > 0)
mute = 0;
@@ -279,6 +329,12 @@
#endif
fade_t *fade;
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
fade = (fade_t*) Malloc(sizeof(fade_t));
fade->index = index;
fade->quantity = quantity;
@@ -331,6 +387,12 @@
ALint openal_playsound(uint32_t index){
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
/*Play sound number index*/
if (index >= globalindex) {
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
@@ -347,6 +409,12 @@
ALint openal_pausesound(uint32_t index){
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
/*Pause sound number index*/
if (index >= globalindex) {
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
@@ -361,6 +429,12 @@
ALint openal_stopsound(uint32_t index){
+ if(openalReady == AL_FALSE)
+ {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
/*Stop sound number index*/
if (index >= globalindex) {
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
--- a/openalbridge/wrappers.c Tue Jun 30 15:59:02 2009 +0000
+++ b/openalbridge/wrappers.c Tue Jun 30 17:02:41 2009 +0000
@@ -80,8 +80,8 @@
ALfloat gain;
ALfloat target_gain;
fade_t *fade;
- int index;
- unsigned int quantity;
+ uint32_t index;
+ uint16_t quantity;
fade = tmp;
index = fade->index;
@@ -114,6 +114,7 @@
#else
_endthread();
#endif
+ return 0;
}
@@ -126,8 +127,8 @@
ALfloat gain;
ALfloat old_gain;
fade_t *fade;
- int index;
- unsigned int quantity;
+ uint32_t index;
+ uint16_t quantity;
fade = tmp;
index = fade->index;
@@ -159,9 +160,10 @@
#else
_endthread();
#endif
+ return 0;
}
#ifdef __CPLUSPLUS
}
-#endif
\ No newline at end of file
+#endif