VGM Driver Update

Announce (tech) demos or games releases

Moderator: Mask of Destiny

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

VGM Driver Update

Post by kubilus1 » Thu Jan 16, 2014 1:06 am

I've been updating the z80 VGM driver to be a bit faster and add some new features. Just so you guys don't think I've forgotten about the project, here is a quick demo of what I have.

https://drive.google.com/file/d/0B7gb_C ... sp=sharing

This is quite a bit more efficient than the old driver and should support the older 1.5 style PCM samples (using 0x8n opcodes) at 8khz. This should be pretty good as is for this kind of playback.

I've also added rudimentary sound effects support as well. The sound effect must be an 8khz unsigned 8 bit PCM. Wav files could be converted with the following ffmpeg command:

Code: Select all

ffmpeg -i in.wav -f u8 -ar 8000 -acodec pcm_u8 out.pcm
The sound effect will effectively take over the PCM channel for the duration of the PCM playback. I'm not totally happy with the results, but it is a nice improvement over the old driver.

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Jan 16, 2014 1:40 am

Some notes on the tracks chosen:

Green Hill Zone - A 1.6 VGM track with PCM samples that are referenced by 0x9n style calls.

ToeJam Slowjam - A 1.5 VGM track that starts out without PCM samples, but uses channel 6 for part of the music. Sound effect must return the state of channel 6 after finishing playback.

Elevator Beats - A 1.5 VGM track that consists almost entirely of PCM.

Pacific Coast - A very busy VGM track, no PCM.

Redwood Forest - Busy VGM track with a *ton* of banking.

djcouchycouch
Very interested
Posts: 683
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu Jan 16, 2014 1:50 am

kubilus1 wrote: Green Hill Zone - A 1.6 VGM track with PCM samples that are referenced by 0x9n style calls.
Not knowing what 0x9n style calls actually are, did you mean 0x8n? A typo?

Mask of Destiny
Very interested
Posts: 591
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Thu Jan 16, 2014 1:53 am

VGM 1.6 added new more efficient DAC instructions ranging from 0x90-0x95.

djcouchycouch
Very interested
Posts: 683
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu Jan 16, 2014 1:55 am

Mask of Destiny wrote:VGM 1.6 added new more efficient DAC instructions ranging from 0x90-0x95.

Right, sorry!

I tried it out and I think it's pretty nifty. :)

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Jan 16, 2014 2:06 am

Yeah, sorry I wasn't clear. With the old VGM formats for PCM your first did a 0xE0 followed by a location into PCM memory, then you followed it with 0x80-0x8F where the first nibble says to play one PCM byte and the second is how many samples to wait.

1.6 added the ability to just enable playing the PCM and to set the length to play and just execute a single 0x93 or 0x95 instruction to start the playback. The playback then occurs during 0x6n style sample waits, effectively.

The long and short is the VGM files can be a lot smaller.

Stef
Very interested
Posts: 3004
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Jan 16, 2014 9:40 am

Really cool news ! Do you think i can replace the current SGDK version by this one without much trouble ?

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Jan 16, 2014 1:24 pm

Yes! This is a drop in replacement for the existing vgm driver in sgdk. I have a patch against sound.c as well that will add the sound effects playback. I'll post it when I get back from work this evening.

nolddor
Very interested
Posts: 101
Joined: Sun Jun 02, 2013 1:35 pm
Location: Spain

Post by nolddor » Thu Jan 16, 2014 3:11 pm

Good news !!! the VGM driver it's alive :D

Someday there will be a VGM_resumePlay (); ...... xD

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Jan 16, 2014 3:42 pm

Someday there will be a VGM_resumePlay (); ...... xD
Perhaps, what do you mean exactly?

djcouchycouch
Very interested
Posts: 683
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu Jan 16, 2014 5:08 pm

So you recommend Deflemask for composing new VGMs? Will the driver be able to take pretty much anything from Deflemask or are there limitations or settings to keep in mind?

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Jan 16, 2014 5:58 pm

It should be able to take pretty much anything from Deflemask with the caveat being the samples are 8khz. Otherwise, I've been able to play anything I've composed, plus sthe samples from Deflemask that I've tried.

I understand that there are some other good VGM tools as well, but they don't work on Linux, so I haven't used them.

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Fri Jan 17, 2014 12:27 am

Patch to SGDK to play sound effects with the driver:

Code: Select all

Index: include/sound.h
===================================================================
--- include/sound.h     (revision 96)
+++ include/sound.h     (working copy)
@@ -511,5 +505,16 @@
  */
 void SND_stopPlay_VGM();
 
+/**
+ * \brief
+ *      Resume playing music after stopping with SND_stopPlay_VGM.
+ */
+void SND_resumePlay_VGM();
 
+/**
+ * \brief
+ *      Play a PCM sound effect while a VGM track is playing.
+ */    
+void SND_playSfx_VGM(unsigned int addr, u16 len); 
+
 #endif // _SOUND_H_
Index: src/sound.c
===================================================================
--- src/sound.c (revision 96)
+++ src/sound.c (working copy)
@@ -830,3 +821,46 @@
 
     Z80_releaseBus();
 }
+
+void SND_resumePlay_VGM()
+{
+    vu8 *pb;
+
+    // load the appropried driver if not already done
+    Z80_loadDriver(Z80_DRIVER_VGM, 1);
+
+    Z80_requestBus(1);
+
+    // point to Z80 VGM play parameter
+    pb = (u8 *) 0xA01004;
+    *pb = 0x01;
+
+    Z80_releaseBus();
+}
+
+void SND_playSfx_VGM(unsigned int addr, u16 len) 
+{
+    vu8 *pb;
+    u16 z80addr;
+    u8 z80bank;
+    z80bank = ((addr & 0xFF8000) >> 15);
+    z80addr = ((addr & ~0xFF8000) + 0x8000);
+
+    char *p = (char *) 0xA01027;
+    char *q = (char *)&z80addr;
+    char *r = (char *) 0xA01029;
+    char *s = (char *)&len;
+    char *t = (char *) 0xA01026;
+    char *u = (char *)&z80bank;
+
+    Z80_requestBus(1);
+    p[0] = q[1];
+    p[1] = q[0];
+    r[0] = s[1];
+    r[1] = s[0];
+    t[0] = u[0];
+    pb = (u8 *) 0xA01025;
+    *pb = 0x01;
+    Z80_releaseBus();
+}
+

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Fri Jan 17, 2014 12:29 am

Also, the above patch will allow resuming play of VGM files.

Stop the playing track ->
SND_stopPlay_VGM();

Resume the playing track ->
SND_resumePlay_VGM();

Should be useful when pausing, and such.

nolddor
Very interested
Posts: 101
Joined: Sun Jun 02, 2013 1:35 pm
Location: Spain

Post by nolddor » Fri Jan 17, 2014 8:57 am

kubilus1 wrote:
Someday there will be a VGM_resumePlay (); ...... xD
Perhaps, what do you mean exactly?
Nowadays, SGDK hasn't a SND_resumePlay_VGM();... only it has a Stop o Start function.

This function is very useful to push pause into a game.

Post Reply