Skip to content

Commit

Permalink
fixes for max and 0 volumes
Browse files Browse the repository at this point in the history
reworked accumulateChannels to preserve volume effects

minor fixes

reverted soChVol_ to long
  • Loading branch information
eadmaster authored and eadmaster committed Nov 29, 2020
1 parent fc79bb4 commit dbaae88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 0 additions & 2 deletions libgambatte/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,7 @@ static void check_variables(void)
sound_channel_volume_base_str[17] = c+'1';
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
//psg_channels_volume[c] = ;
gb.getPSG()->setSoChanVolume(unsigned(atoi(var.value)), c);
//printf("ch %d: %u\n", c, unsigned(atoi(var.value)));
}
}

Expand Down
24 changes: 13 additions & 11 deletions libgambatte/src/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ namespace gambatte
, rsum_(0x8000) // initialize to 0x8000 to prevent borrows from high word, xor away later
, enabled_(false)
{
// init as full volume
setSoChanVolume(100, 0);
setSoChanVolume(100, 1);
setSoChanVolume(100, 2);
setSoChanVolume(100, 3);
}

void PSG::init(const bool cgb)
Expand Down Expand Up @@ -98,10 +103,10 @@ namespace gambatte
uint_least32_t *const buf = buffer_ + bufferPos_;

std::memset(buf, 0, cycles * sizeof(uint_least32_t));
ch1_.update(buf, soChVol_[0], cycles);
ch2_.update(buf, soChVol_[1], cycles);
ch3_.update(buf, soChVol_[2], cycles);
ch4_.update(buf, soChVol_[3], cycles);
ch1_.update(buf, (soChVol_[0] * soVol_ * 0x1999999A) >> 32, cycles);
ch2_.update(buf, (soChVol_[1] * soVol_ * 0x1999999A) >> 32, cycles);
ch3_.update(buf, (soChVol_[2] * soVol_ * 0x1999999A) >> 32, cycles);
ch4_.update(buf, (soChVol_[3] * soVol_ * 0x1999999A) >> 32, cycles);
}

void PSG::generateSamples(unsigned long const cycleCounter, bool const doubleSpeed)
Expand Down Expand Up @@ -181,15 +186,12 @@ namespace gambatte
+ ((nr50 >> 4 & 0x7) + 1) * so2Mul) * 64;
}

void PSG::setSoChanVolume(const unsigned nr50, const unsigned ch)
void PSG::setSoChanVolume(const unsigned percent, const unsigned ch)
{
if( ch < 0 || ch > 3 )
return; // invalid channel number
if( ch > 3 || percent > 100 )
return; // invalid arg

unsigned long soChVol = (((nr50 & 0x7) + 1) * so1Mul
+ ((nr50 >> 4 & 0x7) + 1) * so2Mul) * 64;

soChVol_[ch] = soChVol;
soChVol_[ch] = int(percent / 10);
}

void PSG::mapSo(const unsigned nr51)
Expand Down
4 changes: 2 additions & 2 deletions libgambatte/src/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PSG {
void setNr44(unsigned data) { ch4_.setNr4(data); }

void setSoVolume(unsigned nr50);
void setSoChanVolume(unsigned nr50, unsigned ch);
void setSoChanVolume(unsigned percent, unsigned ch);
void mapSo(unsigned nr51);
unsigned getStatus() const;

Expand All @@ -84,7 +84,7 @@ class PSG {
std::size_t bufferPos_;
unsigned long lastUpdate_;
unsigned long soVol_;
unsigned long soChVol_[5];
unsigned long soChVol_[4];
uint_least32_t rsum_;
bool enabled_;

Expand Down

0 comments on commit dbaae88

Please sign in to comment.