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: 14685
  • 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: 3758
  • Location: Stockholm, Sweden
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: 14685
  • 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: 3758
  • Location: Stockholm, Sweden
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: 3758
  • Location: Stockholm, Sweden
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: 540
  • 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: 540
  • 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: 3758
  • Location: Stockholm, Sweden
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: 540
  • 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: 3758
  • Location: Stockholm, Sweden
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: 540
  • 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: 3758
  • Location: Stockholm, Sweden
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: 540
  • 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: 3758
  • Location: Stockholm, Sweden
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: 3758
  • Location: Stockholm, Sweden
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: 96
  • 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: 3758
  • Location: Stockholm, Sweden
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: 96
  • 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: 3758
  • Location: Stockholm, Sweden
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: 96
  • 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: 3758
  • Location: Stockholm, Sweden
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: 96
  • 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: 3758
  • Location: Stockholm, Sweden
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: 96
  • 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: 3758
  • Location: Stockholm, Sweden
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: 96
  • 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: 3758
  • Location: Stockholm, Sweden
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
  • Joined: 05 Sep 2013
  • Posts: 3758
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Sep 16, 2022 1:03 pm
Thanks to raphnet's work, devkitSMS' PSGlib now supports even larger tunes! :D
Now uncompressed tunes have no real limit (compressed tunes should be limited to 64 KiB, at least until we fix the compressors...)

PSGlib_MB (as in MultiBank) requires you to use the newer assets2banks to arrange tune files into banks in a way that guarantees that each song data is contiguous, then the paging will be handled automatically by the library, all you have to do is to specify the bank number where the tune starts as a second parameter when starting a tune as in:

PSGPlay (void *song, unsigned char bank);
or
PSGPlayNoRepeat (void *song, unsigned char bank);
or
PSGPlayLoops (void *song, unsigned char bank, unsigned char loops);



To use this version you have to define
PSGLIB_MULTIBANK

before including the header file and then link the MB version object file PSGlib_MB.rel instead of the usual PSGlib.rel.

We hope you'll enjoy it!

P.S. no changes have been made to the 'standard' PSGlib library so you don't need this new feature if your tunes are 16 KiB at most.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 540
  • Location: Málaga, Spain
Reply with quote
Great work!
Post Posted: Fri Dec 02, 2022 3:22 pm
Last edited by eruiz00 on Fri Dec 02, 2022 5:13 pm; edited 1 time in total
Hi!

Had a big, long, 31kb psg compressed song, and it works!

Thanks Sverx, very professional work, as always.

PD. Oh my god, One time I compiled the game it worked well, but then changed a song now doesn't. Testing.

PD2. Well.... I have been testing. What I found is that the uncompressed psg works well, but the compressed (with the psgcomp found today in the psglib github page) not.

Send a PM with a test project.

Regards!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3758
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Dec 02, 2022 4:47 pm
eruiz00 wrote
Had a big, long, 31kb psg compressed song, and it works!
Thanks Sverx, very professional work, as always.


That's raphnet's work. I've never done anything that can be deemed 'professional' XD
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 540
  • Location: Málaga, Spain
Reply with quote
Post Posted: Fri Dec 02, 2022 5:15 pm
sverx wrote
eruiz00 wrote
Had a big, long, 31kb psg compressed song, and it works!
Thanks Sverx, very professional work, as always.


That's raphnet's work. I've never done anything that can be deemed 'professional' XD


Almost everyone involved in something like this has to be a great guy... but I send you a probe of an error LOL I know this will have a solution. If not, I will put the psgs without compression!

Note: everything is up to date, the libs, the headers, the compiler.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3758
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Dec 05, 2022 8:03 am
eruiz00 wrote
What I found is that the uncompressed psg works well, but the compressed (with the psgcomp found today in the psglib github page) not.


I'll look into that ASAP. In the meantime, try compressing using Calindro's PSGTool to check if that has a different outcome.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3758
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Jan 20, 2023 1:59 pm
I forgot to post here to say that this issue has been resolved already.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3758
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Oct 30, 2023 1:49 pm
A common pitfall I noticed with SFXs is that one could have a noise channel only SFX use channel 2 tone generator and convert that using only '3' as a vgm2psg optional parameter thus creating an SFX file that doesn't work as expected, so I just pushed a small update to the vgm2psg converter that warns the user when such cases happens.

So if running
vgm2psg explosion.vgm explosion.psg 3
you get this message:
Quote
*** sverx's VGM to PSG converter ***
Info: SFX conversion on channel(s): 3
Warning: channel 3 (the noise channel) is using channel 2 tone. You probably need to run vgm2psg using option 23
Info: conversion complete


it means you should either fix your vgm or run the converter again with
vgm2psg explosion.vgm explosion.psg 23
  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!