Welcome to the Shining Force Central Forums!
SFC Forums Index Shining Forums Shining Force II
Register for your free forum account now or Login to remove this advert.

Music resuming

For those who dislike to hear battle music restart everytime.

Discussion about this classic Genesis/Mega Drive game.

Music resuming

Postby Wiz » Sun Dec 17 2017 3:07am

Latest patch :

Quick demo through battle 1 :
Here's a brief demonstration of the behaviour of my custom sound driver with its music resuming feature.

Basic principle :
- When loading music, previous music's current state is saved
- If new music to load is the same as currently saved music, then resume it

Most importantly, this allows to avoid repetitive music during battles :
- Battlefield music is resumed everytime
- And series of consecutive attacks from ally or enemy side allow to resume their respective music

Also worth noting :
- Exploration music is resumed after getting an item or after a priest action.
- Resuming is deactivated during cutscenes, to make sure to keep the original intended mood, instead of resuming inappropriately.

EDIT : [SF2DISASM][HOWTO] Music resuming

Original post :
Last edited by Wiz on Sun Jan 14 2018 11:35pm, edited 5 times in total.

User avatar
Shining Member
Shining Member
Posts: 169
Joined: Sun Mar 18 2007 2:43pm
Location: Blois, France

Re: Music resuming

Postby Doh042 » Sun Dec 17 2017 3:47am

Question about your specifics implementation here --

What I notice that is annoying (mildly~) in my current game/project/demo is that while I crossfade/pause the battle music, the Combat Sequence music restarts for every fight. That means you can only hear the later parts when you do stuff like Aura 4, or hit many enemies with Bolt and such.

At first I was thinking of also pausing that one, but that solution got tossed out the window as soon as I started hot-swapping the song based on which battle sequence song you'd get (Hero/Enemy/Promoted Hero/Different Character song for reasons/Bosses, etc.)

Since I'm doing this in Unity, I could technically have as many audio source for all of the possible battle songs, and pause/resume them as well -- just pick the right one. But I think I prefer the more elegant solution that each character can point to its own song, and that I just load it at the fight start.

Maybe I can note the timestamp and play from there.. I'll have to check it out.

Anyway, curious to hear if you're just pausing the main battle theme song, like I am currently doing, or if you went further.
... enjoy!

... enjoy!


User avatar
Posts: 52
Joined: Tue Nov 28 2017 3:36am
Location: Montreal, Quebec

Re: Music resuming

Postby Wiz » Sun Dec 17 2017 2:13pm

Indeed, keeping a "play cursor" for each character seems to be a good idea to make sure we can hear their songs entirely, I like it !

Your idea seems feasible thanks to the fact that you can start playing music at any timestamp, I guess the sound library can do that with no problem, with any kind of classic audio file : wav, mp3, etc.

But with SF2, I cannot just store a timestamp to resume music, because of the way music is rendered by applying sequential commands.
Chip tune music is quite a "stateful" process with lots of properties to keep for each channel, in order to send the proper commands to the sound chips with the proper timing, to generate the proper waveform.

So starting from a given timestamp implies to store all the current channels properties, which is exactly what i do with my sound driver.

This takes a lot of place in the Z80 RAM so I had to make room by moving SFX data out of the Z80 RAM, to a place in the ROM after the game's textbanks where a few free kylobytes remained. SFX are now read from this place directly.

Here's the details of the channel data :
Code: Select all
YM Channel RAM Data :

(in DAC mode, samples are played instead of notes.
The sample length actually represents its play length,
and not the samples actual length which can be longer)

bytes 00-01 :   pointer to next data to parse in ROM

byte 02 :   time counter for note/sample length

byte 03 :   set to $01 when channel has nothing to do

byte 04 :   output level, from $00 to $0F

byte 05 :    current algorithm

byte 06 :    key release value. Release key when time counter 02 reaches this value.

byte 07 :   note/sample length

byte 08 :   set to $80 when there is no key release, even between different notes

byte 09 :   note length before vibrato

byte 0A :   time counter before vibrato

bytes 0B-0C :   vibrato data start pointer

byte 0D :   vibrato data relative pointer

bytes 0E-0F :   current YM frequency

byte 10 :   YM Instrument   

bytes 11-12 :   YM frequency to reach when sliding

bytes 13-14 :   loop A start pointer

bytes 15-16 :   loop B start pointer

bytes 17-18 :   loop C start pointer

bytes 19 :   loop C counter

byte 1A :   set to $01 when it's not anymore loop A's first pass

byte 1B :   set to $01 when it's not anymore loop B's first pass

byte 1C :   note shift value

byte 1D :   frequency shift value

byte 1E :   Stereo Output setup

byte 1F :   slide speed

PSG Tone/Noise Channel RAM Data :

(I just noted the bytes that are used in a different way than above)

byte 04 :   PSG Instrument total level

byte 05 :   actual level to apply = base level - $F + instrument data

bytes 10-11 :   PSG Instrument pointer

byte 12 :   PSG Instrument relative pointer

byte 1E :   set if key has just been released

And this is why resuming cannot be 100% satisfying by conception :
If you save current state after a "key down" command for a long note, then resuming will not apply the "key down" command again, and the note will be lost until the next "key down" command for the next note.
So depending on the situation, resuming can feel perfect, but it can also feel like it's missing some channels for a few seconds until everything really is resumed.

This is something I can not do much to compensate, unless I alter the music sound a bit :
When resuming, I could try to force "key down" commands for every channel currently playing a note, but this also could feel a bit wrong if a channel's current instrument's "enveloppe" has an "Attack-decay" phase important enough to be noticed as being played at the wrong time.
But this is something that I want to try at some point and check by myself if it could feel better in spite of this.

Don't hesitate if you have any other question about this, but yeah as you can see, resuming chip music is another thing entirely. :D

So I've tested the game until battle 5 and it appears that my integration totally wrecks the existing "music stack" mechanics, as I had not realised how much the game uses the "play previous music from music stack" command. It happens a lot, really, even during simple warps between maps !
So yeah, I really have to work on two fronts :
- improve the resuming quality : missing first notes and altered SFX.
- improve the integration : make it work on battles only for a start, and don't alter the music stack push/pop flow.

User avatar
Shining Member
Shining Member
Posts: 169
Joined: Sun Mar 18 2007 2:43pm
Location: Blois, France

Re: Music resuming

Postby Morath » Tue Dec 19 2017 6:13pm

Great idea! I tested it out through town up to the first battle briefly. I certainly prefer resuming the music after short pieces of music and sound-effect-type stuff. It's worth noting that much of the music in the game is "front-loaded" in recognition of the fact that music would be often restarting due to the battles and such interrupting. Overall, music resuming gives a greater sense of continuity and I do prefer how the player's (or AI's) actions in-game directing the actions of the characters in game gives a better sense of flow in a similar way to how a director of an orchestra directs groups of instruments.

Keep up the good work!

Posts: 20
Joined: Sat Sep 23 2006 2:43pm

Re: Music resuming

Postby Wiz » Wed Dec 27 2017 12:26am

Thank you Morath for the feedback ! :)

I decided to change my strategy and let the sound driver decide to apply music resuming all by itself, whenever it's able to do so.

This means different use cases work quite well now :
- Short jingles (save, raise, item, join ...) let the previous music be resumed
- Warps back and forth between two maps allow both songs to be resumed as long as no other music is played
- In battle, the battlefield music is resumed everytime after a battle scene
- Battle scene music can also be resumed if previous battle scene used the same music : you can now hear series of consecutive attacks from enemies with the enemy attack music being resumed ; same idea with consecutive ally attacks, as long as they share the same music, which is currently the case between all unpromoted characters and all promoted characters.

So yeah, the main workflow works quite well, and this is quite enjoyable to feel this sense of continuity, as you said Morath. :)

But there are still important things to fix :
- Resuming should be smoother, I believe some DAC samples are cut too roughly sometimes.
- I still notice wrong behavior at the end of the cutscene where Astral saves the King. The music is supposed to stop while text is displayed, but oddly enough, there is an attempt to resume previous music, and it produces wrong sound ... I'll have to debug that next.

But well, here's a new IPS patch version to try while I do the polishing :

- Resuming is now smoother by avoiding PCM sample resuming. Going back on the battlefield by first hearing the end of a releasing drum sound all of a sudden didn't feel quite clean. Now it does feel clean I think. :)
- The wrong behavior I noticed was the "Fade out" command that I had broken ... in 2009 without noticing :D ! Fixed, cutscenes can end properly now.
- Talking about cutscenes, I noticed that some resuming also happen during cutscenes and well, I don't think this should be the case, as this can alter the original intended mood of a scene, so I'll implement some way to deactivate music resuming during cutscenes.
But for now, here's a new IPS patch I'll now test more extensively on real hardware.

Sorry for the useless bump, nothing really new at the moment, but thanks to MXC I just discovered the bump feature and couldn't help but try it. :D Didn't expect the immediate effect !

Version 1.3.0 is now available, and I'm now totally satisfied with it ! :D
- Fade In has been tweaked to feel quick enough so that there's no big fall in sound volume when resuming
- The fade in also updates every instruments so that every sustained note is immediately resumed.
- Resuming can now be deactivated by a simple command from game engine to sound driver. I've configured it to avoid resuming during cutscenes.
I love it, no more repetitive music now ! :)
Original post updated, here's the link to latest IPS patch :
And a video demo :
Last edited by Wiz on Wed Jan 10 2018 11:08am, edited 1 time in total.

User avatar
Shining Member
Shining Member
Posts: 169
Joined: Sun Mar 18 2007 2:43pm
Location: Blois, France

Re: Music resuming

Postby Corsair » Wed Jan 10 2018 12:01am


User avatar
Shining Legend
Shining Legend
Posts: 7154
Joined: Mon Apr 21 2008 2:52am

Return to Shining Force II

Who is online

Users viewing this topic: No registered users and 1 guest