# HG changeset patch # User koda # Date 1246247259 0 # Node ID 1cb7118a77ddaaf7973e51926e582d2a9748e7bd # Parent 2573d4ff78f9c115a6a2348993dd39ee5c3b9f0b initial bugfix for volume setup diff -r 2573d4ff78f9 -r 1cb7118a77dd QTfrontend/SDLs.cpp --- a/QTfrontend/SDLs.cpp Mon Jun 29 00:58:32 2009 +0000 +++ b/QTfrontend/SDLs.cpp Mon Jun 29 03:47:39 2009 +0000 @@ -26,7 +26,7 @@ music = -1; SDL_Init(SDL_INIT_VIDEO); - openal_init(50); + openal_init(40); } @@ -62,12 +62,12 @@ if (music < 0) { music = openal_loadfile(QString(datadir->absolutePath() + "/Music/main theme.ogg").toLocal8Bit().constData()); openal_toggleloop(music); - openal_setvolume(music,66); - } - openal_fadein(music, 50); + } + openal_setvolume(music, 60); + openal_fadein(music, 70); } void SDLInteraction::StopMusic() { - if (music >= 0) openal_fadeout(music, 50); + if (music >= 0) openal_fadeout(music, 70); } diff -r 2573d4ff78f9 -r 1cb7118a77dd QTfrontend/SDLs.h --- a/QTfrontend/SDLs.h Mon Jun 29 00:58:32 2009 +0000 +++ b/QTfrontend/SDLs.h Mon Jun 29 03:47:39 2009 +0000 @@ -21,18 +21,18 @@ #include -extern "C" int openal_init (int); -extern "C" int openal_close (void); -extern "C" int openal_loadfile (const char*); -extern "C" int openal_toggleloop (int); -extern "C" int openal_setvolume (int, unsigned char); -extern "C" int openal_setglobalvolume (unsigned char); -extern "C" int openal_togglemute (void); -extern "C" int openal_fadeout (int, unsigned int); -extern "C" int openal_fadein (int, unsigned int); -extern "C" int openal_playsound (int); -extern "C" int openal_stopsound (int); -extern "C" int openal_pausesound (int); +extern "C" int openal_init (int memorysize); +extern "C" int openal_close (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_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); class SDLInteraction : public QObject { diff -r 2573d4ff78f9 -r 1cb7118a77dd hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Mon Jun 29 00:58:32 2009 +0000 +++ b/hedgewars/uConsts.pas Mon Jun 29 03:47:39 2009 +0000 @@ -161,7 +161,7 @@ ifAlpha = $00000001; // use alpha channel (unused right now?) ifCritical = $00000002; // image is critical for gameplay (exit game if unable to load) ifTransparent = $00000004; // image uses transparent pixels (color keying) - ifIgnoreCaps = $00000008; // ignore hardware capabilities when loading (i.e. image won't be drawn using OpenGL) + ifIgnoreCaps = $00000008; // ignore hardware capabilities when loading (i.e. image will not be drawn using OpenGL) const cMaxPower = 1500; diff -r 2573d4ff78f9 -r 1cb7118a77dd hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Mon Jun 29 00:58:32 2009 +0000 +++ b/hedgewars/uMisc.pas Mon Jun 29 03:47:39 2009 +0000 @@ -82,7 +82,7 @@ cReducedQuality : boolean = false; cLocaleFName : shortstring = 'en.txt'; cSeed : shortstring = ''; - cInitVolume : LongInt = 128; + cInitVolume : LongInt = 50; cVolumeDelta : LongInt = 0; cTimerInterval : Longword = 8; cHasFocus : boolean = true; diff -r 2573d4ff78f9 -r 1cb7118a77dd hedgewars/uSound.pas --- a/hedgewars/uSound.pas Mon Jun 29 00:58:32 2009 +0000 +++ b/hedgewars/uSound.pas Mon Jun 29 03:47:39 2009 +0000 @@ -104,15 +104,16 @@ isSoundEnabled:= openal_init(numSounds); if isSoundEnabled then WriteLnToConsole(msgOK) else WriteLnToConsole(msgFailed); -ChangeVolume(cInitVolume) end; procedure ReleaseSound; begin +if isMusicEnabled then openal_fadeout(Mus, 30); openal_close(); end; procedure SoundLoad; +const volume = 60; var i: TSound; s: shortstring; t: Longword; @@ -127,6 +128,7 @@ s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; WriteToConsole(msgLoading + s + ' '); defVoicepack^.chunks[i]:= openal_loadfile (Str2PChar(s)); + openal_setvolume(defVoicepack^.chunks[i],volume); TryDo(defVoicepack^.chunks[i] >= 0, msgFailed, true); WriteLnToConsole(msgOK); end; @@ -139,6 +141,7 @@ s:= Pathz[Soundz[i].Path] + '/' + voicepacks[t].name + '/' + Soundz[i].FileName; WriteToConsole(msgLoading + s + ' '); voicepacks[t].chunks[i]:= openal_loadfile (Str2PChar(s)); + openal_setvolume(voicepacks[t].chunks[i],volume); if voicepacks[t].chunks[i] < 0 then WriteLnToConsole(msgFailed) else @@ -184,7 +187,8 @@ TryDo(Mus >= 0, msgFailed, false); WriteLnToConsole(msgOK); -openal_fadein(Mus, 50); +openal_setvolume(Mus, 60); +openal_fadein(Mus, 70); openal_toggleloop(Mus); end; diff -r 2573d4ff78f9 -r 1cb7118a77dd openalbridge/loaders.c --- a/openalbridge/loaders.c Mon Jun 29 00:58:32 2009 +0000 +++ b/openalbridge/loaders.c Mon Jun 29 03:47:39 2009 +0000 @@ -136,10 +136,13 @@ FILE *oggFile; // ogg handle OggVorbis_File oggStream; // stream handle vorbis_info *vorbisInfo; // some formatting data - vorbis_comment *vorbisComment; // other less useful data int64_t pcm_length; // length of the decoded data int size = 0; - int section, result, i; + int section, result; +#ifdef DEBUG + int i; + vorbis_comment *vorbisComment; // other less useful data +#endif oggFile = Fopen(filename, "rb"); result = ov_open(oggFile, &oggStream, NULL, 0); diff -r 2573d4ff78f9 -r 1cb7118a77dd openalbridge/openalwrap.c --- a/openalbridge/openalwrap.c Mon Jun 29 00:58:32 2009 +0000 +++ b/openalbridge/openalwrap.c Mon Jun 29 03:47:39 2009 +0000 @@ -21,11 +21,6 @@ #ifdef __CPLUSPLUS extern "C" { #endif - - typedef struct _fade_t { - int index; - unsigned int quantity; - } fade_t; // Sources are points emitting sound. ALuint *Sources; @@ -169,14 +164,14 @@ free(data); //deallocate data to save memory if (AlGetError("ERROR %d: Writing data to buffer\n") != AL_TRUE) - return -5; + return -6; //memory allocation for source position and velocity SourcePos[globalindex] = (ALfloat*) Malloc(sizeof(ALfloat)*3); SourceVel[globalindex] = (ALfloat*) Malloc(sizeof(ALfloat)*3); if (SourcePos[globalindex] == NULL || SourceVel[globalindex] == NULL) - return -6; + return -7; //source properties that it will use when it's in playback for (i = 0; i < 3; i++) { @@ -191,7 +186,7 @@ alSourcei (Sources[globalindex], AL_LOOPING, 0 ); if (AlGetError("ERROR %d: Setting source properties\n") != AL_TRUE) - return -7; + return -8; alGetError(); /* clear any AL errors beforehand */ @@ -271,48 +266,7 @@ return AL_TRUE; } -#ifndef _WIN32 - void *helper_fadeout(void *tmp) { -#else - void WINAPI helper_fadeout(void *tmp) { -#endif - ALfloat gain; - fade_t *fade; - int index; - unsigned int quantity; - - fade = tmp; - index = fade->index; - quantity = fade->quantity; - free(fade); -#ifdef DEBUG - fprintf(stderr, "Fade-out: index %d quantity %d", index, quantity); -#endif - - alGetSourcef(Sources[index], AL_GAIN, &gain); - - for ( ; gain >= 0.00f; gain -= (float) quantity/10000){ -#ifdef DEBUG - fprintf(stderr, "Fade-out: Set gain to %f\n", gain); -#endif - alSourcef(Sources[index], AL_GAIN, gain); - usleep(10000); - } - - AlGetError("ERROR %d: Setting fade out volume\n"); - - //stop that sound and reset its gain - alSourceStop (Sources[index]); - alSourcef (Sources[index], AL_GAIN, 1.0f); - -#ifndef _WIN32 - pthread_exit(NULL); -#else - _endthread(); -#endif - } - ALint openal_fadeout(int index, unsigned int quantity) { #ifndef _WIN32 pthread_t thread; @@ -343,43 +297,6 @@ return AL_TRUE; } -#ifndef _WIN32 - void *helper_fadein(void *tmp) -#else - void WINAPI helper_fadein(void *tmp) -#endif - { - ALfloat gain; - fade_t *fade; - int index; - unsigned int quantity; - - fade = tmp; - index = fade->index; - quantity = fade->quantity; - free (fade); - - gain = 0.0f; - alSourcef(Sources[index], AL_GAIN, gain); - alSourcePlay(Sources[index]); - - for ( ; gain <= 1.00f; gain += (float) quantity/10000){ -#ifdef DEBUG - fprintf(stderr, "Fade-in: Set gain to: %f\n", gain); -#endif - alSourcef(Sources[index], AL_GAIN, gain); - usleep(10000); - } - - AlGetError("ERROR %d: Setting fade in volume\n"); - -#ifndef _WIN32 - pthread_exit(NULL); -#else - _endthread(); -#endif - } - ALint openal_fadein(int index, unsigned int quantity) { #ifndef _WIN32 diff -r 2573d4ff78f9 -r 1cb7118a77dd openalbridge/openalwrap.h --- a/openalbridge/openalwrap.h Mon Jun 29 00:58:32 2009 +0000 +++ b/openalbridge/openalwrap.h Mon Jun 29 03:47:39 2009 +0000 @@ -33,29 +33,6 @@ #include "winstdint.h" #endif -#ifndef _SLEEP_H -#define _SLEEP_H -/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. * By Wu Yongwei **/ -#ifdef _WIN32 -# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) -# include -# define sleep(t) _sleep((t) * 1000) -# else -# include -# define sleep(t) Sleep((t) * 1000) -# endif -# ifndef _NEED_SLEEP_ONLY -# define msleep(t) Sleep(t) -# define usleep(t) Sleep((t) / 1000) -# endif -#else -# include -# ifndef _NEED_SLEEP_ONLY -# define msleep(t) usleep((t) * 1000) -# endif -#endif - -#endif /* _SLEEP_H */ #ifdef __CPLUSPLUS extern "C" { diff -r 2573d4ff78f9 -r 1cb7118a77dd openalbridge/wrappers.c --- a/openalbridge/wrappers.c Mon Jun 29 00:58:32 2009 +0000 +++ b/openalbridge/wrappers.c Mon Jun 29 03:47:39 2009 +0000 @@ -22,8 +22,9 @@ extern "C" { #endif - void *Malloc (size_t nbytes) - { + extern ALint *Sources; + + void *Malloc (size_t nbytes){ void *aptr; if ( (aptr = malloc(nbytes)) == NULL) { fprintf(stderr, "ERROR: not enough memory! malloc() failed"); @@ -32,14 +33,15 @@ return aptr; } - FILE *Fopen (const char *fname, char *mode) - { + + FILE *Fopen (const char *fname, char *mode) { FILE *fp; if ((fp=fopen(fname,mode)) == NULL) fprintf (stderr, "ERROR: can't open file %s in mode '%s'", fname, mode); return fp; } + ALint AlGetError (const char *str) { ALenum error; @@ -51,6 +53,97 @@ return AL_TRUE; } + +#ifndef _WIN32 + void *helper_fadein(void *tmp) +#else + void WINAPI helper_fadein(void *tmp) +#endif + { + ALfloat gain; + ALfloat target_gain; + fade_t *fade; + int index; + unsigned int quantity; + + fade = tmp; + index = fade->index; + quantity = fade->quantity; + free (fade); + +#ifdef DEBUG + fprintf(stderr, "Fade-out: index %d quantity %d\n", index, quantity); +#endif + + //save the volume desired after the fade + alGetSourcef(Sources[index], AL_GAIN, &target_gain); + if (target_gain > 1.0f || target_gain <= 0.0f) + target_gain = 1.0f; + + alSourcePlay(Sources[index]); + + for (gain = 0.0f ; gain <= target_gain; gain += (float) quantity/10000) { +#ifdef DEBUG + fprintf(stderr, "Fade-in: Set gain to: %f\n", gain); +#endif + alSourcef(Sources[index], AL_GAIN, gain); + usleep(10000); + } + + AlGetError("ERROR %d: Setting fade in volume\n"); + +#ifndef _WIN32 + pthread_exit(NULL); +#else + _endthread(); +#endif + } + + +#ifndef _WIN32 + void *helper_fadeout(void *tmp) +#else + void WINAPI helper_fadeout(void *tmp) +#endif + { + ALfloat gain; + ALfloat old_gain; + fade_t *fade; + int index; + unsigned int quantity; + + fade = tmp; + index = fade->index; + quantity = fade->quantity; + free(fade); + +#ifdef DEBUG + fprintf(stderr, "Fade-out: index %d quantity %d\n", index, quantity); +#endif + + alGetSourcef(Sources[index], AL_GAIN, &old_gain); + + for (gain = old_gain; gain >= 0.00f; gain -= (float) quantity/10000) { +#ifdef DEBUG + fprintf(stderr, "Fade-out: Set gain to %f\n", gain); +#endif + alSourcef(Sources[index], AL_GAIN, gain); + usleep(10000); + } + + AlGetError("ERROR %d: Setting fade out volume\n"); + + //stop that sound and reset its volume + alSourceStop (Sources[index]); + alSourcef (Sources[index], AL_GAIN, old_gain); + +#ifndef _WIN32 + pthread_exit(NULL); +#else + _endthread(); +#endif + } + #ifdef __CPLUSPLUS } #endif \ No newline at end of file diff -r 2573d4ff78f9 -r 1cb7118a77dd openalbridge/wrappers.h --- a/openalbridge/wrappers.h Mon Jun 29 00:58:32 2009 +0000 +++ b/openalbridge/wrappers.h Mon Jun 29 03:47:39 2009 +0000 @@ -20,6 +20,52 @@ #include #include "al.h" +#ifndef _WIN32 +#include +#include +#else +#define WIN32_LEAN_AND_MEAN +#include +#include "winstdint.h" +#endif + +#ifndef _SLEEP_H +#define _SLEEP_H +/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. * By Wu Yongwei **/ +#ifdef _WIN32 +# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) +# include +# define sleep(t) _sleep((t) * 1000) +# else +# include +# define sleep(t) Sleep((t) * 1000) +# endif +# ifndef _NEED_SLEEP_ONLY +# define msleep(t) Sleep(t) +# define usleep(t) Sleep((t) / 1000) +# endif +#else +# include +# ifndef _NEED_SLEEP_ONLY +# define msleep(t) usleep((t) * 1000) +# endif +#endif +#endif /* _SLEEP_H */ + +#pragma once + +typedef struct _fade_t { + int index; + unsigned int quantity; +} fade_t; + void *Malloc (size_t nbytes); FILE *Fopen (const char *fname, char *mode); ALint AlGetError (const char *str); +#ifndef _WIN32 +void *helper_fadein (void *tmp); +void *helper_fadeout (void *tmp); +#else +void WINAPI helper_fadein (void *tmp); +void WINAPI helper_fadeout (void *tmp); +#endif \ No newline at end of file