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: 14096
  • 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: 3118
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: 14096
  • 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: 3118
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: 3118
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: 420
  • 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: 420
  • 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: 3118
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: 420
  • 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: 3118
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: 420
  • 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: 3118
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: 420
  • 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: 3118
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: 3118
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
  • Joined: 23 Sep 2021
  • Posts: 71
  • Location: Poland
Reply with quote
Post Posted: Tue Jan 25, 2022 1:21 pm
I have written music using channel A, B and D (NOISE-DRUMS), when I play SFX which only uses channel C it stops channel D (Noise-Drums) - where's the problem? (Channel D resumes after playing SFX).

LD HL,SFX0
LD C,SFX_CHANNEL3
CALL PSGSFXPlay
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3118
Reply with quote
Post Posted: Tue Jan 25, 2022 1:53 pm
since the noise channel can also use the 3rd wave channel frequency to generate white or periodic noise, when the SFX uses channel 3 at the same time the noise channel will be silenced.

to avoid it, the only way is not to use 3rd wave channel frequency for the noise channel, which might be quite limiting honestly, but that's how the chip works.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Sep 2021
  • Posts: 71
  • Location: Poland
Reply with quote
Post Posted: Tue Jan 25, 2022 4:21 pm
I changed SFX to channel B, while C is free and channel D is NOISE-Drums. Unfortunately SFX from Channel B still interrupts Noise.

LD HL,SFX0
LD C,SFX_CHANNEL2
CALL PSGSFXPlay
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3118
Reply with quote
Post Posted: Tue Jan 25, 2022 5:10 pm
SFXs can only use channel 2 (3rd wave channel) and/or 3 (noise channel)

also the VGM files should be converted according to the channels they need to use, so possible command line switches for conversion are:

-2 for SFXs using channel 2 only
-3 for SFXs using channel 3 only
-23 for SFXs using both channels
  View user's profile Send private message Visit poster's website
  • Joined: 23 Sep 2021
  • Posts: 71
  • Location: Poland
Reply with quote
Post Posted: Tue Jan 25, 2022 5:55 pm
I converted VGM using PSGTool.jar but did not use the additional [2 | 3 | 23] command.
Now I checked and PSGTool.jar with [23] added the converted files are identical to without it.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3118
Reply with quote
Post Posted: Wed Jan 26, 2022 10:36 am
so I think the issue you're experiencing is that your tune is using the 3rd wave channel [PSG2] frequency register to drive the noise channel [PSG3] and this means that any SFXs using that very same channel will force the noise channel to silence for the whole SFX duration.

there's actually nothing you can do in this situation, as current PSGlib code doesn't support playing SFXs using the 2nd wave channel [PSG1] instead of using the 3rd, so that noise channel can continue undisturbed.

of course if you could change the tunes so that the noise channel uses only those three presets frequency that don't need the 3rd wave channel to get into play you will be fine.

how to do that, it depends on the tracker you're using.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Sep 2021
  • Posts: 71
  • Location: Poland
Reply with quote
Post Posted: Wed Jan 26, 2022 11:30 am
Thanks for the info. Channel D (3 / Noise) mutes for a while while SFX is running, so it's not a huge problem. I was just wondering why this was happening, now it's clear.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3118
Reply with quote
Post Posted: Wed Jan 26, 2022 4:56 pm
for best results anyway if your SFX uses only the 3rd wave channel [PSG2] then convert the VGM using the additional 2 on the command line switch (it means 'filter out everything that's not on PSG2') and in your code fire the effect using:

LD HL,SFX0
LD C,SFX_CHANNEL2
CALL PSGSFXPlay
  View user's profile Send private message Visit poster's website
  • Joined: 23 Sep 2021
  • Posts: 71
  • Location: Poland
Reply with quote
Post Posted: Fri Apr 01, 2022 7:52 pm
What do I need to pay attention to or make any changes to make PSGLib work with the ColecoVision code? At the moment, nothing works, there is silence - I probably don't know something.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3118
Reply with quote
Post Posted: Mon Apr 04, 2022 12:32 pm
I suspect the PSG is mapped onto a different port in the ColecoVision. Let me check that...

edit: it seems like the ColecoVision has the PSG mapped at I/O C0-DF thus I would try changing the PSGlib.inc souce from

.define      PSGDataPort         $7f


to

.define      PSGDataPort         $df


and see if it plays
  View user's profile Send private message Visit poster's website
  • Joined: 23 Sep 2021
  • Posts: 71
  • Location: Poland
Reply with quote
Post Posted: Mon Apr 04, 2022 4:28 pm
I changed it earlier, but unfortunately still silence. It may be required to additionally initialize the sound via the BIOS.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3118
Reply with quote
Post Posted: Tue Apr 05, 2022 7:25 am
other sources say the PSG port is the $E0-$FF range, so you might want to try with this instead:

define      PSGDataPort         $ff
  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!