Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Clarify the volume amplification logic used. #28

Closed
Altaflux opened this issue Sep 29, 2024 · 2 comments
Closed

[Question] Clarify the volume amplification logic used. #28

Altaflux opened this issue Sep 29, 2024 · 2 comments

Comments

@Altaflux
Copy link

Hi, I am trying to learn about gameboy emulation and stumbled on your emulator which has been very insightful.
I am a bit stumbled by the logic around how sound volume is being calculated and would love to better understand the math behind it.

I am referring specifically to the following lines:
https://github.com/mvdnes/rboy/blob/main/src/sound.rs#L891

        let left_vol = (self.volume_left as f32 / 7.0) * (1.0 / 15.0) * 0.25;
        let right_vol = (self.volume_right as f32 / 7.0) * (1.0 / 15.0) * 0.25;

I understand (self.volume_left as f32 / 7.0) as 7 is the maximum volume of the gameboy registers so it is calculating the "max" volume.
But I am not sure what is the purpose of (1.0 / 15.0) neither of * 0.25;.

I you could help me understand this logic I would greatly appreciate it.

@mvdnes
Copy link
Owner

mvdnes commented Sep 30, 2024

I think my rationale back in the day was:

  • the division by 7 is for the master volume range
  • the division by 15 is for the range of each individual channel
  • the division by 4 (* 0.25) is to divide by the number of channels

Re-reading the pandocs, I am not overly confident this is correct, but it seems to work well enough.

@Altaflux
Copy link
Author

Thanks for the clarification, really appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants