Fix sound DC levels

This was causing popping in Mega Man (I)
This commit is contained in:
Ilari Liusvaara 2013-12-05 08:48:21 +02:00
parent 6725b4545a
commit 607d3e252c
4 changed files with 12 additions and 12 deletions

View file

@ -218,13 +218,13 @@ void Channel1::loadState(SaveState const &state) {
void Channel1::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) { void Channel1::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) {
unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0;
unsigned const outLow = outBase * (0 - 15ul);
unsigned const endCycles = cycleCounter_ + cycles; unsigned const endCycles = cycleCounter_ + cycles;
for (;;) { for (;;) {
unsigned const outHigh = master_ unsigned const outHigh = master_
? outBase * (envelopeUnit_.getVolume() * 2 - 15ul) ? outBase * (envelopeUnit_.getVolume())
: outLow; : 0;
unsigned const outLow = -outHigh;
unsigned const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles); unsigned const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles);
unsigned out = dutyUnit_.isHighState() ? outHigh : outLow; unsigned out = dutyUnit_.isHighState() ? outHigh : outLow;

View file

@ -122,13 +122,13 @@ void Channel2::loadState(SaveState const &state) {
void Channel2::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) { void Channel2::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) {
unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0;
unsigned const outLow = outBase * (0 - 15ul);
unsigned const endCycles = cycleCounter_ + cycles; unsigned const endCycles = cycleCounter_ + cycles;
for (;;) { for (;;) {
unsigned const outHigh = master_ unsigned const outHigh = master_
? outBase * (envelopeUnit_.getVolume() * 2 - 15ul) ? outBase * (envelopeUnit_.getVolume())
: outLow; : 0;
unsigned const outLow = -outHigh;
unsigned const nextMajorEvent = std::min(nextEventUnit->counter(), endCycles); unsigned const nextMajorEvent = std::min(nextEventUnit->counter(), endCycles);
unsigned out = dutyUnit_.isHighState() ? outHigh : outLow; unsigned out = dutyUnit_.isHighState() ? outHigh : outLow;

View file

@ -156,8 +156,8 @@ void Channel3::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cy
unsigned const nextMajorEvent = unsigned const nextMajorEvent =
std::min(lengthCounter_.counter(), endCycles); std::min(lengthCounter_.counter(), endCycles);
unsigned out = master_ unsigned out = master_
? ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - 15ul ? ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - (15 >> rshift_)
: 0 - 15ul; : 0;
out *= outBase; out *= outBase;
while (waveCounter_ <= nextMajorEvent) { while (waveCounter_ <= nextMajorEvent) {
@ -171,7 +171,7 @@ void Channel3::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cy
++wavePos_; ++wavePos_;
wavePos_ &= 0x1F; wavePos_ &= 0x1F;
sampleBuf_ = waveRam_[wavePos_ >> 1]; sampleBuf_ = waveRam_[wavePos_ >> 1];
out = ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - 15ul; out = ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - (15 >> rshift_);
out *= outBase; out *= outBase;
} }
@ -188,7 +188,7 @@ void Channel3::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cy
break; break;
} }
} else { } else {
unsigned const out = outBase * (0 - 15ul); unsigned const out = 0;
*buf += out - prevOut_; *buf += out - prevOut_;
prevOut_ = out; prevOut_ = out;
cycleCounter_ += cycles; cycleCounter_ += cycles;

View file

@ -224,11 +224,11 @@ void Channel4::loadState(SaveState const &state) {
void Channel4::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) { void Channel4::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) {
unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0;
unsigned const outLow = outBase * (0 - 15ul);
unsigned const endCycles = cycleCounter_ + cycles; unsigned const endCycles = cycleCounter_ + cycles;
for (;;) { for (;;) {
unsigned const outHigh = outBase * (envelopeUnit_.getVolume() * 2 - 15ul); unsigned const outHigh = outBase * (envelopeUnit_.getVolume());
unsigned const outLow = -outHigh;
unsigned const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles); unsigned const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles);
unsigned out = lfsr_.isHighState() ? outHigh : outLow; unsigned out = lfsr_.isHighState() ? outHigh : outLow;