Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - PSGLib feature request: PSGFadeIn/Out

Reply to topic
Author Message
  • Joined: 23 Mar 2013
  • Posts: 611
  • Location: Copenhagen, Denmark
Reply with quote
PSGLib feature request: PSGFadeIn/Out
Post Posted: Mon Apr 20, 2015 8:35 am
PSGLib should really have its own development thread. Well, anyway, I have a feature request... :)

PSGLib is the music engine to end all SMS homebrew game music engines, IMO.Compact, clean and out of the way when you don't need it, and easy to control when you do need it. You couldn't ask for more. Well, here I go: Would it be possible to add fade in/out commands for background music? I think it would go well with screen fading transitions, etc.
  View user's profile Send private message Visit poster's website
  • Joined: 14 Apr 2013
  • Posts: 624
Reply with quote
Post Posted: Mon Apr 20, 2015 8:52 am
hang-on wrote
PSGLib should really have its own development thread. Well, anyway, I have a feature request... :)

PSGLib is the music engine to end all SMS homebrew game music engines, IMO.Compact, clean and out of the way when you don't need it, and easy to control when you do need it. You couldn't ask for more. Well, here I go: Would it be possible to add fade in/out commands for background music? I think it would go well with screen fading transitions, etc.

I fear it's not really possible because PSGlib doesn't know about volumes (and frequencies). It only knows about registers and values it can write to the registers. So if you want to do fading you will need to do it in your psgfile itself.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Mar 2013
  • Posts: 611
  • Location: Copenhagen, Denmark
Reply with quote
Post Posted: Mon Apr 20, 2015 12:51 pm
Hmmm, alright - I was imagining some kind of master volume control knob, that would override whatever was in the psg-file. But I'll have to admit that I have no idea what is going on under the hood :)
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Tue Apr 21, 2015 8:05 am
hang-on wrote
I was imagining some kind of master volume control knob, that would override whatever was in the psg-file.

That's almost exactly what I was thinking! I thought of like a 'global volume modifier' sort of thing.
E.g. if the modifier is 0, nothing changes, but if it's -5, it lowers the volume by five. So if the volume for a tone register is set to 15 (decimal) in a PSG file, it changes to 10. But if its set to 5 or less in a psg file, it's set to zero.
  View user's profile Send private message Visit poster's website
  • Joined: 31 Oct 2007
  • Posts: 853
  • Location: Estonia, Rapla city
Reply with quote
Post Posted: Thu Apr 23, 2015 2:03 pm
Since PSG has logarithmic volume scale all you need is to add a fixed value to all the volume registers to get equal attenuation going on.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue May 05, 2015 8:17 am
I thought about adding this feature few times in the past months, actually.
What has stopped me is that it should also change the volume of already playing channels, which requires to rewrite a big chunk of the PSGFrame function so that it saves volume for each one of the 4 PSG channels.
Thus I'm not saying it isn't possible, just that it's something I'm not planning to do at the moment :|
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu May 28, 2015 1:54 pm
I'm actually exploring the chance of adding this feature, and I realized it would be easier if I can be absolutely sure there are no 'unlatched' PSG commands for volumes and for noise channel mode/frequency in the PSG file.
So I'm asking the experts: can I safely convert each and every unlatched volume command to a latched one? Can I also safely do the same for the noise channel 'tone' register? If there are no concerns about this, I will work on rolling a new vgm2psg and a new PSGlib version which supports 'volume attenuation' of the tune...
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Thu May 28, 2015 2:02 pm
I only experimented with that stuff on an SMS2. Are you suggesting using the two-write versions instead of the single byte ones? The former is non standard and may not work everywhere, the latter is following the docs.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu May 28, 2015 2:09 pm
Two writes? I don't even know what's that :D
I meant... can I replace the non-latched PSG commands such as
%0-DDDDDD

with the corresponding latched versions
%1cctdddd

for volumes and noise channel mode/shift rate with no side effects?
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu May 28, 2015 3:08 pm
oh wait, I'm already doing this in vgm2psg, I didn't even remember that... sorry pal :)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu May 28, 2015 3:30 pm
Update rolled. Now you can set the attenuation by setting the value in register L and calling the PSGSetMusicVolumeAttenuation routine.

ld l,6
call PSGSetMusicVolumeAttenuation


it should work even while the tune is playing.
Keep in mind that it's a "global" setting. It means that for instance if after doing a complete volume fade out and stopping the tune you forget to set it back at 0, you won't hear anything when you'll start a new tune. You should call the function again using 0 for full volume. A value of 15 will 'mute' the tune completely. SFXs are NOT affected.

Let me know if it doesn't work as expected :)
  View user's profile Send private message Visit poster's website
  • Joined: 23 Mar 2013
  • Posts: 611
  • Location: Copenhagen, Denmark
Reply with quote
Post Posted: Thu May 28, 2015 6:14 pm
Great sverx - thanks! I'll try it out next time I fiddle with music.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri May 29, 2015 8:17 am
Of course I forgot that I also had to fix PSGSFXStop so that it correctly restores the tune volumes, applying attenuation, when a SFX is over or stopped.
Now it should be fixed... so please download again :)
  View user's profile Send private message Visit poster's website
  • Joined: 01 Feb 2014
  • Posts: 878
Reply with quote
Post Posted: Fri May 29, 2015 4:02 pm
hang-on wrote
Great sverx - thanks! I'll try it out next time I fiddle with music.

Same here, and I'm looking forward to trying this out. It's probably going to be a while until I'll do some music again, though.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!