Finding Trim Points in WAV Files

From vgmrips

To know where to trim if vgmlpfnd and vgm2txt aren't enough, you will need to make a WAV file from a VGM and open it in a program that can display what the music waveform looks like.

Creating .wavs from VGMs

Note: Converting will be very resource-intensive and will probably slow down your computer for a while (depending of the size of the VGMs), and the resulting WAV file(s) will be very large, but you will soon get rid of them. Alternatively, you may convert the files to .flac.

Any music player that can play VGMs and create .wav files can do the trick. We will explore using

  1. ZXTune
  2. Winamp + the VGM input plugin, in_vgm
  3. XMPlay + in_vgm
  4. VGMPlay

Below are some pointers for experienced loggers; you can skip them and go on to your player of choice.

Using in_vgm has an advantage: you can stop the output for each VGM whenever you think you have enough of it converted, such as when you only need help finding the Start Sample. If it's possible in VGMPlay without mangling the file (or having to skip forward with Right Arrow), I don't know how.

At last report years ago, using Foobar's foo_gep seemed to strip silence you need to trim properly. I'm not sure if this is still the case.

You'll sometimes want to make WAVs of your trimmed VGMs, too: to compare them to the raw logs, and make sure your timing is correct. At those times, you might want to use vgm_trim with 0 for the Start Sample so you don't have to line up the waveforms by hand.

Note: (By the way, some differences with a waveform on a loop mean you made a mistake, but others are just an artifact of trimming and can't be prevented no matter what you do. Perfectionism kills! Sometimes you just have to say good enough is good enough.)

Using ZXTune

  1. Drag your VGM into the playlist/program
  2. Right-click on it
  3. Select Convert
  4. Under "Select directory", click the "..." button to choose a folder to put your WAVs in
  5. Under "Specify filename template", make sure it says [Filename]
  6. Make sure the word under these settings says "WAV" (or "FLAC" for smaller files, especially if you change the Compression to Max/8)
  7. Click OK

You can convert many VGMs at once. Drag all of them into the playlist, press Ctrl+A to select them all, then right-click and do the same steps as needed.

The files created should already have a frequency of 44100 Hz. If they do not, go to File > Preferences > Sound and change the Sound frequency, then make new WAV/FLAC files.

Using Winamp, the VGM input plugin and the Disk Writer output plugin

  1. Run Winamp
  2. Press CTRL+P to open the preference screen
  3. Go to the "output" section
    1. Remember or write down the currently-selected output plugin
    2. Select the "Nullsoft Disk Writer plug-in"
      • (if you don't have it, download the full version of Winamp, which has it bundled)
    3. Click on the configure button below the list
      1. Set the output directory, or make "Output to directory containing source files" checked
      2. Select the proper output format: PCM, 16 Bit, Stereo, 44.100 kHz
      3. Make sure the option "kill null samples" is disabled/unchecked. The .wav won't give you correct times if any samples are removed
  4. Now go to the input section to configure the VGM input plugin (in_vgm)
    1. Set "pause after non-looped tracks" to zero
  5. If shuffle, repeat, the equalizer or any DSP plugin are activated, turn them off. They won't do you any good here.
  6. Drop the file(s) into Winamp and play them. (No music will play, because the audio is being written to your hard drive instead)
  7. When Winamp is done writing the files, press CTRL+P again and turn the output plugin back to what was it before you changed it to the disk writer. This way you can listen to files again.

Using XMPlay and in_vgm

  1. Go into Options and Stuff (press F9, menu-click on XMPlay, or click the wrench icon)
  2. Go to Input
  3. Configure the VGM input plugin (in_vgm)
    1. Make sure Playback Rate is 44100 Hz
    2. Set "pause after non-looped tracks" to zero
    3. (Optional) Set Play Loops to 2, so WAVs of trimmed files can be compared to raw logs easily
  4. Go to Output
    1. Remember or write down the currently-selected output Device
    2. Change the Device to "WAV Writer"
    3. Under "File writing", do one of these:
      • Click the Source checkbox to make XMPlay put WAVs in the same folder as the source VGMs
      • Choose a specific Folder to place all the WAVs in
    4. (Optional) Check Auto filename, so the program doesn't ask for one every time
    5. (Optional) Go to Miscellaneous and uncheck "Auto-loop any track ending with sound"
  5. Open the VGMs in XMPlay: They'll automatically be written to WAVs.
  6. When all WAVs have been written, go back into the Output Options and change the Output Device back to what it was before you changed it to WAV Writer.

Using VGMPlay

From the Command Line

VGMPlay -w your_vgm_here.vgm

Via settings

Open VGMPlay.ini in a plain-text editor like Notepad. Find (ctrl+f) and change the following settings as so. (You can also specify them with VGMs on the command line:)

[General]
SampleRate = 44100
JinglePause = 0
FadeRAWLogs = False
Volume = 1.0
LogSound = 1

You can now drop your logs on VGMPlay.exe and wait for output to finish.

Note: It's also possible to place these options in a new VGMPlay.ini file that you put inside the folder of VGMs you're working on. VGMPlay will automatically use these, and you can just move/delete the file when you don't need it.

The above settings can also be specified on the command line; see VGMPlay's wiki page for details.

Other Players?

Check the readme or options to see if they describe how to convert files.

Sound Editors

Audacity
or an Audacity fork like Tenacity, Audacium, or AudioCity. (Info below correct as of 2.0.6... yeah.)
GoldWave (shareware)
(Correct as of ~v5)
ocenaudio
(Correct info here as of... 2.0.16. Oy. Used much more RAM than Audacity.)
Wavosaur
Portable and lightweight; only requires <6mb disk space and uses even less RAM than Audacity... at least until you open a .wav file.
MIDI files
Using vgm2mid, it's possible to find loops as well, though I don't know the process to do so.

Any other program like these, which lets you view exact samples (see below) in WAVs/FLACs, is fine too. (This tutorial will use GoldWave for its example images of waveforms.)

Whatever you choose, if you're not used to the program, open any sound file in it and try to do the Everyday Tasks below until you know the interface. Then I'll show you how to find the trim /points/sample numbers you need for vgm_trim.

Everyday Tasks

Many sound editors can mark loop points as you work, via menu options. In Audacity(/ies), I don't know any quick way to do so, except to:

  • use Edit -> Region Save/Restore to keep your selection/cursor
  • use label tracks on a selection or cursor and move the labels as needed

Viewing in Samples

When viewing a WAV file, you're trying to find the exact start, loop begin (if applicable), and loop/song end points. These numbers should be in samples, not seconds.

In the converting instructions above, the number 44100 appeared. VGM stores data at a resolution of 44100 samples per second (hence, 44.1Hz); that's why it was important that the WAV/FLAC files used this sample rate/frequency too. If your sound editor says the files have that number, you're good to go.

But the default time numbers shown in these programs are in seconds, minutes and so on. To change to sample mode in:

Audacities

At the bottom, you'll see a drop-down list (newer versions), or boxes saying Selection Start, End/Length, and Audio Position (older versions). There are arrows by the numbers below/nearby. Click any of those (or right-click on the numbers themselves), and select "samples".

Note: If you don't see any of that stuff, Use View -> Toolbars and make sure Selection Toolbar is checked.

GoldWave

There is a status bar at the bottom of the screen giving you a number in the format "__ to __ (__ unit)". Right click on it and select the option that says "__ to __ (__ smp)" (it should be the second to last option). The bar will now give you numbers like "selection-start to selection-end (selection-size smp)".

ocenaudio

Use View -> Display Time Format -> Samples.

Getting the sample numbers for vgm_trim isn't simple. You have two options:

  1. Hold Alt and move the cursor to make the exact sample number beneath it appear at the bottom. Move the cursor over the trim point you want to find. This is imprecise and best combined with vgm2txt.
  2. Click to place the cursor before a marker or region (see below). Use Controls -> Move Cursor -> Next Marker; the exact sample will display in the black window at the top. A region counts as a single marker; to see the end sample you must use Edit -> Select Audio from Regions, and the end sample will display. This is precise but a bit of a pain.

Wavosaur

Use Options -> Sample Display -> Samples. The currently-selected range will always be visible next to the track's sample rate (which should of course read 44100 Hz). If there's no selection, the numbers will be the same.


Now the program is giving you what you need: the position of the selection markers in samples. Once you've done this once, you shouldn't need to do it again.

Zooming In/Out on Time and Amplitude

Zooming normally (that is, time-wise/horizontally) is pretty easy, most of the time complete with magnifying-glass icons. But the less-simple amplitude/vertical zoom is something you'll definitely want to know how to do.

Why's that? Some sounds actually start long before you can actually see them at the default amplitude scale (that's how tall the waveforms look). You can make bigger the sound wave on the vertical axis with the sound editor, and see where the VGM('s sound) actually starts. We'll see an example later on, when we learn trim point finding.

Audacity

Right Click and Left Click on the amplitude scale to the left of the waveforms. You can also fit the horizontal selection to the window by pressing CTRL+E.

GoldWave

Press CTRL+UP and CTRL+DOWN. Fit the selection by pressing SHIFT+S.

ocenaudio

There's a magnifying glass in the upper-right corner, next to the waveform. This is used for horizontal and vertical zooming, but doing so is not simple either way.

Without a selection, the glass has a + inside: Click/hold it, and it will zoom in toward the music cursor. With a selection, it has nothing inside: Clicking/holding it will zoom so that the selection fills the window. Hold Ctrl when you click to make the + appear and scroll normally.

Either way, hold Shift to make - appear and zoom out.

To zoom in on amplitude, you must hold the Alt key. Hold Shift at the same time to zoom out.

You can also use View -> Zoom for all these things, and to fit to the selection.

At this point, you no doubt want to know how to scroll left and right while zoomed in. If you hover the cursor over the samples at the bottom, it will change to indicate you can drag. Click and drag left/right to scroll.

Wavosaur

Next to the normal Zoom buttons, you'll find amplitude zoom buttons. Apply as needed.

Finding "Zero Crossings"

Zero Crossings are points at the start and end of a loop that are silent (0.0db), which should make for good and safer loop/end points. You can make the program find these for you.

Audacities
Simply press the Z key.
GoldWave
Use Edit -> Marker -> Snap to zero crossing.
ocenaudio
Use Adjust Selection -> Snap to Zero Cross. This can be found in the Edit menu, or by menu-clicking on your selection.
Wavosaur
Use Options -> Snap to zero crossing. This is a toggled option rather than one you activate by pressing, so you'll have to make new selections to use it.

Moving Your Loop Section Around Without Losing the Loop Length

Optional, but extremely handy and worth getting used to.

Audacities (~2.0.6)

  1. There are two radio buttons after the start point that say End and Length. Push Length.
  2. Click into or otherwise access Selection Start, so that you can enter numbers there.
  3. Change the start point as you need by typing.
  4. When finished and ready to try the new endpoint in vgm_trim, change the radio button back to End.

GoldWave

???

ocenaudio

  1. Use Edit -> Create Region to create a region from your selection.
  2. Move the cursor over one of the red region endpoints (at the top) until the cursor becomes a hand with all five fingers extended.
  3. Click and drag; the entire region should move. Place it where you want.
  4. If necessary, you can adjust the endpoints now by clicking on them when the hand has only the pointer/index/first finger extended.
  5. Use Edit -> Select Audio from Regions to regain a selection, so that you can play it and re-check the loop.

There is a feature to convert a region into a loop, but it doesn't appear to be helpful for our needs.

Wavosaur

You'll have to turn a selection of the possible loop into an, uh, Loop (Tools -> Loop -> Create Loop Points). Then open Properties (in the same menu) and change each loop sample by the amount of/to the pair of samples you need.


Finding Trim Points in the WAVs

Trimming VGMs shows the three types of songs, and shows examples of the kind of points you're trying to find. If you've never searched for trim points before, you can practice on the VGMs provided there. (You should also read the whole tutorial for further insight and info, if you haven't already.)

You want to find two to three points:

  • The time where the song starts (Start Sample)
  • Where it finishes (End Sample)
  • Where it jumps to when it finishes, to loop (Loop Sample, which can be 0 to indicate "No Loop" in case of non-looping songs)

For looping songs without an intro, Start Sample and Loop Sample may be the same number.


Now that you know what you're looking for, play the WAV file on your sound editor and find where the song starts. Select the part of the sound around this spot and zoom to fit the view. Zooming in lets you get more precise values. Keep zooming until you get a nice, close look at the sound wave.

This is the start of the Ghouls 'n Ghosts song, as mentioned in Trimming VGMs, in a close zoom. You can take a good look at the sound wave at this scale, but it's not abusively close either.

As you probably noticed, the Start Sample (yellow) is set a few samples away from the first noticeable changes in the wave. This is important because we don't want to trim out the starting commands at the beginning of the music, so we always give a bit of a space. Here's a hint: any space or gap below 500 samples is not noticed by the human ear at all. The above space is only 50 samples, which is less than 2 milliseconds in length!

Note: If the leading silence of a VGM log is only made of Wait commands, it's safe to go right up to the end of the Wait and beginning of the music. You can't tell if that's the case with just WAVs, though. vgm2txt can not only show you this, but help you confirm all the trim points you find. If you combine these two methods, you're really playing with power!

It's also worth zooming in on the amplitude scale as I mentioned earlier:

This is the last sound wave we saw, with expanded amplitude. The tiny bump you noticed before is now a big obvious hump pointing down. Doing this is a good way to find silence gaps in songs, which make good and safer edit points. As mentioned, you can also make your sound editor "snap" to these zero-crossings for you.

Once you've placed the selection marker at the appropriate position, get the number for it (depending on how you selected and how your sound editor shows you this information) and write it down as the Start Sample. Discard the commas, if any are present. Do the same thing with the End and Loop Samples.

Listen carefully to the sound at these points and see if they're correct. If they are, it's time to use vgm_trim to do the actual trimming. Then you'll have to listen to the trimmed file to check if the file "agrees" that your trims are good.

You may need to repeat the finding process a few times to get good-sounding trim points, so don't be discouraged if your first tries sound funkotronic when actually trimmed. Even veterans can struggle with this. If you're having difficulty finding the right samples, or want more tools in your toolkit, try vgm2txt and vgmlpfnd.

Another method of finding loops which may make it easier can be found in the Manual looping tutorial.

Keep in mind that, as long as it sounds right and it doesn't have excessive information, the trimming is good.