Merge pull request #1043 from zsilencer/develop

bugs
This commit is contained in:
Ted John 2015-05-07 13:46:14 +01:00
commit d9cd873ad7
3 changed files with 42 additions and 28 deletions

View File

@ -268,8 +268,10 @@ bool Source_SampleStream::LoadWAV(SDL_RWops* rw)
log_verbose("Could not find FMT chunk");
return false;
}
Uint64 chunkstart = SDL_RWtell(rw);
PCMWAVEFORMAT waveformat;
SDL_RWread(rw, &waveformat, sizeof(waveformat), 1);
SDL_RWseek(rw, chunkstart + fmtchunk_size, RW_SEEK_SET);
if (waveformat.wf.wFormatTag != WAVE_FORMAT_PCM) {
log_verbose("Not in proper format");
return false;
@ -341,6 +343,8 @@ Channel::Channel()
SetRate(1);
SetVolume(SDL_MIX_MAXVOLUME);
oldvolume = 0;
oldvolume_l = 0;
oldvolume_r = 0;
SetPan(0.5f);
done = true;
stopping = false;
@ -395,8 +399,15 @@ void Channel::SetPan(float pan)
if (pan < 0) {
Channel::pan = 0;
}
volume_l = (float)sin((1.0 - Channel::pan) * M_PI / 2.0);
volume_r = (float)sin(Channel::pan * M_PI / 2.0);
double decibels = (abs(Channel::pan - 0.5) * 2.0) * 100.0;
double attenuation = pow(10, decibels / 20.0);
if (Channel::pan <= 0.5) {
volume_l = 1.0;
volume_r = float(1.0 / attenuation);
} else {
volume_r = 1.0;
volume_l = float(1.0 / attenuation);
}
}
bool Channel::IsPlaying()
@ -692,6 +703,8 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length)
} while(loaded < length && channel.loop != 0 && !channel.stopping);
channel.oldvolume = channel.volume;
channel.oldvolume_l = channel.volume_l;
channel.oldvolume_r = channel.volume_r;
if (channel.loop == 0 && channel.offset >= channel.source->Length()) {
channel.done = true;
}
@ -700,21 +713,19 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length)
void Mixer::EffectPanS16(Channel& channel, sint16* data, int length)
{
float left = channel.volume_l;
float right = channel.volume_r;
for (int i = 0; i < length * 2; i += 2) {
data[i] = (sint16)(data[i] * left);
data[i + 1] = (sint16)(data[i + 1] * right);
float t = (float)i / (length * 2);
data[i] = (sint16)(data[i] * ((1.0 - t) * channel.oldvolume_l + t * channel.volume_l));
data[i + 1] = (sint16)(data[i + 1] * ((1.0 - t) * channel.oldvolume_r + t * channel.volume_r));
}
}
void Mixer::EffectPanU8(Channel& channel, uint8* data, int length)
{
float left = channel.volume_l;
float right = channel.volume_r;
for (int i = 0; i < length * 2; i += 2) {
data[i] = (uint8)(data[i] * left);
data[i + 1] = (uint8)(data[i + 1] * right);
float t = (float)i / (length * 2);
data[i] = (uint8)(data[i] * ((1.0 - t) * channel.oldvolume_l + t * channel.volume_l));
data[i + 1] = (uint8)(data[i + 1] * ((1.0 - t) * channel.oldvolume_r + t * channel.volume_r));
}
}

View File

@ -133,6 +133,7 @@ private:
double rate;
int volume;
float volume_l, volume_r;
float oldvolume_l, oldvolume_r;
float pan;
bool done;
bool deleteondone;

View File

@ -2447,32 +2447,34 @@ int ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint
uint8 vol1 = -1;
uint8 vol2 = -1;
if (pany < 0) {
pany = -pany;
int panx2 = panx;
int pany2 = pany;
if (pany2 < 0) {
pany2 = -pany2;
}
if (pany > 6143) {
pany = 6143;
if (pany2 > 6143) {
pany2 = 6143;
}
pany -= 2048;
if (pany > 0) {
pany = -((pany / 4) - 1024) / 4;
vol1 = (uint8)pany;
if (pany >= 256) {
pany2 -= 2048;
if (pany2 > 0) {
pany2 = -((pany2 / 4) - 1024) / 4;
vol1 = (uint8)pany2;
if (pany2 >= 256) {
vol1 = -1;
}
}
if (panx < 0) {
panx = -panx;
if (panx2 < 0) {
panx2 = -panx2;
}
if (panx > 6143) {
panx = 6143;
if (panx2 > 6143) {
panx2 = 6143;
}
panx -= 2048;
if (panx > 0) {
panx = -((panx / 4) - 1024) / 4;
vol2 = (uint8)panx;
if (panx >= 256) {
panx2 -= 2048;
if (panx2 > 0) {
panx2 = -((panx2 / 4) - 1024) / 4;
vol2 = (uint8)panx2;
if (panx2 >= 256) {
vol2 = -1;
}
}