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

Merge train from preview #664

Merged
merged 10 commits into from
Jan 10, 2025
Merged

Merge train from preview #664

merged 10 commits into from
Jan 10, 2025

Conversation

rasky
Copy link
Collaborator

@rasky rasky commented Jan 9, 2025

No description provided.

rasky added 8 commits January 9, 2025 14:53
Because the RSP mixer ucode does overread (that is, it can read a bit
past the waveform end), we need to make sure that those extra bytes
are 0 (in case of a non looping waveform). Up until now, this was left
to the waveform callback to implement.

We can do better: just like for the looping case, we can have the mixer
handle this internally by clearing up the extra samples, calling the
callback only for actual samples. This better matches the waveform
callback API too, and makes things easier.

Moreover, the overread now is 100% an implementation detail of the mixer.
Added samplebuffer_undo to remove some samples that were previously
added.
Added samplebuffer_is_inited
Rewrite the looping logic of the RSP code correctly handle RDRAM
misalignments.
Currently, the mixer allocates all channels with a single global malloc.
The whole allocation is changed when something calls mixer_ch_set_limits,
just like the xm64 player does. Normally, this didn't create any problems
and if anything, decreased fragmentation.

Unfortunately, with compressed waveforms support now (VADPCM), there is
a bug if you play a compressed waveforms and then starts a xm64. xm64
will call mixer_ch_set_limits that in turn will reallocate all channels,
including discarding sample buffers that already contains VADPCM samples
that were already decompressed but not yet played back; and since
VADPCM can't seek backward, the playback will crash.

Compressed waveforms normally work in "frames" so it's normally to
fully decompressed one audio frame even though this is more than
strictly requested by the mixer: the extra samples stay in the sample
buffer ready. But if the mixer reallocates memory, that data is
discarded, casing havoc.

The new strategy, implemented by this change, is to allocate each
channel individually. This way, calling mixer_ch_set_limits on
*other* channels won't create issues to other channels were playback
is in progress. It can increase fragmentation but such is life.

There's also a slight-possible breaking change because samplebuffer
API is public (mistake from the past), and now samplebuffer owns the
allocation. Hopefully nobody is doing anything with them anyway.
Calling wav64_close on an in-progress playback would cause a crash. This
is quite unfortunate and unexpected by the user.

We add a private API to the mixer to do this, but it's pretty clear
that wav64 will have to track whether playback is in progress or not
at some point. For now, let's fix the crash.
Currently, wav64 is limited to rom:/ addresses as internally it
does direct DMA access. We change it to use a file descriptor so that
it can work on any filesystem. Direct DMA requests are basically changed
into standard lseek+read calls.
rasky added 2 commits January 10, 2025 14:01
Also create a pluggable compression system, similar to that already
used for assets.
@rasky rasky merged commit abf759e into DragonMinded:trunk Jan 10, 2025
4 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.

1 participant