X Tutup
Skip to content

AGI: add --pcjr-noise option to set shift register#6754

Merged
bluegr merged 8 commits intoscummvm:masterfrom
SinusPi:add-pcjr-sr01
Jun 24, 2025
Merged

AGI: add --pcjr-noise option to set shift register#6754
bluegr merged 8 commits intoscummvm:masterfrom
SinusPi:add-pcjr-sr01

Conversation

@SinusPi
Copy link
Contributor

@SinusPi SinusPi commented Jun 20, 2025

The standard SN76489 sound chip found in PCjr machines uses a 15-bit shift register for its periodic noise generator. When the noise channel "borrows" a tone channel's frequency, it sounds awfully out of key. Some SEGA consoles, however, use a version of the chip with a 16-bit shift register, generating periodic noise with a resonant frequency in key with the borrowed one, thus allowing for using the periodic noise as a bass instrument. On a 15-bit shifting chip, using noise for music can only be achieved by premultiplying all the borrowed frequencies by 15/16ths, a workaround very much inconvenient.

With --pcjr-noise=16, the chip emulation is set to generate properly resonant noise.

Now, admittedly, original Sierra games rarely use that feature in their music files. Homebrew games may, though, and it's better to have the option rather than not have it.

The standard SN76489 sound chip found in PCjr machines uses a 15-bit
shift register for its periodic noise generator. When the noise channel
"borrows" a tone channel's frequency, it sounds awfully out of key.
Some SEGA consoles, however, use a version of the chip with a 16-bit
shift register, generating periodic noise with a resonant frequency
in key with the borrowed one, thus allowing for using the periodic noise
as a bass instrument. On a 15-bit shifting chip, using noise for music
can only be achieved by premultiplying all the borrowed frequencies by
15/16ths, a workaround not entirely convenient.

With --pcjr-noise=16, the chip emulation is set to generate properly
resonant noise.
@bluegr
Copy link
Member

bluegr commented Jun 20, 2025

Since this option can basically have two values (15 and 16), it makes sense to simplify it to a boolean, to make it easier to use for casual users. Something like "Improve PCjr chip emulation", perhaps?

This can be added as a game feature flag for fan made games, which can then be toggled as a checkbox by the ScummVM GUI

@SinusPi
Copy link
Contributor Author

SinusPi commented Jun 21, 2025 via email

@SinusPi
Copy link
Contributor Author

SinusPi commented Jun 21, 2025

Should it be a checkbox, then, only enabled when PCjr is selected? Or, rather, a separate entry in the sound engines' list, like, "PCjr (SEGA compatible)", or something like that? There would be less of a UI impact this way.

@SinusPi
Copy link
Contributor Author

SinusPi commented Jun 21, 2025

Hmmm, wait, you said "game feature flag". So far I'm not aware of how game feature flags work in ScummVM. So what's the proper procedure here - do I need to make my option into something like that, and build the GUI option for it (like the Adlib OPL emulator choice)? Or does it go somewhere else then? Or should I simplify this PR to just the implementation of the 16-bit shifter, and save actual options to enable it for a later PR, so as to compartmentalize properly? Please advise.

@sev-
Copy link
Member

sev- commented Jun 21, 2025

GUI options for AGI engine are defined in agi/detection.cpp file.

  1. Add an alias like GAMEOPTION_NOISE
  2. Add it to the relevant detection entries, e.g., mark PC titles
  3. Add textual description of this GAMEOPTION to metaengine.cpp

On adding or running a game, the game options become visible in the Game tab in the "Game Options" in the main GUI and in the General Main Menu (Ctrl+F5 in-game)

@SinusPi SinusPi marked this pull request as draft June 21, 2025 23:14
@SinusPi
Copy link
Contributor Author

SinusPi commented Jun 21, 2025

Very well - I thought it would fit in better as a "sound" option, but if "game" option it is, then game option it is.

@SinusPi
Copy link
Contributor Author

SinusPi commented Jun 23, 2025

There we go. Option added to game's custom settings.
It took me a while to realize the settings are set in stone once a game's detected, and won't get updated by a mere change in code... ^^;

@SinusPi SinusPi marked this pull request as ready for review June 23, 2025 00:45

namespace Agi {

#define GAMEOPTIONS_DEFAULT GUIO5(GAMEOPTION_ORIGINAL_SAVELOAD,GAMEOPTION_ENABLE_MOUSE,GAMEOPTION_ENABLE_PREDICTIVE_FOR_MOUSE,GAMEOPTION_USE_HERCULES_FONT,GAMEOPTION_COMMAND_PROMPT_WINDOW)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that option be available in commercial AGI games as well, or only for fan made games?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough commercial games to test, but indeed I'd go with fanmades only, as I'm not sure any commercial one used noise for music.

Copy link
Contributor Author

@SinusPi SinusPi Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option removed from commercial games.

Comment on lines +125 to +127
Common::String cfgPCjrNoise = ConfMan.get("pcjr_16bitnoise");
if (cfgPCjrNoise == "true")
periodicNoiseMask = 0x10000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use ConfMan.getBool() here instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

-100
};

int32 periodicNoiseMask = 0x08000; // default 15-bit periodic noise mask
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this as a member variable of the SoundGenPCJr class. As per our code formatting guidelines, it should be prepended with an underscore, i.e. _periodicNoiseMask

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@bluegr
Copy link
Member

bluegr commented Jun 24, 2025

Nice work, thanks! Squashing

@bluegr bluegr merged commit 8b2b973 into scummvm:master Jun 24, 2025
5 of 8 checks passed
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

Successfully merging this pull request may close these issues.

3 participants

X Tutup