diff options
author | peter1138 <peter1138@openttd.org> | 2010-03-06 11:08:31 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2010-03-06 11:08:31 +0000 |
commit | 77fe7e0a74c597794d90e7776aa100a82fe2a60a (patch) | |
tree | 049718321cb28fbaee6c85be2d98ebe54a44b330 /src/mixer.cpp | |
parent | 1eb52326cf810d9ea4380cd97ac84daaf4f358d8 (diff) | |
download | openttd-77fe7e0a74c597794d90e7776aa100a82fe2a60a.tar.xz |
(svn r19332) -Codechange: Simplify sound panning by using float data, and switch to sinusoidal algorithm to maintain output level.
Diffstat (limited to 'src/mixer.cpp')
-rw-r--r-- | src/mixer.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/mixer.cpp b/src/mixer.cpp index 1b054f4e3..36c982bec 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp @@ -10,6 +10,7 @@ /** @file mixer.cpp Mixing of sound samples. */ #include "stdafx.h" +#include <math.h> #include "core/math_func.hpp" struct MixerChannel { @@ -185,10 +186,18 @@ void MxSetChannelRawSrc(MixerChannel *mc, int8 *mem, size_t size, uint rate, boo mc->is16bit = is16bit; } -void MxSetChannelVolume(MixerChannel *mc, uint left, uint right) +/** + * Set volume and pan parameters for a sound. + * @param mc MixerChannel to set + * @param volume Volume level for sound, range is 0..16384 + * @param pan Pan position for sound, range is 0..1 + */ +void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan) { - mc->volume_left = left; - mc->volume_right = right; + /* Use sinusoidal pan to maintain overall sound power level regardless + * of position. */ + mc->volume_left = volume * sin((1.0 - pan) * M_PI / 2.0); + mc->volume_right = volume * sin(pan * M_PI / 2.0); } |