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 'official' topic [was: "Music engines"]

Reply to topic Goto page Previous  1, 2, 3, 4, 5
Author Message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 13231
  • Location: London
Reply with quote
Post Posted: Wed Oct 18, 2017 9:02 am
Then I guess the compression isn't helpful, except perhaps to avoid exceeding 16KB? I always compress my assets on principle, the 4MB limit doesn't come close...
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Wed Oct 18, 2017 9:22 am
The 16 KB limit is disturbing IMHO :|

Tunes that turn just over 16 KB when compressed have to be 'simplified' so that they would fit, tunes much bigger have to be split into separate tunes and somehow 'linked' at run time (that is, start part #2 when part #1 is over...)

Compression on these assets also means to save some ROM for almost no drawbacks - PSGlib plays compressed tunes directly with tiny overhead.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 13231
  • Location: London
Reply with quote
Post Posted: Wed Oct 18, 2017 10:42 am
I suspect tunes going over 16KB are doing write intensive things like vibrato, tremolo and arpeggiation. A heavier music engine would generate these from very little data, at the cost of more CPU; these are exactly the sort of thing that it may be possible to tailor the compression for, for example some RLE for repeating sequences would do a lot better than repeated back references to a single copy of the repeated sequence.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Wed Oct 18, 2017 11:34 am
yes, a nice alternative to a VGM-source driven approach would be a tracker-source driven approach, Mod2PSG2 style.

To do this BTW we should also (engine itself apart) create a format and converters from other tracker formats (DefleMask, MusicMaker, etc...)

or revitalize Mod2PSG2 engine...
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Wed Oct 18, 2017 3:13 pm
eruiz00 wrote
Have to test NOW as i spent 93 kb for psgs. If could get more space it would be great.


OK, don't waste your time. Try Calindro's KiddEd built in PSG converter (export functions), it works much better.

I'll let you all know when my own compressor would be finally worthy :(
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 377
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sat Oct 21, 2017 5:14 pm
Ummmm....

This evening, testing the function PSGSetMusicVolumeAttenuation
I see it only produces glitches.

I explain: I want to use it to fade out the music, while its playing, doing this:


// Fade music
for(a=0;a<=60;a++)
{
   SMS_waitForVBlank();
   if(a%4==0)
      PSGSetMusicVolumeAttenuation (a>>2);
}


Have to say the music update routine is in a interrupt handler at 180:


// Handler de interrupciones
void InterruptHandler(void)
{
   unsigned char oldbank=lastbank;
   
   // Update music
   if(musicbank)
   {
      changeBank(musicbank);
      PSGFrame();
   }

   // Update sounds
   if(PSGSFXGetStatus())
   {
      changeBank(soundbank);
      PSGSFXFrame();
   }

   SMS_mapROMBank(oldbank);

   numinterrupts++;
}


Any insight?

[/code]

I am using z88dk, if this could be of utility...
  View user's profile Send private message
  • Joined: 28 Jan 2017
  • Posts: 377
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sat Oct 21, 2017 5:34 pm
Tryed the following change:


   SMS_waitForVBlank();
   if(a%8==0)
   {
      PSGStop ();
      PSGSetMusicVolumeAttenuation(a>>2);
      PSGResume ();
   }


But PSGResume() does not exit. Should not have been ported to z88dk. If this wont help, it doesnt matter, afterall.

Thanks!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Sat Oct 21, 2017 8:56 pm
you don't need to stop and resume to change music volume attenuation

tell me more about the glitches (I've never experienced them)
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 377
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sat Oct 21, 2017 9:41 pm
Have been testing.

What it happens is every frame i use the function, there are a sound in channel 3 (a noise sound) at full volume. The music is 'lowering' the volume OK, but there are a 'click' (or other type or noise, from the noise type sounds you can ear in vgm2psg, by example).

The video show a 120 frames fade (two seconds) with the above functions, lowering the sound each 20 frames (frame>>3).

I think that if you have a music with other sound effect on chanel 3, it will play that last sound played at full volume each time you call the function.

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Sat Oct 21, 2017 10:37 pm
void PSGSetMusicVolumeAttenuation (unsigned char attenuation) {
/* *********************************************************************
  sets the volume attenuation for the music (0-15)
*/
  PSGMusicVolumeAttenuation=attenuation;
  if (PSGMusicStatus) {
    PSGPort=PSGLatch|PSGChannel0|PSGVolumeData|((PSGChan0Volume+PSGMusicVolumeAttenuation>15)?15:PSGChan0Volume+PSGMusicVolumeAttenuation);
    PSGPort=PSGLatch|PSGChannel1|PSGVolumeData|((PSGChan1Volume+PSGMusicVolumeAttenuation>15)?15:PSGChan1Volume+PSGMusicVolumeAttenuation);
    if (!PSGChannel2SFX)
      PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|((PSGChan2Volume+PSGMusicVolumeAttenuation>15)?15:PSGChan2Volume+PSGMusicVolumeAttenuation);
    if (!PSGChannel3SFX)
      PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|((PSGChan3Volume+PSGMusicVolumeAttenuation>15)?15:PSGChan3Volume+PSGMusicVolumeAttenuation);
  }
}


if channel 2 and/or channel 3 is/are busy with SFX(s) its/their volume(s) won't be updated. I don't get what's happening with your fade... are you playing an SFX there?
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 377
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sun Oct 22, 2017 12:17 am
Ummmm....

Have changed the function by this:


PSGSFXStop();
if(lastplayedmusic!=0)
{
   // Fade music
   for(a=0;a<=120;a++)
   {
      if(a%8==0)
      {
         PSGSetMusicVolumeAttenuation(a>>3);
      }
      SMS_waitForVBlank();
   }
}


Does not work (glitches)

After that fail, made a pg with a volume 0 sound and enough length. Change the function by this:


PSGSFXPlaySound(nosound_psg);
if(lastplayedmusic!=0)
{
   // Fade music
   for(a=0;a<=120;a++)
   {
      if(a%8==0)
      {
         PSGSetMusicVolumeAttenuation(a>>3);
      }
      SMS_waitForVBlank();
   }
}


As psglib see it is playing a sound, should not touch the volume (like you said), but does exactly the same.

Doing slower fadeouts, what i can say is that it seems that ONLY in those frames in which you call psgsetmusicvolumeattenuation the music does not sound, and a glitch in channel 3 sounds instead.

... remember i am with z88dk implementation.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Sun Oct 22, 2017 9:41 am
try compiling a small separate program with SDCC and see if you experience the same problems. I'm my tests I don't get any problem changing volume while tune is playing.
  View user's profile Send private message Visit poster's website
  • Joined: 17 Nov 2015
  • Posts: 97
  • Location: Canada
Reply with quote
Post Posted: Sun Oct 22, 2017 6:09 pm
The code in z88dk is not identical to psglib because everything has been rewritten in asm (where that applies). It should be functionally identical but it's not impossible that there are bugs.

z88dk's psglib is rooted here:
https://github.com/z88dk/z88dk/tree/master/libsrc/_DEVELOPMENT/arch/sms/PSGlib/z...

I'll take a look to see if I can spot anything.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 377
  • Location: Málaga, Spain
Reply with quote
Post Posted: Fri Oct 27, 2017 5:27 am
Yeah!

With kidded the psg size went from 93kb to 75kb!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Fri Oct 27, 2017 7:59 am
eruiz00 wrote
With kidded the psg size went from 93kb to 75kb!


yeah, that's a nice compressor, unlike my own! :|
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2686
Reply with quote
Post Posted: Sun Apr 05, 2020 1:09 pm
just added the
PSGlib function reference
that was missing...
  View user's profile Send private message Visit poster's website
Reply to topic Goto page Previous  1, 2, 3, 4, 5



Back to the top of this page

Back to SMS Power!