Easy Audio Looping

Ever downloaded a great sound track that you wanted to use in the game, but then you found out it just plays from start to finish, and starts playing again from the beginning?

However, if you listen to some of the BGM’s that come with RPG Maker, such as the battle themes, you’ll notice that they have the intro part, but then it will just keep playing forever.

This is accomplished through a concept called “looping”. Basically, let’s say you had a 60 second song, and you wanted the part between 15 and 45 seconds to keep playing. You would specify that at the 15 second mark, you would like to start looping, and at the 45 second mark, you would end looping.

Now, your audio file starts playing from the beginning of the song. Once it reaches the 15 second mark, it will notice that it’s entered a loop. It will continue to play until the 45 second mark, where it notices that it’s at the end of the loop. Now it goes back to the beginning of the loop, and starts playing the song at 15 seconds again.

Normally, this information is set in the music files themselves. However, with this plugin, you can use a simple spreadsheet to maintain audio loops for all of your music files!

This also means you can create different kinds of loops for the same music file if you wanted to, without distributing multiple copies of the same file.

Usage

I recommend downloading the template file that I provided above if you haven’t already done so. Place it inside your project’s Data folder.

Creating Audio Profiles

This plugin uses something called “audio profiles”, which is a set of configuration options for a particular music file.

Open the template that you downloaded in a text editor like notepad or a spreadsheet program like Excel, and you will see some sample data that I’ve provided. You will set up your audio looping in this file. Here is how it looks:

Here is an explanation of what the headers are

1: Profile – the name of this audio profile. Used in events.
2: Name – the name of the music file.
3: Folder – which folder the music file is in. Usually bgm
4: Unit – how time is calculated, either in “seconds” or in “samples”.
5: Start Time – at what time the music should start playing.
6: Loop Start – at what time the music’s loop starts
7: Loop End – at what time the music’s loop ends
8: Loop Length – how long the loop lasts from the loop start

The “Profile” is just a name that you choose for this profile. It can be anything you want, but preferably something easy to remember.

The “Name” is the name of the song that this profile applies to. For example, if you want to work with “Battle1” bgm, you would just write “Battle1” here.

The “Folder” just tells the game where it can find your sound file. For the “Unit”, both “seconds” and “samples” are supported. If you are comfortable with samples, then you can use those since those are more precise. Otherwise, you’ll probably be working with seconds.

All music by default starts at 0 seconds. However, if you wanted it to start at a different position, like maybe 20 seconds into the song, you can just write 20. If you wanted to start in between a second, for
example, at 20.5 seconds, you can just write 20.5 if needed. You can choose any number that you wish.

The Loop Start and Loop End are used to determine where the song will loop. If you want the song to loop between 5 seconds and 10 seconds forever, you would just write 5 for the Loop Start and 10 for the
Loop End.

Loop Duration is optional: some people prefer working with Loop Start and Loop Duration, whereas others prefer to use Loop Start and Loop End.

Converting your Audio Profiles

The plugin doesn’t support spreadsheet formats. Instead, it uses something called JSON.

Converting your spreadsheet into JSON is easy. Here is a method you can use:

1. Go to this website: http://www.csvjson.com/csv2json
2. Copy all of your data (including headers) into the left box
3. Press Convert
4. Open notepad
5. Copy everything in the right box into notepad
6. Save the file as “audioProfiles.json” and place it in Data folder.

Here is how the final JSON data will look:

And now you’re done! You can edit the JSON data directly at this point if you wanted to.

Using Your Audio Profiles

Now you want to test your audio profiles in the game.

For example, if you wanted to test the Battle1_short audio profile that I provided, which does some strange loop on Battle1 BGM, you would start by creating a plugin command and write

load_audio_profile Battle1_short

This will load the audio profile. The next time you play Battle1, the audio profile settings will be applied, and you should hear it looping strangely after a few seconds.

Note that the audio profile will not be applied until you stop the music and play it again.

If you would like to remove an audio profile because you are done with it, you would use the plugin command

remove_audio_profile Battle1_short

This will delete the audio profile so that the next time you play Battle1 BGM, it will be back to normal.

Thank you so much Hime! And again, you did great!
I figured out that the bgm starts at the beginning (might be the Start Position from the JSON file) after an enemy ecounter occured.
Is it possible that the bgm memorizes its exact position when an enemy encounters occurs, and after battle it continues at that spot? I think the basic bgm config from RPG Maker MV does this by default. Did I miss something or could you let some magic happen? 🙂
Thanks in advance!

Thanks for the report. I’ve updated the plugin. Just replace your copy with the new one.

If the requested music start time is before the specified offset in the profile, the game will use the custom offset.
If the start time is AFTER the offset, then we assume it is continuing from where it left off previously.

To create code blocks or other preformatted text, indent by four spaces:

This will be displayed in a monospaced font. The first four
spaces will be stripped off, but all other whitespace
will be preserved.
Markdown is turned off in code blocks:
[This is not a link](http://example.com)