diff options
Diffstat (limited to 'hgewin')
-rwxr-xr-x | hgewin/hge_impl.h | 6 | ||||
-rw-r--r-- | hgewin/sound.cpp | 27 |
2 files changed, 16 insertions, 17 deletions
diff --git a/hgewin/hge_impl.h b/hgewin/hge_impl.h index 5acdcd4..244dafc 100755 --- a/hgewin/hge_impl.h +++ b/hgewin/hge_impl.h @@ -123,7 +123,7 @@ public: virtual HEFFECT CALL Effect_Load(const char *filename, DWORD size=0); virtual void CALL Effect_Free(HEFFECT eff); virtual HCHANNEL CALL Effect_Play(HEFFECT eff); - virtual HCHANNEL CALL Effect_PlayEx(HEFFECT eff, int volume=100, int pan=0, float pitch=1.0f, bool loop=false); + virtual HCHANNEL CALL Effect_PlayEx(HEFFECT eff, float volume=1.0, float pan=0.0, float pitch=1.0f, bool loop=false); virtual HMUSIC CALL Music_Load(const char *filename, DWORD size=0); virtual void CALL Music_Free(HMUSIC mus); @@ -142,8 +142,8 @@ public: virtual void CALL Stream_Free(HSTREAM stream); virtual HCHANNEL CALL Stream_Play(HSTREAM stream, bool loop, int volume = 100); - virtual void CALL Channel_SetPanning(HCHANNEL chn, int pan); - virtual void CALL Channel_SetVolume(HCHANNEL chn, int volume); + virtual void CALL Channel_SetPanning(HCHANNEL chn, float pan); + virtual void CALL Channel_SetVolume(HCHANNEL chn, float volume); virtual void CALL Channel_SetPitch(HCHANNEL chn, float pitch); virtual void CALL Channel_Pause(HCHANNEL chn); virtual void CALL Channel_Resume(HCHANNEL chn); diff --git a/hgewin/sound.cpp b/hgewin/sound.cpp index 2bde29e..9024652 100644 --- a/hgewin/sound.cpp +++ b/hgewin/sound.cpp @@ -16,7 +16,6 @@ // Channel functions are fully supported now. However music and streaming are // still not supported. Some APIs changed for OpenAL is different from BA$$. -#include <cassert> #include "hge_impl.h" #include "AL/al.h" @@ -218,23 +217,23 @@ HEFFECT CALL HGE_Impl::Effect_Load(const char *filename, DWORD size) HCHANNEL CALL HGE_Impl::Effect_Play(HEFFECT eff) { - return Effect_PlayEx(eff, 100, 0, 1.0f, false); + return Effect_PlayEx(eff, 1.0f, 0, 1.0f, false); } -HCHANNEL CALL HGE_Impl::Effect_PlayEx(HEFFECT eff, int volume, int pan, float pitch, bool loop) +HCHANNEL CALL HGE_Impl::Effect_PlayEx(HEFFECT eff, float volume, float pan, float pitch, bool loop) { if(hOpenAL) { const ALuint sid = get_source(); // find an unused sid, or generate a new one. if (sid != 0) { - if (volume < 0) volume = 0; else if (volume > 100) volume = 100; - if (pan < -100) pan = -100; else if (pan > 100) pan = 100; + if (volume < 0) volume = 0; else if (volume > 1.0) volume = 1.0; + if (pan < -1.0) pan = -1.0; else if (pan > 1.0) pan = 1.0; alSourceStop(sid); alSourcei(sid, AL_BUFFER, (ALint) eff); - alSourcef(sid, AL_GAIN, ((ALfloat) volume) / 100.0f); + alSourcef(sid, AL_GAIN, volume); alSourcef(sid, AL_PITCH, pitch); - alSource3f(sid, AL_POSITION, ((ALfloat) pan) / 100.0f, 0.0f, 0.0f); + alSource3f(sid, AL_POSITION, pan, 0.0f, 0.0f); alSourcei(sid, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); alSourcePlay(sid); } @@ -282,22 +281,22 @@ void CALL HGE_Impl::Stream_Free(HSTREAM stream){} HCHANNEL CALL HGE_Impl::Stream_Play(HSTREAM stream, bool loop, int volume){return 0;} -void CALL HGE_Impl::Channel_SetPanning(HCHANNEL chn, int pan) +void CALL HGE_Impl::Channel_SetPanning(HCHANNEL chn, float pan) { - assert(pan >= -100); - assert(pan <= 100); + if(pan>1.0)pan=1.0; + if(pan<-1.0)pan=-1.0; if(hOpenAL) { - alSource3f((ALuint) chn, AL_POSITION, ((ALfloat) pan) / 100.0f, 0.0f, 0.0f); + alSource3f((ALuint) chn, AL_POSITION, pan, 0.0f, 0.0f); } } -void CALL HGE_Impl::Channel_SetVolume(HCHANNEL chn, int volume) +void CALL HGE_Impl::Channel_SetVolume(HCHANNEL chn, float volume) { if(hOpenAL) { - if (volume < 0) volume = 0; else if (volume > 100) volume = 100; - alSourcef((ALuint) chn, AL_GAIN, ((ALfloat) volume) / 100.0f); + if (volume < 0) volume = 0; else if (volume > 1.0f) volume = 1.0f; + alSourcef((ALuint) chn, AL_GAIN, volume); } } |