Skip to content

Conversation

@sean-horton
Copy link
Contributor

This is an attempt at replacing sound with Duckstation's SPU. It is a non-ABI breaking change and can be turned off and on using options.cmake value AUDIO_SPU_EMULATION.

I have not hooked up FMV audio to the SPU emulator, but it should be trivial. I'll wait to see if this PR is even something that would be wanted.

  • MidiPlayer defines the SPU/SND functions.
  • Sequencer is the modified duckstation SPU
  • oddio defines fixes for vag attributes (which I'll mention more below)

The SPU runs at 44100hz which is executing in the SDL callback. The emulator should probably run in its own thread as running calculations in the SDL callback is probably bad practice. Unsure if this will cause clipping on slower CPU's. CPU usage seems comparable to master branch, however if many sounds are playing (slig constantly shooting), my CPU usage is slightly higher than master.

Interestingly the PC vag attributes differ from PSX. This can be seen by disabling the vag attribute fixes by commenting out mSoundSampleParser.applyFix(...) in MidiPlayer. With it commented it will sound like pc, with it uncommented it will sound like psx. One obvious example is Abe's "Hello". He has a deeper voice in pc, whereas psx is slightly higher pitch.

R6 is even more messed up and fixes can not be applied without more inspection, right now it uses all pc sounds, so Abe will have pc's lower pitch voice.

Further, I believe a lot of the volumes are incorrect in the sound definitions within things like slig.cpp.

  1. When a slig stops shooting it plays eHitBottomOfDDeathPit at full volume. This should almost certainly be played at a lower volume. SND_SEQ_SetVol()
  2. The sequence played for doves in, for example, paramonia, play at full volume, and should have SND_SEQ_SetVol()
  3. And; Leaves shooting out of wells seem to have too low of volume
  4. Probably others...

I have not applied fixes for AE, so that could probably be improved. However, I know greeters wheeling around make no noise, but it's because their volume is too low, increasing it the sound will play.

In short; I'm pretty sure the pc port introduced more sound issues than just the player, most likely to cover for the incorrect player.

{
std::vector<psx::Sample*> samples;


Copy link
Contributor

Choose a reason for hiding this comment

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

Double endline


if (soundDatFile.read(soundData, fileSize))
{
// Tada!
Copy link
Contributor

Choose a reason for hiding this comment

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

👀
I don't see anything happening here, what's the magic trick?


EXPORT void CC SND_Stop_Channels_Mask_4CA810(u32 bitMask)
{
bitMask;
Copy link
Contributor

Choose a reason for hiding this comment

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

This line, and the ones in SND_Load_VABS_4CA350 don't seem to do anything, is this needed?

return player->SFX_SfxDefinition_Play(reinterpret_cast<psx::SfxDefinition*>(const_cast<SfxDefinition*>(sfxDef)), volume, pitch_min, pitch_max);
}

#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good practice to end the source code files with an endline at the end. Also, not having one in an .hpp file can cause problems with including multiple ones one after the other.

Seems multiple files miss it here.

pDSoundBuffer->SetFrequency(freqHz);
pDSoundBuffer->SetVolume(sVolumeTable_BBBD38[panRightConverted]);

// OLD PAN
Copy link
Contributor

Choose a reason for hiding this comment

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

If the new panning is superior, no need to keep the original bad one in, should be removed instead, with all vars that it exclusively uses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This adds panning to the existing SDL audio rendering and is unrelated to the SPU emulation path. Since the existing SDL implementation is mono it's superior in the sense that it adds panning. I'm mentioning in case you don't want to modify the existing audio renderer otherwise I can remove the old panning.

audio/Stream.cpp
audio/MidiPlayer.hpp
audio/MidiPlayer.cpp
audio/oddio.h)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep ) on the new line like it was originally :)

/* AO reads sequence inline with data. AE reads from a sounds.dat file */
virtual ResourceData* readSeq(const char_type* fileName, const char_type* sequenceName)
{
fileName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably safe to remove, like the other lines like this in this file (and others)

void SPU::DeInit()
{
mutex.lock();
// TODO - does it matter?
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh, you tell us 😛

{
SPUSeqStop(seqId);
}
// SPUSeqSetVolume(seqId, 100, 100);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's some commented out code here. If it's not needed, please remove :)

@tarceri
Copy link

tarceri commented Jun 30, 2025

You probably should not be integrating Duckstation source code as the license is "CC Attribution-NonCommercial-NoDerivatives 4.0 International" note the "No Derivatives" this license is incompatible with pretty much any free software license GPL, MIT, etc

@rozniak
Copy link
Member

rozniak commented Jul 1, 2025

You probably should not be integrating Duckstation source code as the license is "CC Attribution-NonCommercial-NoDerivatives 4.0 International" note the "No Derivatives" this license is incompatible with pretty much any free software license GPL, MIT, etc

The license was changed on Sep 1st 2024 from the looks of it, and the last work on this was in June 2024 so would have been based on source that was licensed under GPL.

EDIT: If any updates done that need referring to Duckstation source, this repo conveniently hosts the last revision prior to Duckstation being made proprietary: https://codeberg.org/vimuser/duckstation

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.

4 participants