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 - Reversing VGM files

Reply to topic
Author Message
  • Joined: 31 Mar 2015
  • Posts: 20
  • Location: Carlisle, UK
Reply with quote
Reversing VGM files
Post Posted: Wed Feb 28, 2018 7:14 pm
Hi, is there an easy way, a website, or an app, that can reverse the sound output in a VGM so that it can play backwards?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12477
  • Location: London
Reply with quote
Post Posted: Wed Feb 28, 2018 7:39 pm
No, it may be quite hard. Probably easier to reverse the WAV.
  View user's profile Send private message Visit poster's website
  • Joined: 16 May 2002
  • Posts: 1116
  • Location: italy
Reply with quote
Post Posted: Wed Feb 28, 2018 10:26 pm
You know, I gave this a quick try, but yeah, it's not as simple as reversing the order of the commands, some stuff rely on the current status of the chip to properly work. I deliberately excluded 1.50 Data Blocks, and I knew from the start that the GG Stereo would have been broken, but yeah, I underestimated the number of things which just can't be swapped around. A task like this is better suited for ValleyBell's black magic.

For the lulz, I attached a very broken Sunset Park 3 Backwards. I recommend you to turn down the volume because it's not nice to listen to.
Sunset Park 3 Backwards.vgz (3.54 KB)
Sunset Park 3 Backwards

  View user's profile Send private message Visit poster's website
  • Joined: 31 Mar 2015
  • Posts: 20
  • Location: Carlisle, UK
Reply with quote
Post Posted: Wed Feb 28, 2018 11:29 pm
Ahh, I get you, thought it might be hard. I'm not skilled enough at vgm-mm to make stuff, I'm working on a rom hack and considered using one of the original pieces played backwards as a sort of joke. It's easy enough for me to use good sn76489 music I found, though I intend to put a few other creations in too. When people get musical help on hacks, is it common practice to offer compensation regardless of the work required? I'm certainly going to need help eventually and I certainly wouldn't want to go begging.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12477
  • Location: London
Reply with quote
Post Posted: Thu Mar 01, 2018 12:24 am
I think it's mostly done pro bono.

For some chips it's almost entirely impossible to play backwards - envelopes and key events are hard to build and place - but for SN76489 in theory you could chunk the file into states with durations, reverse that and then render it back to VGM. It'd almost certainly sound terrible though. Is that the approach you took, Tom? I'm too lazy to try it myself, but the reversed WAV would be a good way to approximate the result before doing the hard work.
  View user's profile Send private message Visit poster's website
  • Joined: 16 May 2002
  • Posts: 1116
  • Location: italy
Reply with quote
Post Posted: Thu Mar 01, 2018 1:06 am
Last edited by Tom on Thu Sep 27, 2018 1:37 pm; edited 1 time in total
No, my attempt was even quicker and dirtier than that, I merely reversed the order of the commands, my laziness prevented me from doing anything better. At first I thought that only the GG Stereo events would be broken, but I later realised all the flaws of such a direct solution. Sometimes my curiosity prevents me from thinking straight before I start coding something, so I extremely underestimated the complexity of such a seemingly trivial task, only opening my eyes while I was falling back to the ground.

Later, I indeed thought about a solution which would detect the "important" commands which define a state (including GG Stereo, why not), and put them in a proper order, but I felt it would have been way too much work for such a novelty, so I didn't pursue it. I can totally see this feature sneaking its way into one of ValleyBell's tools, though, since he can speak the VGM language as well as he can speak English. Or German.

I'm sorry, I could have avoided these two posts if only I counted up to ten (thousands) before I started coding while thinking "let's just reverse the order of the commands and see if that works".

On a side note, the mere "reverse the order of the commands" approach should totally work in other file formats which don't preserve the state. For example, it wouldn't work with MIDI files, because, like VGM files, they would require a more accurate handling of instruments and controllers (the most obvious one being volume), but it should theoretically work with simple MOD/XM files (but not IT files). Of course, if the MOD/XM file uses advanced commands such as portamento, then it's all lost once again.

Still, even in the ideal conditions, one should still think about what to do with the note durations. Think about this example:
  • Note A
  • Wait 5
  • Note B
  • Wait 1
  • Note C
If played backwards, how long should "Note B" be? Originally meant to be a note with duration 1, should it now have a duration 5? This is debatable, I guess. In a backwards WAV file you'd hear the tail of "Note A" after 1 time unit, so I guess that "Note B" should retain its duration after all. This is such a mess.

I really, really should count up to ten (billions) before I start wondering about things.

edit: I noticed a typo, like, 6 months later
  View user's profile Send private message Visit poster's website
  • Joined: 31 Jan 2014
  • Posts: 35
Reply with quote
Post Posted: Thu Mar 01, 2018 7:47 am
Yeah, reversing playback isn't straightforward, though it's probably doable with a bit of effort. If you want something comparable but simpler, it would probably be easier to make a "frequency inverter" that can do what this hack does, but for SMS/GG VGM files. It still wouldn't be 100% trivial, since you'd have to simulate playback in order to combine the separate latch/data commands and get the actual output tone on each channel, but I don't think it'd be difficult. You'd probably need some options for setting the inversion point/range, too, because a literal frequency inversion usually results in a lot of ear-splittingly high tones (as I found when I made a few hacks like this a while back).

I'm not promising I'll do anything, mind, but I might try it if no one else wants to.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2296
Reply with quote
Post Posted: Thu Mar 01, 2018 10:59 am
maybe making the original tune set all the 4 channels parameters at every tick would be a good starting data to handle the way Tom explained?
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12477
  • Location: London
Reply with quote
Post Posted: Thu Mar 01, 2018 1:13 pm
The basis for a VGM trimmer or optimiser is to transform it from commands + timing to states + duration. This is kind of like transforming a video file to all keyframes - you can then mess with it (cut, reverse, transform, filter, transpose, time stretch) and then pass it back into the reverse transformation to VGM commands. So it's possibly fairly easy to bolt onto an existing tool or framework. The only issue is that backwards music still sounds weird...
  View user's profile Send private message Visit poster's website
  • Joined: 16 May 2002
  • Posts: 1116
  • Location: italy
Reply with quote
Post Posted: Fri Mar 02, 2018 1:27 am
Last edited by Tom on Fri Mar 02, 2018 3:11 am; edited 1 time in total
Why did I spend so much time on this.

I'll test it a bit more and then I'll release it, both the tool and the source code.
Sunset Park 3 Backwards (good).vgm (16.55 KB)
Sunset Park 3 Backwards... only it's good this time
Lemmings_backwards.vgm (9.41 KB)
She'll be coming... ohwait, she'll be going towards the mountain, I guess, since this is backwards
Chris_backwards.vgm (30.87 KB)
Hey Chris, please don't hate me, I just wanted to test something complex and your song is awesome :U
Ending_backwards.vgm (39.63 KB)
You know, this sounds better than I expected

  View user's profile Send private message Visit poster's website
  • Joined: 16 May 2002
  • Posts: 1116
  • Location: italy
Reply with quote
Post Posted: Fri Mar 02, 2018 3:01 am
Last edited by Tom on Fri Mar 02, 2018 11:54 pm; edited 1 time in total
Ok so, I tested it a bit more, and I think I can release what I have so far. Sorry for the double post, but I thought it would have been cleaner to have a single dedicated attachment instead of mixing it with the examples I posted before. I labeled it as version 0.1 since I know that some people like to keep a timeline of older versions or something.
UPDATE: version 0.1 deleted from here, see post below for 0.1.2

Please, treat it as a beta, but it should work, given the following constraints:
  • PSG only
  • uncompressed VGM files only
  • up to VGM version 1.50
Also, please note that it requires the Visual Basic Virtual Machine (msvbvm50) to run. Here is the link to the official Microsoft website: http://download.microsoft.com/download/vb50pro/utility/1/win98/en-us/msvbvm50.exe

I'm sorry for the Attachment Fairy, but I'd prefer if the Virtual Machine is not attached to my post for copyright reasons. It's not like that file is going to disappear from the internet anyway; on the contrary, it's all over the place if you Google for it. I do have several backup copies of it in the unlikely event that all the internet goes down at the same time, though.

Once you're all set, just drag and drop a file on the VGM_Reverse.exe icon in your Windows Explorer. If nothing goes wrong, you should receive a second VGM file with the _backwards suffix. If something goes wrong, you'll get some kind of error message. I should add more, but for now this will do.

The source code will arrive someday. I want to proofread it a bit more.
UPDATE: the source code is in the post below; it's still confusing as hell, but I commented it today so you might be able to read it.

Also, I don't get why the backwards version of Chris's song is a bit shorter, but since it's 4am here in Italy and I still don't know why I spent so much time over this, I'll take another look at a later time. All I know is that VGMTools doesn't seem to find any errors, neither in the original file nor in the backwards one. But I'm too tired to investigate this further now. Good night to me.
  View user's profile Send private message Visit poster's website
  • Joined: 16 May 2002
  • Posts: 1116
  • Location: italy
Reply with quote
Post Posted: Fri Mar 02, 2018 11:51 pm
I don't feel loved :(

Either way, here is version 0.1.2 complete with commented source code.

I don't think I'm going to work on this any further.
Vgm Reverse 012 (with source).rar (9.28 KB)
Everything you (didn't) ask for!

  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12477
  • Location: London
Reply with quote
Post Posted: Sat Mar 03, 2018 7:23 am
I love you Tom ❤️

I wish we could get an inline JS player for the VGMs to make it easy to listen.
  View user's profile Send private message Visit poster's website
  • Joined: 31 Mar 2015
  • Posts: 20
  • Location: Carlisle, UK
Reply with quote
Post Posted: Sun Mar 04, 2018 3:24 am
Oh that's wonderful! I love you too ♥ It works just as I had wanted! When I have finished what I am working on I will be sure to send you a copy. The result may give you a chuckle.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!