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
Refactor the ReelMagic audio FIFO class #2090
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kcgen
force-pushed
the
kc/reelmagic-fifo-3
branch
from
November 26, 2022 08:22
f642602
to
b906f18
Compare
kklobe
reviewed
Nov 26, 2022
kklobe
reviewed
Nov 26, 2022
kcgen
force-pushed
the
kc/reelmagic-fifo-3
branch
7 times, most recently
from
November 27, 2022 19:31
664ee68
to
787b2dd
Compare
kcgen
force-pushed
the
kc/reelmagic-fifo-3
branch
2 times, most recently
from
November 28, 2022 02:53
b98a5e7
to
79e99f3
Compare
Context: the Sound Blaster's internal frequency can be derived from the Transfer Time constant passed into the 40h call: Time Constant = 65536 - (256 000 000/(channels * sampling rate) - The channels parameter is 1 for mono, 2 for stereo. - Only the high byte of the result is sent to the DSP. Ref: Sound Blaster Series Hardware Programming Guide Set digitized sound transfer time constant, 6-14 DSP Commands https://pdos.csail.mit.edu/6.828/2018/readings/hardware/SoundBlaster.pdf --- If we solve for the sampling rate: 256 000 000 sampling rate = ---------------------------------------- <channels> * (65536 - (<high-byte> << 8)) Where <channels> can be 1 or 2 and <high-byte> 0 to 255. Here's are some sample rates: mono (1 channel) with high-byte 0 => 3 906 Hz mono (1 channel) with high-byte 127 => 7 751 Hz mono (1 channel) with high-byte 166 => 11 111 Hz mono (1 channel) with high-byte 234 => 45 454 Hz mono (1 channel) with high-byte 255 => 1 000 000 Hz stereo (2 channels) with high-byte 0 => 1 953 Hz stereo (2 channels) with high-byte 127 => 3 875 Hz stereo (2 channels) with high-byte 211 => 11 111 Hz stereo (2 channels) with high-byte 245 => 45 454 Hz stereo (2 channels) with high-byte 255 => 500 000 Hz The high-byte passed into 40h is valid for setting DMA rates however the above shows we can't trust it to give us a valid playback rate within the documented 5-45 Khz range. So this commit simply keeps the the sound blaster's requested channel rate between the 5 to 45 KHz range. This can be seen in The Horde ReelMagic edition, which, on initialization, feeds the Sound Blaster a 255-value via 40h, which in turn (previously) asked the mixer channel to run at 1 million Hz :)
The prior code could overflow into a large negative number if the elapsed PIT ticks exceeded the read latch. This would result in the uint32_t wrapping to a value of 4+ billion, exceeding `iround`'s signed integer limit. This occurs in The Horde, ReelMagic edition.
A double free was encountered when shutting down The Horde (ReelMagic edition) using Opus CD-DA tracks.
DOSBox's mixer has (for a very long time) allowed adjustment of a channel's volume through a user control (via MIXER) and by the application (via the SB Mixer), however the names of these member variables and their functions to manage them were often not obvious. This commit renames names these variables and functions to match their purpose. It also adds a third fixed volume scalar to let a channel scale up or down it's samples to get to 0 dB on the signed 16-bit scale, which is used by the ReelMagic and GUS chanels.
This uses current decoded MP2 frame as the FIFO itself without any copying or re-buffering.
kcgen
force-pushed
the
kc/reelmagic-fifo-3
branch
from
November 28, 2022 17:34
79e99f3
to
d2a5020
Compare
Completed testing on the Pi 4. See recommended settings in the PR comment above (applicable to all systems). Even during playback, the Pi only runs its CPU between ~1.1 - 1.4 GHz to keep up. Here's a 3-second running log of the core's frequency (Hz):
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Suggest reviewing commit-by-commit.
The refactored ReelMagic AudioFifo class now loads audio directly into DOSBox Staging's mixer (via pointer from the MPEG stream's decoded interleaved audio buffer) without queuing or math operations performed on the samples.
It now also skips initial gaps in decoded audio.
The ReelMagic's mixer channel is now activated on an as-needed basis.
Playback is working smooth with fewer initial audio hiccups, even at 800 Mhz:
Tips for optimal performance
Use your lowest latency
[sdl]
conf settings. If you're using a Raspberry Pi, be sure to use the recommended baseline configs.In addition to the baseline settings, further apply these ReelMagic specific settings, which are suitable for all the ReelMagic games:
Notes: