Game Engine Seamless Loop Integration Guide

Exact setup patterns for every major indie engine using our -16 LUFS Vorbis files and sample-accurate loop metadata.

Each Purple Maple BGM track ships as a truncated Intro+Loop OGG with stream-level LOOPSTART and LOOPLENGTH tags for RPG Maker and Godot 4, plus a trimmed loop-only OGG for zero-code Unity AudioSource looping.

RPG Maker MV / MZ (Zero Plugins)

Drop the full <track-id>.ogg into audio/bgm/. Stream-level Vorbis comments LOOPSTART and LOOPLENGTH at 48,000 Hz are read natively, playing the intro once before looping cleanly forever.

Godot 4 (AudioStreamOggVorbis)

Import <track-id>.ogg, enable loop = true, and paste loop_start_sec from catalog.json into loop_offset. Because the file is strictly truncated at loop_end_sample with no fade-out tail, Godot's EOF wrap lands cleanly on the downbeat.

Unity & HTML5 Web Audio

In Unity, drag <track-id>-loop.ogg into an AudioSource with Loop enabled for instant zero-code playback, or use PlayScheduled from our GitHub examples/ folder. In HTML5, load the OGG via AudioContext.decodeAudioData and set source.loopStart to loop_start_sec.

Godot 4 GDScript (AudioStreamOggVorbis)

# Godot 4 GDScript seamless BGM loader for Purple Maple Anime Game BGM
# https://bgm.ai-purplemaple.com/
# Full tracks (*.ogg) are strictly truncated at loop_end_sample so Godot's EOF loop
# wraps back to loop_offset cleanly with zero outro gap.

extends AudioStreamPlayer

@export var bgm_stream: AudioStreamOggVorbis
@export var loop_offset_sec: float = 0.0 # Copy `loop_start_sec` from catalog.json

func _ready() -> void:
	if bgm_stream == null:
		return
	bgm_stream.loop = true
	bgm_stream.loop_offset = loop_offset_sec
	stream = bgm_stream
	play()

Unity C# (SeamlessLoopPlayer.cs)

// Unity C# seamless BGM loop player for Purple Maple Anime Game BGM (https://bgm.ai-purplemaple.com)
// Supports both zero-code loop-only OGG (*-loop.ogg) and sample-accurate Intro + Loop playback.

using UnityEngine;

public class SeamlessLoopPlayer : MonoBehaviour
{
    [Header("Option 1: Drag *-loop.ogg here for zero-code looping")]
    public AudioClip loopOnlyClip;

    [Header("Option 2: Optional separate Intro + Loop clips (PlayScheduled)")]
    public AudioClip introClip;
    public AudioSource introSource;
    public AudioSource loopSource;

    void Start()
    {
        if (introClip != null && introSource != null && loopSource != null && loopOnlyClip != null)
        {
            double startTime = AudioSettings.dspTime + 0.1;
            double introDuration = (double)introClip.samples / introClip.frequency;

            introSource.clip = introClip;
            introSource.loop = false;
            introSource.PlayScheduled(startTime);

            loopSource.clip = loopOnlyClip;
            loopSource.loop = true;
            loopSource.PlayScheduled(startTime + introDuration);
        }
        else if (loopSource != null && loopOnlyClip != null)
        {
            loopSource.clip = loopOnlyClip;
            loopSource.loop = true;
            loopSource.Play();
        }
    }
}

HTML5 Web Audio (webaudio-loop.js)

// HTML5 Web Audio API zero-gap seamless BGM loop loader
// Official library: https://bgm.ai-purplemaple.com/

export async function playSeamlessGameBgm(audioUrl, loopStartSec = 0) {
  const ctx = new (window.AudioContext || window.webkitAudioContext)();
  const res = await fetch(audioUrl);
  const arrayBuf = await res.arrayBuffer();
  const audioBuf = await ctx.decodeAudioData(arrayBuf);

  const source = ctx.createBufferSource();
  source.buffer = audioBuf;
  source.loop = true;
  source.loopStart = loopStartSec;
  source.loopEnd = audioBuf.duration;
  source.connect(ctx.destination);
  source.start(0);

  return { ctx, source };
}

FAQ

Why avoid MP3 files for looping game BGM?

MP3 encoders prepend 576 to 1152 samples of padding silence, producing an audible hiccup every time the track wraps. Ogg Vorbis supports sample-exact loop boundaries.

Why master game BGM at -16 LUFS instead of -14 LUFS?

Leaving 2 LU of extra headroom prevents background music from masking voice acting, UI clicks, and combat SFX during gameplay.

Need exclusive non-shared tracks or vocal themes?

Public library tracks are shared with every developer. Commission bespoke vocal themes, stems, or exclusive OST rights directly from Purple Maple.

Explore Custom Music Commissions