WINTERMUTE: Limit the range of the panning-variable to stay within [-1,1].

Also, store the panning state, so that the next playback starts with the same pan.
This commit is contained in:
Einar Johan Trøan Sømåen 2014-01-14 00:24:28 +01:00
parent 0c570712f1
commit 0c0ed9fdd8
2 changed files with 8 additions and 3 deletions

View File

@ -58,6 +58,7 @@ BaseSoundBuffer::BaseSoundBuffer(BaseGame *inGame) : BaseClass(inGame) {
_file = nullptr;
_privateVolume = 255;
_volume = 255;
_pan = 0;
_looping = false;
_loopStart = 0;
@ -143,9 +144,9 @@ bool BaseSoundBuffer::play(bool looping, uint32 startSample) {
_handle = new Audio::SoundHandle;
if (_looping) {
Audio::AudioStream *loopStream = new Audio::LoopingAudioStream(_stream, 0, DisposeAfterUse::NO);
g_system->getMixer()->playStream(_type, _handle, loopStream, -1, _volume, 0, DisposeAfterUse::YES);
g_system->getMixer()->playStream(_type, _handle, loopStream, -1, _volume, _pan, DisposeAfterUse::YES);
} else {
g_system->getMixer()->playStream(_type, _handle, _stream, -1, _volume, 0, DisposeAfterUse::NO);
g_system->getMixer()->playStream(_type, _handle, _stream, -1, _volume, _pan, DisposeAfterUse::NO);
}
}
@ -268,8 +269,11 @@ bool BaseSoundBuffer::setLoopStart(uint32 pos) {
//////////////////////////////////////////////////////////////////////////
bool BaseSoundBuffer::setPan(float pan) {
pan = MAX(pan, -1.0f);
pan = MIN(pan, 1.0f);
_pan = (int8)(pan * 127);
if (_handle) {
g_system->getMixer()->setChannelBalance(*_handle, (int8)(pan * 127));
g_system->getMixer()->setChannelBalance(*_handle, _pan);
}
return STATUS_OK;
}

View File

@ -93,6 +93,7 @@ private:
bool _streamed;
Common::SeekableReadStream *_file;
int32 _volume;
int8 _pan;
};
} // End of namespace Wintermute