Need help testing 32X Sandbox

Announce (tech) demos or games releases

Moderator: Mask of Destiny

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sat Jul 29, 2017 8:19 pm

100920000!?!??? What the hell?? Where on earth could that value be coming from??

I've put together two more builds.

- One build just displays the info for event 0, which it's apparently getting stuck at on your end with a huge delay. The delay for this event should be 0!!
- The other build tosses out any event processing whatsoever. It will probably crash or go crazy once it hits the end of the song, but that should take a little while (should do that somewhere past event 4000) and in the meantime it should count up the event number. It does use the delay values read from the song, but the tickrate is now completely hardcoded (doesn't use the tickrate from the song) and is 100 samples per midi tick, just in case that was screwing with something in the build I just posted.

Chilly Willy
Very interested
Posts: 2572
Joined: Fri Aug 17, 2007 9:33 pm

Re: Need help testing 32X Sandbox

Post by Chilly Willy » Sat Jul 29, 2017 8:39 pm

That huge value was repeatable. It hung half the time without any display, and if it ran it had that huge value each time. You might check your routine for reading MUS delays compared to what's in the code I posted earlier. The majority of that code is from the MUS player I did for PSP Doom which works fine. I'm in the middle of modding that code to also handle MIDI so I have a MIDI/MUS library for the 32X.

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sat Jul 29, 2017 10:15 pm

Oops, forgot to attach the builds I made T u T

So this is how mine works:

Code: Select all

// now read in delay ticks
u32 delay = 0;
u8 delayFlag = ( evtByte & 0x80 );
while( delayFlag )
{
	u8 delayByte = *readBuffer++;
	delay = ( delay << 7 ) | ( delayByte & 0x7F );
	delayFlag = ( delayByte & 0x80 );
}
event.Delay = delay;
The first event byte (evtByte) has the delay flag set if it has a delay. By this point, it has already read in the parameter bytes so the readBuffer points at either the next event, if this event has no delay, or it points at the first delay byte.
So it reads in the byte, shifts the current delay left 7 bits, or's in the new 7-bit delay value, and then checks the delay byte it just read for the continue flag. Lather rinse repeat until it encounters a delay byte with no continue flag.

Also attaching those builds I claimed I made in the last post and then completely forgot to attach >.>
Attachments
OutRom_1.zip
(234.56 KiB) Downloaded 23 times
OutRom_2.zip
(234.65 KiB) Downloaded 23 times

Chilly Willy
Very interested
Posts: 2572
Joined: Fri Aug 17, 2007 9:33 pm

Re: Need help testing 32X Sandbox

Post by Chilly Willy » Sun Jul 30, 2017 12:21 am

That should work as long as delay is clear to start.

Rom 1:
Song loaded!
Num events: 4453
Num patches: 8

Event #0 info:
Event type: 7
Channel: 0
Param1: 249
Param2: 0
Delay: 0

Rom 2:
Frame: advancing
Current event: 1
Current delay: 100918000 and decreasing

Your pointer is clearly off - maybe you're reading too many bytes, or not enough bytes. The code for reading the delay is right, so it would have to be in the code processing the events themselves.

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sun Jul 30, 2017 1:08 am

Huh. So it's event #1 this time?

Welp, time to boot up the hex editor and figure out what kinda drugs my pointers are on. Sigh. Still have no idea why this would work in an emulator and not on real hardware.

EDIT: Oh heck, I think I have an idea. Gimme a bit, I might have screwed up my cache purging somewhere.

EDIT 2: OK, so if what I think might have been an issue was in fact an issue, this version should fix that. Turns out when I made the master SH2 responsible for loading the song, I had the master SH2 also purge the cache - NOT the slave SH2 (when I blindly copy paste code, nobody wins). Without knowing too much about the subject, I can only assume that's entirely the wrong way to do it. So I borrowed another aspect of the code you just posted - when a song is loaded, "playing" is set to 2. When it goes to process an audio buffer, it checks if playing is 2 and, if so, it purges the cache and sets playing to 1. This way I know for sure that the slave CPU is the one doing the cache purge. If it was reading the wrong values out of the cache instead of memory, that might have completely screwed up the delay values. The fix is attached. On the other hand, if it's still an issue, then I know for sure it lies within my song loading.
Attachments
OutRom.zip
(234.65 KiB) Downloaded 24 times

Chilly Willy
Very interested
Posts: 2572
Joined: Fri Aug 17, 2007 9:33 pm

Re: Need help testing 32X Sandbox

Post by Chilly Willy » Sun Jul 30, 2017 2:52 am

Yep, that was it! Events advance now, and the delays are all reasonable (all less than 100... usually less than 30).

It went to event 18389 and wound up with a delay of about 34000000. I guess this rom doesn't check for the end of song event. :lol:

Caches were always the most "fun" part of programming systems as old as the 32X. More than once I've flushed the wrong processor cache line. :D

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sun Jul 30, 2017 2:56 am

No it doesn't check for song end lol. I expected something like that would happen! Song end is triggered by a Finish event (which my converter ALWAYS ends a song with), but that's handled in the processEvent function which that rom does not call at all just in case event processing was screwing something up. So yeah it just runs right into something else's memory lol. But at least it seems like it works!!
Well, let me start adding things back in and see if I can't get some sweet jams playing on real hardware :)

EDIT: Alright, here's a new build! It SHOULD play music, hopefully FOR REAL this time! (fingers crossed!!)
Attachments
OutRom.zip
(234.98 KiB) Downloaded 24 times

Chilly Willy
Very interested
Posts: 2572
Joined: Fri Aug 17, 2007 9:33 pm

Re: Need help testing 32X Sandbox

Post by Chilly Willy » Sun Jul 30, 2017 3:42 am

Nope. Stuck at event 326, delay 16. Ticklength is 87. Also still hangs when you press a button.

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sun Jul 30, 2017 3:57 am

GAHD DAMMIT.

Reasons I wish I had my own 32X: significantly quicker turnaround for process of elimination while debugging. Sigh.

So there's three versions attached.

- OutRom_1 only processes three events: song finish, tickrate change, and note off. Note off is useless because there's never a note on, but it does seem to indicate that it gets stuck on a note off event. If this one works, the problem is likely not with note off.
- OutRom_2 adds note on events back in. IF IT PLAYS, it should sound a little ugly (because patch change events are not processed). If this one works, I know that the problem is not in note on or off.
- OutRom_3 processes ALL events, but this one does no voice mixing whatsoever. If this one works, I know the problem definitely lies with voice mixing. Otherwise, the problem may lie with one of the other event types.
Attachments
OutRom_3.zip
(234.96 KiB) Downloaded 21 times
OutRom_2.zip
(234.81 KiB) Downloaded 22 times
OutRom_1.zip
(234.81 KiB) Downloaded 21 times

Chilly Willy
Very interested
Posts: 2572
Joined: Fri Aug 17, 2007 9:33 pm

Re: Need help testing 32X Sandbox

Post by Chilly Willy » Sun Jul 30, 2017 5:09 am

Umm - both 1 and 2 play music just fine. They act the same, and sound like they do both note on and off. The third runs as well, but without sound.

Yeah, it's a pain to test for real hardware when you don't have it. That's why I have almost every console and at least one kind of cart for them (and custom firmware on consoles that have firmware).

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sun Jul 30, 2017 5:12 am

Huh, musta mixed something up.
GOOD TO KNOW THOUGH. Interesting, so voice mixing works, and processing all events works, but processing all events plus voice mixing breaks. Curious. I'm certain the problem lies with one of the event types I had commented out in 1+2.

Chilly Willy
Very interested
Posts: 2572
Joined: Fri Aug 17, 2007 9:33 pm

Re: Need help testing 32X Sandbox

Post by Chilly Willy » Sun Jul 30, 2017 5:17 am

Yeah, sounds like you're setting a mixer into a state that causes the mixing to fail, causing the audio to stop or loop forever or something.

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sun Jul 30, 2017 5:22 am

You know, I actually wouldn't be surprised if the problem lies in switching channel patches.
Here's three more builds.

- 1 has bank select and patch number events disabled (adds in pan and volume however)
- 2 has bank select enabled, patch number disabled (song shouldn't have any bank select commands, so just a sanity check).
- 3 has patch number enabled and bank select disabled. If one of these fails I would bet money it's this one.
Attachments
OutRom_1.zip
(234.87 KiB) Downloaded 21 times
OutRom_2.zip
(234.87 KiB) Downloaded 21 times
OutRom_3.zip
(234.93 KiB) Downloaded 22 times

Chilly Willy
Very interested
Posts: 2572
Joined: Fri Aug 17, 2007 9:33 pm

Re: Need help testing 32X Sandbox

Post by Chilly Willy » Sun Jul 30, 2017 5:27 am

You'd have won the bet - the third hangs at event 326. The first two play fine.

KillaMaaki
Very interested
Posts: 58
Joined: Sat Feb 28, 2015 9:22 pm

Re: Need help testing 32X Sandbox

Post by KillaMaaki » Sun Jul 30, 2017 5:49 am

Hm, that's curious. So the error happens in patch changing, which grabs a pointer to the sample bank the channel is set to use, then grabs the sample from that sample bank. If the cache was involved here (for example, the main CPU actually ends up setting up a song's default sound banks after the song's loaded - if somehow when it goes to switch patches, it got the wrong sample bank pointer out of the cache, that could definitely screw up patch loading. Then again, patch pointer comes AFTER sample bank pointer in the SongChannel struct, and that seems to be getting the correct pointer to the piano patch.

Another possibility I just realized is that I could be encountering an alignment issue with my InstrumentData struct. I grab a pointer to the sample data from the sample bank and then just cast that pointer to (InstrumentData*). This might be working just fine for the *first* instrument data (pointer table, which preceeds sample data, is a table of 128 uint32s, so the first struct directly after would probably have proper alignment), and then failing on subsequent patches. I probably need to fix my padding - now that I look again at my content builder, it's padding each sample data to multiples of two bytes, but probably should be padding to a multiple of *four* bytes as the first field of sample data is a uint32.
Though I don't know whether alignment issues would still be an issue in Kega Fusion or not.

EDIT: So this one has a couple things - a few more cache clear lines for channel sample banks and active patches, but also it now pads out sample data to a multiple of four bytes instead of two. This should keep each instrument sample aligned properly, if that was indeed the issue, as far as I can tell.
Attachments
OutRom.zip
(235.01 KiB) Downloaded 24 times

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest