Allow communication of currently playing sample info from Player to arm9 #44
Allow communication of currently playing sample info from Player to arm9 #44prayerie wants to merge 3 commits into
Conversation
|
I had a look at this - it seems quite risky to me, as it's entirely possible that the ARM9 could read from the Though I believe it could be safe as long as:
The presence of a 64-bit field also concerns me as I would assume only 32-bit writes are atomic, but I could easily be wrong here x) In any case, I think I'll need to see the NT half of this code before I can conclude whether it's OK or not 😅 |
that makes sense yes :-) the NT part of the code does indeed use an uncached mirror. I'll reply properly more when i'm home |
|
Forgot to reply yesterday, but I'll put this here v quickly and update/put the nt code in a pr later on
re the 64 bit field: i didn't notice any slowdowns whatsoever, however it has been a while since i initially tested it out using just a 32 bit value for the sample's position, so i'll see if the accuracy even matters to that degree, maybe it is just fine as a u32 |
asiekierka
left a comment
There was a problem hiding this comment.
Aligning the array of structs should be enough to ensure no cache line conflicts.
| CommandDbgOut("finestep: 0x%x channel: 0x%x\n", fine_step, channel); | ||
| SCHANNEL_TIMER(channel) = SOUND_FREQ((int)GET_FREQ_DIRECT(fine_step)); | ||
| u32 bendfreq = GET_FREQ_DIRECT(fine_step); | ||
| SCHANNEL_TIMER(channel) = SOUND_FREQ((int)bendfreq); |
There was a problem hiding this comment.
#define SOUNDXTMR_FREQ(n) TIMER_FREQ_SHIFT(n, 1, 1)
SOUND_FREQ is an inaccurate rounding of a Hz-based frequency. As such, I think it is unwise to use the Hz-based value as a return value - it can lead to difficult-to-debug inaccuracies in the sample cursor on some playback rates.
There was a problem hiding this comment.
noted, I'll change this, thanks
|
fwiw re exelotl's point, i changed the playback position to be 32 bit and noticed no accuracy loss over time, so i changed that also |
note, I wrote most of this code a while ago, so if it looks a bit dodgy in how it's done etc that's ok ofc just please lemme know :o)
This adds a new struct
PlayingSampleInfo:It's arranged to have minimal padding.
Playerallows for setting a pointer to an array of 16 of these (one per channel) to facilitate communication between arm9 and arm7 about which samples are currently playing, and at what frequency (doing it this way is preferred to avoid FIFO message spam).This addition is designed with the sample playhead cursor in mind, but in order to keep the fork of libntxm (somewhat) uncoupled from NitrousTracker, the names don't reference sample cursors, as in theory it could be used for something else..
A FIFO command is added to set the location of this array of structs from arm9 code.
Also,
bendNoteandbendNoteDirectinSampleandInstrumenthave been updated to return the frequency bent to, which allows "playbackfreq" to remain accurate with portamento, arpeggio, etc commands