Jump to content
IGNORED

VGM Compression Tool


Tursi

Recommended Posts

The web interface has a question mark on the A01 file but not on the B01, so I guess it says A01 is not a TI file. But I don't understand why, it comes straight from the Quick Player and it´s saved in TI-format.
Likely you created the file not on the TI
It's easy to fix click on convert to tifiles

Sent from my Pixel 6 Pro using Tapatalk

Link to comment
Share on other sites

1 hour ago, arcadeshopper said:

Likely you created the file not on the TI
It's easy to fix click on convert to tifiles

Sent from my Pixel 6 Pro using Tapatalk
 

Sorry, that didn't help. I will try to use the older version of Quick Player to see if I get the same result. I did the Smurf conversions with the older version and had no problem to load on the TI.

Link to comment
Share on other sites

Again, 01A is corrupt. The second character of the TIFILES tag was overwritten. I thought I mentioned that I had fixed this before...

 

For long term use with emulation, getting used to a hex editor and the general look of headers is helpful. The diagnoses could be a few seconds. ;)

 

image.thumb.png.ab9f9b53241ef8bea9cb25b63913b3d5.png

 

Now the why, I guess that's back on me. Stand by.

 

Edited by Tursi
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

On 4/26/2022 at 1:12 AM, Nick99 said:

@Tursi, I have tried out the latest version of Quick Player so I can use the animations like Chuck in the converted songs. 

Problem is that I can't load the finished files on my TI with E/A.

Are you sure you are running the latest? It should say 20220307 in the title bar. I tested here with a two-file output and it worked fine, plus the same version is reported both at Harmesslion and Github.

 

Converted this with a fresh download:

test2test1

 

Edited by Tursi
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

12 hours ago, Nick99 said:

I must have missed that update, tried to download the zip-file on Github, but get the message "It's not the site you looking for". Is the zip-file to be found elsewhere?

Harmlesslion.com is the primary distribution for all my software (although eventually it will scrape github).

 

http://harmlesslion.com/software/vgm

 

If you are downloading from github directly, the file will always be in the "dist" folder. Looks like you may have tried to use the link in the readme.md. Github keeps changing up the syntax for direct linking...  (Edit: ah, not github's fault this time. I changed the branch name. Nevertheless, meant to remove that link from the readme as part of the update...)

 

 

 

Edited by Tursi
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...
On 8/16/2021 at 2:55 PM, Tursi said:

Well, you're free to compile the tools for Mac. Except for testplayer, I made sure there was nothing Windows specific in any of them.

 

I just compiled the core tools for macos and can confirm they work, but there is one caveat: sscanf_s is a Windows-only concept. Luckily, sscanf_s and sscanf are exactly the same when not used on strings (i.e. no %s used in the format string), so adding a simple #define was enough to get it to compile.

 

So, a big thank you @Tursi for making these cross-platform!

Edited by TheMole
  • Like 2
Link to comment
Share on other sites

Thanks for the note! I did try to avoid the windows-only concepts, but I was probably annoyed that day. ;)

 

I saw your comment about sound effects overriding the music incorrectly. I haven't got a lot of runtime on that code yet, and when I did some Coleco work recently I had some doubts it was correct there. If you spy a clear bug, let me know!

 

Link to comment
Share on other sites

  • 11 months later...

I'm working on some music in Deflemask, and was trying to convert something that uses the noise channel for bass notes. Should sound something like this:

 

However, after converting the .vgm generated by Deflemask with the vgmcomp2 toolchain, the bass notes end up being either super high or super low pitched... I tried scalepitch to fix it, but none of the scaling factors I try have any impact on the majority of notes. Only a few (the highest ones in the dissonant chords near the end of the song) actually change in pitch. I either get an deep thumping noise, or an insanely high pitched tone as can be heard here (recorded via js99er, but sounds the same in mame):

 

None of the tools output any issues or concerns, and I'm not really sure I understand what the file format of the intermediary text files is, so I'm having a hard time "debugging" the song. Here's the command line output:

Import VGM PSG - v20201001
Reading maintheme.vgm - 8541 bytes
Reading version 0x150
Refresh rate 60 Hz (735 samples per tick)
Selecting 16-bit shift register.
File 1 parsed! Processed 1152 ticks (19.200000 seconds)
Adapting user-defined shift rates...0 notes tuned.

-Writing channel 1 as maintheme.vgm_ton00.60hz...
-Writing channel 2 as maintheme.vgm_ton01.60hz...
Skipping channel 3 - no data
-Writing channel 4 as maintheme.vgm_noi02.60hz...
Skipping channel 5 - no data
Skipping channel 6 - no data
Skipping channel 7 - no data
Skipping channel 8 - no data
done vgm_psg2psg.
VGMComp2 PSG Prep Tool - v20201006

Opened tone channel 0: maintheme.vgm_ton00.60hz
Opened tone channel 1: maintheme.vgm_ton01.60hz
Channel 2 (tone) free
Opened noise channel 3: maintheme.vgm_noi02.60hz
Imported 1152 rows
501 custom noises (non-lossy)
0 tones moved   (non-lossy)
0 mutes mapped  (non-lossy)
0 tones clipped (lossy)
0 noises mapped (lossy)
** DONE **
VGMComp2 Compression Tool - v20210901

- Skipping streams 2 and 6 due to no audio
Got 1152 rows... Successful!

1 songs (19.200000 seconds) compressed to 668 bytes (34.792000 bytes/second @ 60hz)

** DONE **

 

And for good measure, here's the .vgm file as created by Deflemask:

maintheme.vgm

 

And the .sbf file that was output by the vgmcomp2 tools:

maintheme.dat

 

Any thoughts?

Edited by TheMole
  • Like 1
Link to comment
Share on other sites

The original VGM converts to an ISR one semitone off for tone 3 managing the pulse channel.  I have fixed it here.  It will sound too low when you play it in a VGM player, but it should convert over for the TI just fine.

 

There is a value in the VGM header which sets the shift of the white noise and pulse generators.  I cannot recall ottomh which way that is, but I remember baking into my conversion scripts.  The TI's PSG is timed differently from the Sega VDP's PSG (and I think pretty much everything derived,) which causes this disparity.

 

 

maintheme_fix.vgm

  • Like 3
Link to comment
Share on other sites

TI's shift generator is 15 bits wide, and the Master System (which most VGMs are for) is 16 bit. I thought my tool adjusted that automatically, reading the header. Your log does detect the 16 bit shift register and it also reports 0 notes tunes. The code definitely autotunes 16 bit to 15 bit - are you sure you're not passing in "-noscalefreq"?

 

That said, you sound way more off than you should be. OLD CS1, you shouldn't be needing custom scripts either, though I vaguely recall there was a reason you did have them.

 

Remember too, you can use testplayer to test every step of the process. With that it seems like the tool converts correctly, and looking at the noise channel I can see it's correctly set for periodic noise.

 

The documentation included covers every file format used in the system, but the independent channels are simple enough. Every row is 1/60th of a second. The first value is the frequency code using the SN timing, and the second value is the volume from 0-100% (in hex, so 0x00 to 0x64). The noise channel has a two special flags in the top word, which are added together: 1 - retrigger noise generator, 2 - use periodic noise instead of white noise

 

The output data definitely doesn't match the input data, which makes me wonder if the prep step is going wrong... these are the commands I used:

 

vgm_psg2psg.exe maintheme.vgm

prepare4SN.exe maintheme.vgm_ton00.60hz maintheme.vgm_ton01.60hz - maintheme.vgm_noi02.60hz maintheme.sn

vgmcomp2 -sn maintheme.sn maintheme.sbf

Steps 1 and 2 result in good output files, but step 3 is giving me the same as you have. Let me see why... I used the toolchain just a couple weeks ago on Super Space Acer and all seemed well.

 

Link to comment
Share on other sites

Ahhh, duh. Yeah, I see it. It's my bug.

 

When vgmcomp2 goes through the data, it noticed that all the volumes on channel 2 are mute, so it discarded that channel entirely (thus the comment about skipping streams 2 (channel 2 tone) and 6 (channel 2 volume)). Without the frequency counts in voice 2, the custom noise is never played. I proved it by editting the .sn file (output from prepare) and changing the first row volume from 0xF (SN mute) to 0xE... could have done similar in the ton02 file.

 

Anyway. I thought I had checked for the custom noise case, but apparently not, so let me see what went wrong there.

 

  • Like 2
Link to comment
Share on other sites

I see. I didn't put autodetection in the compression code. What I did instead was add a 'forcechan' option to force a channel to be included even if it looks unused (rather than bake per-chip intelligence into the packer).

 

So, add "-forcechan 2" to your command line on vgmcomp2.

 

I'm sure I looked at autodetect before and there may be a reason I didn't do it, but for now I will have to leave you there. :)

 

Link to comment
Share on other sites

38 minutes ago, Tursi said:

OLD CS1, you shouldn't be needing custom scripts either, though I vaguely recall there was a reason you did have them.

Because I apparently like to do things the hard way, and I work a lot in ISR sound lists.  It has been a learning experience, as well, dealing with VGMs.  I never fully implemented the compression code -- it just sits dormant.

Link to comment
Share on other sites

4 hours ago, Tursi said:

I proved it by editting the .sn file (output from prepare) and changing the first row volume from 0xF (SN mute) to 0xE... could have done similar in the ton02 file.

This solved it for me, thanks!

 

4 hours ago, Tursi said:

So, add "-forcechan 2" to your command line on vgmcomp2.

This, however, didn't seem to make any difference?

 

One more question, the bass notes sound great now and completely in tune. But in some places, where the noise channel is used to add those extra notes in some of the more dissonant chords, the note sounds a bit out of tune. Is this just an artefact of the lower resolution of the shift generator, i.e. not being able to hit the exact right notes at higher frequencies?

Link to comment
Share on other sites

9 hours ago, TheMole said:

One more question, the bass notes sound great now and completely in tune. But in some places, where the noise channel is used to add those extra notes in some of the more dissonant chords, the note sounds a bit out of tune. Is this just an artefact of the lower resolution of the shift generator, i.e. not being able to hit the exact right notes at higher frequencies?

Comments in my script about changing tone 3 to manage the white or pulse noise channel:

 

"If pseudo-bass (option b) is selected, also increase tone 3 value by 35 semitones, three octaves minus one."

 

What this particular transform does is allow me to use tone 3 as my percussion channel, then convert it to pulse or white noise.  I do not use Deflemask, so I do not know how it handles the interaction between tone 3 and the noise generator.  Manually poking the chip needs the compensation on tone 3 to make the noise in-tune.

  • Like 1
Link to comment
Share on other sites

13 hours ago, TheMole said:

This solved it for me, thanks!

 

This, however, didn't seem to make any difference?

 

One more question, the bass notes sound great now and completely in tune. But in some places, where the noise channel is used to add those extra notes in some of the more dissonant chords, the note sounds a bit out of tune. Is this just an artefact of the lower resolution of the shift generator, i.e. not being able to hit the exact right notes at higher frequencies?

I don't know... I thought I noticed that too, but I was not familiar enough with your original tune.

 

Use the source, Luke, as always. ;) Look at the generated text files - they are just rows of notes after all. Are the frequency counts actually incorrect at some point?

 

Unfortunately seems and sounds is pretty hard to troubleshoot, and I don't have good pitch detection in my head either. I need the numbers. Try to isolate which channel is wrong, and use testplayer to verify each step of the process, see if it changes or if it's always wrong. Testplayer can play the original VGM, the separate channels, the post-prepare file, and the SBF packed file. Let's start by figuring out where it gets detuned. Then we can dig deeper into why. (Edit: it can't do the VGM, only the custom formats.)

 

If it's the original VGM, I can at least examine the hex data to see if it was saved that way. ;)

 

As for -forcechan 2 not working, it worked here. Remember this goes on vgmcomp2. Show me your log including command line. ;)

 

Edited by Tursi
  • Like 1
Link to comment
Share on other sites

3 hours ago, OLD CS1 said:

Comments in my script about changing tone 3 to manage the white or pulse noise channel:

 

"If pseudo-bass (option b) is selected, also increase tone 3 value by 35 semitones, three octaves minus one."

 

What this particular transform does is allow me to use tone 3 as my percussion channel, then convert it to pulse or white noise.  I do not use Deflemask, so I do not know how it handles the interaction between tone 3 and the noise generator.  Manually poking the chip needs the compensation on tone 3 to make the noise in-tune.

Yeah, that's the compensation that vgm_psg2psg does when it converts a VGM file. That's because on the Master System and similar SNs, periodic noise ticks once every 16 cycles, but the TI version ticks once every 15 cycles. So if it starts with a 16-cycle VGM, it multiplies the cycle count by 15/16 to get the same pitch.

 

  • Like 1
Link to comment
Share on other sites

13 hours ago, TheMole said:

One more question, the bass notes sound great now and completely in tune. But in some places, where the noise channel is used to add those extra notes in some of the more dissonant chords, the note sounds a bit out of tune. Is this just an artefact of the lower resolution of the shift generator, i.e. not being able to hit the exact right notes at higher frequencies?

I walked through the sequence again and confirmed forcechan worked (vgmcomp2.exe -sn -forcechan 2 maintheme.sn maintheme.sbf). I listened to every step and to my ears everything from the VGM (played by AudioOverload) through the compressed file sounded the same, so it might very well be the note resolution.

The final SN file is the actual chip data - it's similar to the separate channels except that all restrictions for the target chip (in this case the SN) are now honored - so the frequency count is limited from 0x1 (highest pitch) to 0x3FF (lowest pitch), and the volume ranges from 0x0 (loudest) to 0xF (mute). The custom pitches are in the third note (which you'll see is always muted in this song, since they only affect the noise), and the noise 'pitch' is always 0x3 for periodic noise. You'll still see the occasional '1' flag on the noise channel which tells it to retrigger - that's really important for some noises. But it'll be the third channel you want to try tuning.

 

Knowing that, with some patience, you could edit the file and try testing the theory. For instance, find a note that you can clearly hear is out of pitch, and use a search and replace to change it by 1 tick up (lower pitch) or down (higher pitch), and see what happens.

 

You can also use the scale tool to try and tweak it from the command line - it'll adjust all the frequencies. "scalepitch" will let you apply a multiplier to all the notes of the specified input channel (specify the noise channel before running it through prepare4sn). For instance, "scalepitch 1.01 maintheme.vgm_noi02.60hz" will raise the pitch counter 1% (and so create a 1% lower frequency, subject to whatever rounding). Since you can immediately play the result with testplayer (and the original file is backed up, so just restore it if you don't like the result), you can iterate moderately quickly.

 

  • Like 1
Link to comment
Share on other sites

Oh yeah, the tools are awesome for sure. I am a bit hampered on my side because I haven't gone through the effort of porting the testplayer to SDL or something similar to allow it to run on my Mac, but that's entirely my problem. It does make it harder to 'debug' the process, but by and large everything always works first time for me, so I don't often have the need either. This was actually the first time that I got a result markedly different from what I was expecting, and it coincided with the first time I tried to use Deflemask instead of just ripping the music from another game... :)

 

Link to comment
Share on other sites

Oh, I just figured it out, the command line arguments are location sensitive. The -sn needs to come first or the -forcechan argument isn't picked up...

So, vgmcomp2 -sn -forcechan 2 infile outfile works, vgmcomp2 -forcechan 2 -sn infile outfile doesn't :).

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...