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.

Download

Plugin: download here (right click, save as)
Template: download here

Place the template inside your project’s data folder.

Installation

Download the plugin and place it in the “plugins” folder in your project’s “js” folder. Then open your Plugin Manager (F10), double-click an empty row, and select the EasyAudioLooping plugin.

Once it is in your list of plugins, turn the plugin on.

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:

easyAudioLooping2

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:

easyAudioLooping5

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:

easyAudioLooping3

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.

easyAudioLooping4

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.

You may also like...

26 Responses

  1. Harold says:

    This was pretty cool, I used to use this to change loop points while a song was still playing for musical progression in boss fights. But now it’s outdated and doesn’t work. 🙁

  2. SmeckoGeck says:

    This error keeps showing up every time I load a save file, and the room has some sort of BGM in it:


    Game has encountered a bug. Please fix it.

    TypeError: Cannot read property ‘bgm file name’ of undefined
    at Fame_System.bgmLoopData (HIME_EasyAudioLooping.js:247:29)
    at Function.AudioManager.updateBgmParameters (HIME_EasyAudioLooping.js:306:51)
    at Function.AudioManager.playBgm (rpg_managers.js:1186:22)
    at Game_System.onAfterLoad (rog_objects.js:239:18)
    at Scene_Save.Scene_File.terminate (YEP_SaveCore.js:1246:40)
    at Function.SceneManager.changeScene (rpg_managers.js:1998:25)
    at Function.SceneManager.updateMain (rpg_managers.js:1982:18)
    at Function.SceneManager.update (rpg_managerse.js:1907:14)

    Press F5 to restart the game.

    Is there something wrong with what I’m doing? Because I have no idea what I’m doing wrong or if I’m doing anything wrong.

  3. Ben says:

    Hm… Great Idea with the Plugin, but its dont work on 1.6.2 ?!

    [
    {
    “Profile”: “Battle_Arms”,
    “Name”: “battle_arms_FULL”,
    “Folder”: “bgm”,
    “Unit”: “seconds”,
    “Start Time”: 0,
    “Loop Start”: 10,
    “Loop End”: 72,
    “Loop Length”: 0
    }
    ]

    Plugin Command: load_audio_profile Battle_Arms
    Play the BGM

    Maybe i did something wrong? No Error or Something…

  4. Mascot1063 says:

    So I tested this out with an old game I started a while back, and it worked pretty flawlessly. But then trying to apply it to a new game, the code no longer works.

    Just to put in a little extra information, I am currently using the RMMV Toybox to make the .json files. This has worked for the last project as well.

  5. DmBd says:

    I added a new loop, formatted it correctly (I think), but all of a sudden I start getting this error:

    TypeError: Cannot set property ‘loopStart’ of null

    Here is my .json file:

    [
    {
    “Profile”: “Forest1loop”,
    “Name”: “Forest1”,
    “Folder”: “bgm”,
    “Unit”: “seconds”,
    “Start Time”: 0,
    “Loop Start”: 6.1,
    “Loop End”: 41.686,
    “Loop Length”: 41.686
    },
    {
    “Profile”: “Endloop”,
    “Name”: “end2”,
    “Folder”: “bgm”,
    “Unit”: “seconds”,
    “Start Time”: 0,
    “Loop Start”: 0.5,
    “Loop End”: 32.781,
    “Loop Length”: 32.781
    }
    ]

    I don’t know what I’m doing wrong. Anyone have any ideas?

    • Yes, I do. Maybe you are putting the Plugin Command AFTER the Play BGM? The Plugin Command: load_audio_profile must be always first and then it goes Play BGM, in this case, Forest1 or end2.

      • "Ethan" says:

        I am getting the same error, but I did place the plugin command before the play BGM. It seems to crash the moment the plugin command is executed.
        My setup
        [
        {
        “Profile”: “Battle1_standard”,
        “Name”: “Battle1”,
        “Folder”: “bgm”,
        “Unit”: “samples”,
        “Start Time”: 0,
        “Loop Start”: 63571,
        “Loop End”: “”,
        “Loop Length”: 4482729
        },
        {
        “Profile”: “Battle1_intro1”,
        “Name”: “Battle1”,
        “Folder”: “bgm”,
        “Unit”: “samples”,
        “Start Time”: 4791947,
        “Loop Start”: 125866,
        “Loop End”: “”,
        “Loop Length”: 4856200
        },
        {
        “Profile”: “Battle1_intro2”,
        “Name”: “Battle1”,
        “Folder”: “bgm”,
        “Unit”: “samples”,
        “Start Time”: 5167358,
        “Loop Start”: 623908,
        “Loop End”: “”,
        “Loop Length”: 4731663
        }
        ]
        (Debug console mentioned something about some sort of sourceNode being Null? I’m no programmer so might mean nothing.)

  6. PlayerUnknown says:

    Uncaught ReferenceError: file is not defined
    What does that mean? Where did I go wrong? I’m not good at scripting obviously, but I only just installed it and now it just gives me this crash immediately whenever I run the game.

  7. D13 says:

    Huh. I think I’ll stick with adding looppoints in Audacity to make looping OGGs. Seems more practical for me. But that’s just me.

  8. Ctelin Ajira says:

    This is pretty cool. I’m definitely going to use this.

    At least until RPG Maker MV’s new audio-looping bug gets resolved. Maybe afterward.

  9. Exas says:

    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!

    • Hime says:

      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.

      I believe this should address the problem.

  10. Anon says:

    Jeez you’re a god.

  11. Wavelength says:

    What an amazingly cool idea!!

Leave a Reply

Your email address will not be published. Required fields are marked *