Author Topic: VGM playback  (Read 16167 times)

0 Members and 1 Guest are viewing this topic.

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
VGM playback
« on: July 03, 2010, 07:15:25 AM »
Here's a look at my latest little project for the SNES: http://www.youtube.com/watch?v=AUlwVFGTmzY

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: VGM playback
« Reply #1 on: July 04, 2010, 01:25:02 AM »
Nifty! PSG-only, but that's really all you can expect. Now you play two kinds of music.  :D

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: VGM playback
« Reply #2 on: July 04, 2010, 06:58:30 AM »
Maybe something like the YM2413 would be possible since most of the instruments are fixed. But that would still require a fair amount of sample data to put in the SPC's 64 kB RAM, where I have to fit the entire VGM as well. Right now I only need a 9-byte square wave sample, while the white noise generation comes for free  :)

One thing I have been working on, though, is a compression scheme that allows me to fit VGMs larger than 64 kB (actually around 60 kB since i need a few k for code and data). I settled for a simple method that gives about a 30% compression ratio on typical SMS/GG VGMs, but is fast enough to decrunch on-the-fly. So that ups my song size limit to about 90 kB.

I still need to tweak the timing a bit though.

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: VGM playback
« Reply #3 on: July 04, 2010, 08:19:59 AM »
That's the compression you were working on for the MD player over at spritesmind, right? I really need to work that into the MD Myth player (which is just your player minus the compression).  ::sm-09.gif::

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: VGM playback
« Reply #4 on: July 04, 2010, 03:50:02 PM »
Right, but I used a different algorithm here. For MD VGMs the real space-waster is usually the DAC write commands (0x8n) that tend to occur in long sequences, but with varying values for n.
For SMS/GG VGMs the DAC is irrelevant, but you've got a lot of 0x50 0xnn commands (which writes 0xnn to the PSG) - sometimes with a wait-command shoved in between every couple of PSG writes. So what I did was to store a byte of flags for every eight commands. If the corresponding bit in the flag byte is 0 then the full command is present. If the bit is 1 then the command is implied to be 0x50 and only the 0xnn byte is present in the compressed stream.

This sequence of commands:

50 FF
75
50 A6
50 0D
50 D2
61 D6 02
50 96
72

gets compressed into:

5D     // flags
FF
75
A6
0D
D2
61 D6 02
96
72

Here it is in action, playing a compressed song: http://www.youtube.com/watch?v=q2RRE0C7OVU
« Last Edit: July 04, 2010, 04:30:52 PM by mic_ »

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: VGM playback
« Reply #5 on: July 04, 2010, 04:13:26 PM »
Very interesting!!  :D

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: VGM playback
« Reply #6 on: July 04, 2010, 06:05:51 PM »
I've created a tool that converts from .VGM to .SPC.

Give it a .VGM/.VGZ file and it'll spit out an .SPC file with the VGM data and my playback code.

The zip also includes the SPC-700 assembly code for the player.

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: VGM playback
« Reply #7 on: July 07, 2010, 01:31:59 AM »
I've updated the converter as well as the playback code, trying to improve lots of small things. The new version is available here.

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: VGM playback
« Reply #8 on: July 14, 2010, 03:20:17 PM »


I've created a GUI for the playback code and put together a ROM with 32 handpicked VGMs: download link

Use a real SNES or BSNES to run it, other emulators will likely mess the sound up.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: VGM playback
« Reply #9 on: July 14, 2010, 04:48:31 PM »
Just tried it , and wow its really cool :D
Seems like you had lots of fun coding it.  ::sm-29.gif::
I also like this "jumpy" text effect which most of the time gets filled with dev log  ~sm-80.gif~.gif  :)

Offline Dr.neo

  • Administrator
  • Hero Member
  • *****
  • Posts: 3826
Re: VGM playback
« Reply #10 on: July 14, 2010, 05:25:19 PM »
it's very cool project, need post to neo homepage indeed  ~sm-36.gif~
In my world,have 0 and 1 only ......Matrix World......

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: VGM playback
« Reply #11 on: July 14, 2010, 05:35:30 PM »
I'm not sure if fun was the main driving force. More like a will to finish it  ::sm-21.gif::

The GUI code is 2000+ lines of poorly written assembly. Lots of hardcoded values/addresses, anonymous labels, and practically no comments. But it turned out ok I think. At least there are no serious bugs in it that I know of.  >:(

Offline Aaendi

  • Newbie
  • *
  • Posts: 25
Re: VGM playback
« Reply #12 on: July 15, 2010, 06:21:25 AM »
I'm not sure if fun was the main driving force. More like a will to finish it  ::sm-21.gif::

The GUI code is 2000+ lines of poorly written assembly. Lots of hardcoded values/addresses, anonymous labels, and practically no comments. But it turned out ok I think. At least there are no serious bugs in it that I know of.  >:(

Sounds like my dynamic animation engine.  I'm trying to release the source code, but it's full of hardcoded values/addresses, no comments and different parts of the engine are in seperate places in my game's code.

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: VGM playback
« Reply #13 on: September 26, 2012, 10:46:26 PM »
I've updated this project a bit lately. Here's the latest ROM, here's the latest source code, and here's a youtube video of the ROM running on a PAL SNES.

Short changelog:
*Improved the VGM compression, without any significant increase in decompression complexity.
*Added 18 more songs, so there are now 50 in total.
*Improved playback timing by using carefully timed code.
*More accurate handling of the noise bass functionality. The previous version used an incorrect duty cycle and a gain that was way too low.
*Varius GUI bugfixes.
*Added a few audio filters that you can switch between using Right on the D-Pad. There's the default one (no filter), echo (80ms delay), a bass boost filter (mix between the original signal, slightly attenuated, and a low pass-filtered version of itself), bass boost with delay, and treble boost (similar to the bass boost but using a high pass filter instead).