mvdnes / rboy

A Gameboy Emulator in Rust
MIT License
605 stars 39 forks source link

Noise length parameter not respected #11

Closed hrydgard closed 3 years ago

hrydgard commented 3 years ago

In sound.rs

 0xFF23 => {
                self.length_enabled = v & 0x40 == 0x40;
                if v & 0x80 == 0x80 {

The self.length_enabled statement is missing. Adding this fixes annoying noise in a number of games including Zelda: Link's Awakening.

Additionally, the enabled flag on the wave channel should be set like this:

   0xFF1A => {
                self.enabled_flag = (v & 0x80) == 0x80;

The Zelda: Oracle games needs this but seem to have other issues too.

Just stuff I noticed when messing around with it :) (I've been using parts of the code to play with upscaling shaders).

hrydgard commented 3 years ago

Found another one, if volshift isn't 0 in the wave channel, you're crushing the precision of the samples. Need to scale them up by a factor of at least 4 before you shift down. Then compensate for the additional volume in the mixing.

mvdnes commented 3 years ago

I have fixed the issues in 2741256df3e7275e59b5bc4c9ab6258e4420a838 and 20414561c8762a5ffe5557ed1a338fe63fff7b16. Thanks a lot for pointing them out! :+1: