Skip to content

swan: New sound core #2401

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

Closed

Conversation

asiekierka
Copy link
Contributor

@asiekierka asiekierka commented Mar 8, 2025

I've come across a recent push to optimize Furnace's sound drivers with acquireDirect(). I've also spent months researching the WonderSwan console and noticed that Furnace's sound core uses the old implementation from Mednafen, which does not incorporate recent discoveries. In particular, it was found that the WonderSwan has a fully digital output pipeline of 16-bit 24000 Hz stereo samples (the headphone adapter has its own DAC onboard!), and not an analog (here: 3072000 Hz) output like other sound chips typical of its era.

As such, I've rewritten the WonderSwan sound driver to, in a hopefully clean and readable manner, implement the sound system as is currently understood. It also provides a very preliminary hook for Hyper Voice support (which can pretty much be used as a direct headphone-only 16-bit 24000 Hz stereo DAC channel; one can use sound DMA to drive it, but Furnace doesn't really appear to concern itself with emulating DMA limitations at this time).

I've reverted the acquireDirect change and some of the optimizations as I question their usefulness (relative to code clarity) when processing a few hundred samples per call as opposed to a few dozen thousand; I'm ready to change it back or optimize it further in case benchmarks show that was a bad call.

I've also taken the opportunity to add support for the WonderSwan's internal speaker output. It's 8-bit mono as opposed to 16-bit stereo, and requires manually controlling the loudness for optimum performance. By default, I've set it to minimum loudness (let's call it 100%), which should be ideal for most tracks, but may lead to quiet audio on real hardware if only one channel is playing at a time. Some artists may wish to use the newly added Headphone output toggle in the chip manager, and adjust with the newly proposed 20xx effect if so.

TODO:

  • It appears one of the changes breaks VGM export, and I'm really not sure which one yet... Apparently not any of mine - it was an upstream issue.

Feedback, benchmark and testing welcome!

Now outputs 24000 Hz digital samples, matching real hardware (as
opposed to 3072000 Hz samples). It has also been rewritten from
scratch to match recent research and make the code significantly
more readable.
@asiekierka asiekierka changed the title swan: New sound core swan: New sound driver Mar 8, 2025
@freq-mod
Copy link
Collaborator

It appears one of the changes breaks VGM export, and I'm really not sure which one yet...

Don't worry, seems like VGM export is totally broken anyway.

@asiekierka
Copy link
Contributor Author

Ah! In that case, I'll wait for further feedback.

@asiekierka
Copy link
Contributor Author

Works great now!

@freq-mod freq-mod requested a review from tildearrow March 11, 2025 17:00
@tildearrow tildearrow changed the title swan: New sound driver swan: New sound core Mar 11, 2025
Copy link
Owner

@tildearrow tildearrow left a comment

Choose a reason for hiding this comment

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

Seems good, but I'll suggest keeping the old core just in case... (I can do this for you so don't worry)

@asiekierka
Copy link
Contributor Author

If you're willing to make both cores available, that's perfectly fine by me. However, I don't think the old core exposes internal speaker output, so that functionality won't work on it.

Copy link
Owner

@tildearrow tildearrow left a comment

Choose a reason for hiding this comment

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

Merging!

@tildearrow
Copy link
Owner

Merged #2401 into master.

Sadly, GitHub has failed to detect merge...

@tildearrow tildearrow closed this Mar 22, 2025
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