diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index c0cc468b..8a18004e 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -2849,8 +2849,8 @@ void CPUUpdateRegister(uint32_t address, uint16_t value) case 0x7c: case 0x80: case 0x84: - soundEvent(address & 0xFF, (uint8_t)(value & 0xFF)); - soundEvent((address & 0xFF) + 1, (uint8_t)(value >> 8)); + soundEvent8(address & 0xFF, (uint8_t)(value & 0xFF)); + soundEvent8((address & 0xFF) + 1, (uint8_t)(value >> 8)); break; case 0x82: case 0x88: @@ -2866,7 +2866,7 @@ void CPUUpdateRegister(uint32_t address, uint16_t value) case 0x9a: case 0x9c: case 0x9e: - soundEvent(address & 0xFF, value); + soundEvent16(address & 0xFF, value); break; case 0xB0: DM0SAD_L = value; diff --git a/src/gba/GBAinline.h b/src/gba/GBAinline.h index 0fc9d869..d9560a3c 100644 --- a/src/gba/GBAinline.h +++ b/src/gba/GBAinline.h @@ -723,7 +723,7 @@ static inline void CPUWriteByte(uint32_t address, uint8_t b) case 0x9d: case 0x9e: case 0x9f: - soundEvent(address & 0xFF, b); + soundEvent8(address & 0xFF, b); break; case 0x301: // HALTCNT, undocumented if (b == 0x80) diff --git a/src/gba/Sound.cpp b/src/gba/Sound.cpp index 0a56be82..1f37de72 100644 --- a/src/gba/Sound.cpp +++ b/src/gba/Sound.cpp @@ -50,8 +50,8 @@ int soundTicks = SOUND_CLOCK_TICKS_; static float soundVolume = 1.0f; static int soundEnableFlag = 0x3ff; // emulator channels enabled -static float soundFiltering_ = -1; -static float soundVolume_ = -1; +static float soundFiltering_ = -1.0f; +static float soundVolume_ = -1.0f; void interp_rate() { /* empty for now */} @@ -161,7 +161,7 @@ void Gba_Pcm::update(int dac) int period = time - last_time; int idx = (unsigned)period / 512; - if (idx >= 3) + if (idx > 3) idx = 3; static int const filters[4] = { 0, 0, 1, 2 }; @@ -188,8 +188,8 @@ void Gba_Pcm_Fifo::timer_overflowed(int which_timer) // Not filled by DMA, so fill with 16 bytes of silence int reg = which ? FIFOB_L : FIFOA_L; for (int n = 8; n--;) { - soundEvent(reg, (uint16_t)0); - soundEvent(reg + 2, (uint16_t)0); + soundEvent16(reg, (uint16_t)0); + soundEvent16(reg + 2, (uint16_t)0); } } } @@ -237,21 +237,21 @@ static void apply_control() static int gba_to_gb_sound(int addr) { static const int table[0x40] = { - 0xFF10, 0, 0xFF11, 0xFF12, 0xFF13, 0xFF14, 0, 0, - 0xFF16, 0xFF17, 0, 0, 0xFF18, 0xFF19, 0, 0, - 0xFF1A, 0, 0xFF1B, 0xFF1C, 0xFF1D, 0xFF1E, 0, 0, - 0xFF20, 0xFF21, 0, 0, 0xFF22, 0xFF23, 0, 0, - 0xFF24, 0xFF25, 0, 0, 0xFF26, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, - 0xFF38, 0xFF39, 0xFF3A, 0xFF3B, 0xFF3C, 0xFF3D, 0xFF3E, 0xFF3F, + 0xFF10, 0, 0xFF11, 0xFF12, 0xFF13, 0xFF14, 0, 0, // 0x60 + 0xFF16, 0xFF17, 0, 0, 0xFF18, 0xFF19, 0, 0, // 0x68 + 0xFF1A, 0, 0xFF1B, 0xFF1C, 0xFF1D, 0xFF1E, 0, 0, // 0x70 + 0xFF20, 0xFF21, 0, 0, 0xFF22, 0xFF23, 0, 0, // 0x78 + 0xFF24, 0xFF25, 0, 0, 0xFF26, 0, 0, 0, // 0x80 + 0, 0, 0, 0, 0, 0, 0, 0, // 0x88 + 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, // 0x90 + 0xFF38, 0xFF39, 0xFF3A, 0xFF3B, 0xFF3C, 0xFF3D, 0xFF3E, 0xFF3F, // 0x98 }; if (addr >= 0x60 && addr < 0xA0) return table[addr - 0x60]; return 0; } -void soundEvent(uint32_t address, uint8_t data) +void soundEvent8(uint32_t address, uint8_t data) { int gb_addr = gba_to_gb_sound(address); if (gb_addr) { @@ -271,13 +271,15 @@ static void apply_volume(bool apu_only = false) soundVolume_ = soundVolume; if (gb_apu) { - static float const apu_vols[4] = { 0.25, 0.5, 1, 0.25 }; + static float const apu_vols[4] = { 0.25f, 0.5f, 1.0f, 0.25f }; gb_apu->volume(soundVolume_ * apu_vols[ioMem[SGCNT0_H] & 3]); } if (!apu_only) { - for (int i = 0; i < 3; i++) - pcm_synth[i].volume(0.66 / 256 * soundVolume_); + double synth_vol = 0.66 / 256.0 * soundVolume_; + pcm_synth[0].volume(synth_vol); + pcm_synth[1].volume(synth_vol); + pcm_synth[2].volume(synth_vol); } } @@ -289,7 +291,7 @@ static void write_SGCNT0_H(int data) apply_volume(true); } -void soundEvent(uint32_t address, uint16_t data) +void soundEvent16(uint32_t address, uint16_t data) { switch (address) { case SGCNT0_H: @@ -308,14 +310,14 @@ void soundEvent(uint32_t address, uint16_t data) WRITE16LE(&ioMem[address], data); break; - case 0x88: + case SOUNDBIAS: data &= 0xC3FF; WRITE16LE(&ioMem[address], data); break; default: - soundEvent(address & ~1, (uint8_t)(data)); // even - soundEvent(address | 1, (uint8_t)(data >> 8)); // odd + soundEvent8(address & ~1, (uint8_t)(data)); // even + soundEvent8(address | 1, (uint8_t)(data >> 8)); // odd break; } } @@ -523,7 +525,7 @@ void soundReset() soundPaused = true; soundTicks = 0; - soundEvent(NR52, (uint8_t)0x80); + soundEvent8(NR52, (uint8_t)0x80); } bool soundInit() diff --git a/src/gba/Sound.h b/src/gba/Sound.h index 9122bc27..0ec30235 100644 --- a/src/gba/Sound.h +++ b/src/gba/Sound.h @@ -48,18 +48,19 @@ extern float soundFiltering; // 0.0 = none, 1.0 = max //// GBA sound emulation // GBA sound registers -#define SGCNT0_H 0x82 -#define FIFOA_L 0xa0 -#define FIFOA_H 0xa2 -#define FIFOB_L 0xa4 -#define FIFOB_H 0xa6 +#define SGCNT0_H 0x82 +#define SOUNDBIAS 0x88 +#define FIFOA_L 0xa0 +#define FIFOA_H 0xa2 +#define FIFOB_L 0xa4 +#define FIFOB_H 0xa6 // Resets emulated sound hardware void soundReset(); // Emulates write to sound hardware -void soundEvent(uint32_t addr, uint8_t data); -void soundEvent(uint32_t addr, uint16_t data); // TODO: error-prone to overload like this +void soundEvent8(uint32_t addr, uint8_t data); +void soundEvent16(uint32_t addr, uint16_t data); // TODO: error-prone to overload like this // Notifies emulator that a timer has overflowed void soundTimerOverflow(int which);