Tons of trouble with Echo (pulling my hair out)

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
KillaMaaki
Very interested
Posts: 84
Joined: Sat Feb 28, 2015 9:22 pm

Tons of trouble with Echo (pulling my hair out)

Post by KillaMaaki » Mon Dec 24, 2018 9:59 am

I'm having a lot of trouble with Echo that I've so far managed to find odd workarounds for... but this one's absolutely driving me nuts.
Trying to get SFX playback working but for some reason even the simplest SFX are glitching out.

For example, exported from dmf2esf, I have this cursor sound (ran in -a mode to get an asm dump of what commands it's saving to the ESF file):

Code: Select all

	dc.b $f8, $22, $00	; Set FM register 34 to value 0
	dc.b $e1		; Lock channel FM 2
; Pattern $00, Row 0; 
	dc.b $41, $00	; Set instrument for channel FM 2
	dc.b $21, $00	; Set volume for channel FM 2
	dc.b $01, $93	; Note A-4 on channel FM 2
; Pattern $00, Row 1; 
	dc.b $fe, $03	; Delay
	dc.b $01, $93	; Note A-4 on channel FM 2
; Pattern $00, Row 2; 
; Pattern $00, Row 3; 
; Pattern $00, Row 4; 
; Pattern $00, Row 5; 
; Pattern $00, Row 6; 
; Pattern $00, Row 7; 
	dc.b $fe, $12	; Delay
	dc.b $11		; Note off channel FM 2
; Pattern $00, Row 8; 
; Pattern $00, Row 9; 
; Pattern $00, Row 10; 
; Pattern $00, Row 11; 
	dc.b $fe, $0f	; Delay
	dc.b $ff	; The End
That ought to just be locking channel 2, playing a couple of tones in quick succession, and then Echo should handle unlocking and letting the music resume as normal.
This is not what happens.
What actually happens is that channel 2 plays the tone, but not all the way through (it's frequently cut short by BGM notes for some reason, even though channel locking should have taken care of that!), for some reason channel 1 ALSO plays a tone (and produces a rather irritating sound), and then channel 2 subsequently holds on to that sound effect's instrument until the next instrument change in the song.

On the other hand if I do not play any BGM at all, the sound effect plays as normal.

I'm fairly baffled by this, and have thus far sunk my entire day into figuring out how to get Echo working properly. Attached are the instrument files and ESF files I'm using here in case it helps
Anyone encounter anything like this while trying to integrate Echo?
Attachments
TestEchoSFX.zip
(10.89 KiB) Downloaded 40 times

Sik
Very interested
Posts: 891
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Tons of trouble with Echo (pulling my hair out)

Post by Sik » Mon Dec 24, 2018 5:41 pm

The stream you posted looks correct (aside from needlessly resetting LFO), so that's not it... but sfx_Cursor.esf.bytes has different values (the first three bytes are 32 34 38 instead of F8 22 00). That probably would do it…
Sik is pronounced as "seek", not as "sick".

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

Re: Tons of trouble with Echo (pulling my hair out)

Post by KillaMaaki » Mon Dec 24, 2018 7:59 pm

Hm, interesting.
Lemme see if I can figure out where those are coming from.

EDIT: Oh wild actually it's *four* extra bytes. Whatever it was trying to serialize, it looks like it gets interpreted as setting the frequency of FM channel 2 and PSG channel 8 (!?)

EDIT 2: OH FOR FUCK'S SAKE instead of writing the literal binary value of "0xF8" it's trying to write the fucking ascii string "248" god dammit. How many places does it do THIS I wonder.

EDIT 3: Alright that's WAY better. Only issue now is that the sound effect retains the panning of whatever was playing before, but I probably just need to modify the exporter to initialize all used channels with default panning.

Sik
Very interested
Posts: 891
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Tons of trouble with Echo (pulling my hair out)

Post by Sik » Tue Dec 25, 2018 12:05 am

KillaMaaki wrote:
Mon Dec 24, 2018 7:59 pm
EDIT 3: Alright that's WAY better. Only issue now is that the sound effect retains the panning of whatever was playing before, but I probably just need to modify the exporter to initialize all used channels with default panning.
Yeah, if it plays on a channel that may be panned then the sound effect needs to explicitly set it (Echo's fault, sorry >_>). Sound effect needs to expect the channel could be in just about any state.

EDIT: also if you're editing the exporter, get rid of that LFO init (that "Set FM register 34") because LFO is global and it could override whatever the BGM is using! (unless you want the sound effect to take over the LFO, that is, but even then it'd be better for only those sound effects using LFO to actually override it)

EDIT 2: adding to the above, for PSG you'll want to explicitly set volume too (since it's not overriden on instrument change, unlike with FM… Echo is a goddamn mess, OK? I didn't fix that only for the sake of backwards compatibility)
Sik is pronounced as "seek", not as "sick".

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

Re: Tons of trouble with Echo (pulling my hair out)

Post by KillaMaaki » Tue Dec 25, 2018 12:17 am

Noted, thanks! :)
I'll probably make a pull request of all of this for the converter repo at some point but for now it's nice to actually have it working!

EDIT: Attached a little demo of what I've managed with Echo so far btw, thanks for your help and input c:
Attachments
rom.zip
(70.84 KiB) Downloaded 40 times

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

Re: Tons of trouble with Echo (pulling my hair out)

Post by KillaMaaki » Thu Dec 27, 2018 7:11 am

Actually.... mighta spotted a bug on hardware, wanted to ask if you knew anything about this or if this might be a converter bug but it definitely only manifests on real hardware.

Basically in that demo you can hear a victory theme when you defeat the slime. The theme has a center-panned marimba arpeggio that plays throughout.
On emulator, this is perfectly audible. However, someone I know online did a recording off of their Model 1 VA2, and when I listened to that the marimba had just about completely vanished!

When they made a direct ROM export from within DefleMask (which AFAIK is pretty much just a VGM player) using the same song's source DMF file though, and tested that, the Marimba was perfectly fine and audible.
So it seems like for some reason only in Echo the Marimba is gone and I'm not sure what happened, maybe the volume is set to something low or maybe it got panned weird somehow?
Wanted to ask if you knew anything.

Sik
Very interested
Posts: 891
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Tons of trouble with Echo (pulling my hair out)

Post by Sik » Thu Dec 27, 2018 5:32 pm

That sounds more like a bug in Echo than hardware >.> Not like I can tell without the stream.

Echo is a buggy piece of shit and honestly I'm surprised anybody still uses it instead of XGM. Maybe because the latter doesn't do FM sound effects…
Sik is pronounced as "seek", not as "sick".

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

Re: Tons of trouble with Echo (pulling my hair out)

Post by KillaMaaki » Thu Dec 27, 2018 5:56 pm

I know your feeling well. The feeling that you've produced barely-working code that could fall apart never really goes away (not even in the world of professional salaried development!) and is less indicative of your own skill and more indicative of your own self worth. You'll always find a way to patch things over and it will always become a better product!

That aside!
Yeah that's the main reason, since I'm very interested in saving on cartridge space. But also, I did try switching back to XGM, and it bugged out on one of my songs and totally failed to play my FM toms correctly, so in fact Echo seems to be better at handling it now that I've fixed up the converter.

Anyway more on topic I just went to produce some streams for you and then.... saw some weirdness.
First of all my BGM files are locking all of the channels, which seems sorta wrongish. Don't know why the converter would do that, it shouldn't be.
But also I'm seeing a hard pan right getting issued for channel 2, which my marimba is on, which seems also wrong. In fact, I've got a sneaking suspicion this is yet ANOTHER thing that's my fault actually. I tried to allow for swapping channel mappings in the conversion (so I could for example swap what's on FM channel 2 with what's on FM channel 5 to help massage my songs to play better with SFX in those channels) and I get the suspicion that a pan command from channel 5 "leaked" into channel 2 in the conversion process.
Will investigate and see!

EDIT: Hm, wait, no my marimba IS on channel 5 oops. So it is getting set to a center pan first thing in the stream, and then never again is the pan touched. Neither is the volume, which is set to max.
But maybe that channel locking is to blame?

Sik
Very interested
Posts: 891
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Tons of trouble with Echo (pulling my hair out)

Post by Sik » Fri Dec 28, 2018 5:59 am

KillaMaaki wrote:
Thu Dec 27, 2018 5:56 pm
First of all my BGM files are locking all of the channels, which seems sorta wrongish.
…yeah, Echo will screw up spectacularly if you try to use the lock commands in a BGM (it'll try to execute a different event and possibly go out of sync with the stream, which means it'll execute garbage… although for the record, it also has a tendency to somehow recover itself if it didn't bring down the whole hardware with it in the process ¯\_(°_o)_/¯)


EDIT: in case you wonder why this happens, BGM and SFX streams are handled by separate loops that call different wrappers for each subroutine, in large part to account for the channel locking (to keep track of the changes BGM makes for restoring the channel later). Since BGM of course doesn't need to lock, those events are not implemented in the BGM loop, and Echo doesn't attempt to handle gracefully any invalid data. Why it loves to somehow go back in sync after a while, I have no idea (seems to be pure luck), but it definitely will make some really weird sounds meanwhile…

And yeah, if we had a new sound driver from scratch that probably should be handled better >_>
Sik is pronounced as "seek", not as "sick".

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

Re: Tons of trouble with Echo (pulling my hair out)

Post by KillaMaaki » Fri Dec 28, 2018 9:35 am

Honestly just knowing this behavior is fine for me. I sorta knew those shouldn't be there in the first place.I'd almost rather it do no error checking at all if that happens to be leaner/more efficient.
I managed to completely reproduce the error on the Genesis GX Plus libretro core, and removing those lock channel commands DID fix it there, so I'd be willing to bet it fixes it on real hardware too (sigh, my cart cannot arrive soon enough!)

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

Re: Tons of trouble with Echo (pulling my hair out)

Post by KillaMaaki » Sat Dec 29, 2018 1:57 am

One more question:
I don't suppose there's a chance that a call to set the frequency of Channel 3 in a sound effect, done definitely after locking that channel (checking the actual byte stream in a hex editor this time to be sure), would persist after the sound is finished playing? My background music initializes the PSG3 frequency but doesn't touch it again, my SFX locks that channel and changes it to a different value, my BGM then takes on that new value for the rest of the song after the SFX has finished.
I could patch this by just forcing my BGM to set the frequency on every note on, but want to make sure I'm not missing something here.

Sik
Very interested
Posts: 891
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Tons of trouble with Echo (pulling my hair out)

Post by Sik » Sun Dec 30, 2018 5:37 am

Locking a channel outright forces a key-off on return (on the assumption that BGM will eventually play a new note later). Behavior has to be like this because it's not always possible to restore an ongoing note (it's pretty problematic for FM in particular).
Sik is pronounced as "seek", not as "sick".

Post Reply