Loop a sound from the middle

Page updated :

What tools do I need?

To play the loop in the middle of the sound, we'll use the following two tools.

  • Wavosaur
  • Xact

Download and install Wavosaur

Wavosaur is a tool for editing waveform data in audio files. You can download Wavosaur from:

When you open the page, download the file from the red border link in the picture. There are 32bit and 64bit versions, so use the one that was in your operating environment.

Wavosaur のダウンロード

Wavosaur can run on a single EXE, so you don't need to install it. Expand to any folder.

Download and install XACT

XACT is a tool that fine-tunes the game sounds of Windows and Xbox so that they can be played during the game.

XACT is not distributed by itself and is included with the XNA Game Studio and DirectX SDK. This time, i'll use the one that comes with XNA Game Studio. You can download XNA Game Studio from the following links:

After downloading, run the installer and install it. XNA Game Studio is officially only supported until Windows 7, but we have confirmed that it will also be installed in a Windows 10 environment.

Create a WAVE file with loop points in Wavosaur

Prepare the sound file you want to loop back in advance. The basics are edited in wave files, but the basic voice data can also be read from MP3 files and other sources. (The audio file used in this sample is borrowed from the "Pockle's Earth (k15.mp3)" file from the"H/MIX GALLERY"site.)


Run wavosaur to start it.

Wavosaur を実行

The screen appears.

Wavosaur のウィンドウ

Drag and drop the prepared audio file into Wavosaur. The waveform data is displayed.


You can select a range by dragging the waveform data with the mouse. Select the range you want to loop through.


Select Tools → Loop → Create loop points from the menu. It is the same when you press the "L" button on the toolbar.

「Create loop points」を選択

"loop start" and "loop end" are displayed on both sides of the selection. This is the range to which it is looped.

「loop start」「loop end」が表示される

Save your voice data by selecting "File" → "Save" from the menu.


The file is basically a WAVE file. Save it to any folder. If you want to edit it again, you can drop this WAVE file into Wavosaur to edit it prematurely.


You have saved the file. XACT uses this WAVE file. If you edit based on an MP3 file, you will no longer use the MP3 file.


Create the files needed to play monogame sounds in XACT

From the Start menu, select Microsoft XNA Game Studio 4.0 Refresh → Microsoft Cross-Platform Audio Creation Tool 3 (XACT3) to start. If you have installed it from the DirectX SDK, please start it from there.

Microsoft Cross-Platform Audio Creation Tool 3 (XACT3)

It becomes the screen immediately after it starts. XACT only does the easiest thing to do, so if you want to know how to use it elsewhere, check out the Web. Even if you use a WAVE file with loop playback settings in the middle, XACT does not require any special action.

XACT 起動画面

The first step is to create the project. Click the Creates a new project button on the toolbar.


Where is the project stored?


Once you have created the project, right-click Wave Backs and select New Wave Bank.

New Wave Bank

Once you've verified that Wave Bank has been created, right-click Sound Banks and select New Sound Bank.

New Sound Bank

The screen is shown in the picture.

Wave Bank と Sound Bank 作成後

Drag and drop the WAVE file you just created into the Wave Bank window.

WAVE ファイルを「Wave Bank」のウィンドウにドラッグ&ドロップ

Then drag and drop the data added to wave bank into the upper-left area of the Sound Bank.

Sound Bank の左上のエリアにドラッグ&ドロップ

Then drag and drop the data added to the Sound area into the cue area in the lower left.

Cue のエリアにドラッグ&ドロップ

Select the Sound file and verify that Looping in the lower left property is checked for Infinite.


When you're done, click the Build button on the toolbar to build it.


The window appears, but you can press the Finish button to complete it.


Make sure that the Win folder is created in the folder where you saved the project, and that three files have been created in it.


Create a game project

All you have to do is register the file and program it in your MonoGame project. I'm writing it in Windows Project. We've confirmed that it works with Windows Store apps and Windows Mobile.

Windows Project

After you create the project, you will register the three files that you just created in XACT in the Content folder. It doesn't have to be a special Content folder.

Content フォルダに3つのファイルを追加

Open the property with the three files you added selected.


Change from Copy to Output Directory to Copy if new.


Windows Universal App Project (UAP) is not available in the above settings. Instead, change the Build Action to Content.


The rest will be the program only. It's basically the same program as sound playback using XACT.

Add Microsoft.Xna.Framework.Audio to your namespace.

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

Add the following three lines: AudioEngine, SoundBank, and WaveBank in the fields:

GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

AudioEngine audioEngine;
SoundBank soundBank;
WaveBank waveBank;

We have created instances of AudioEngine, SoundBank, and WaveBank in the LoadContent method. Each corresponds to three files added to the Content folder, so specify it as a relative path from the folder at the project root.

We're going to get cue supright here, but in the actual game you should play it where you need it.

protected override void LoadContent()
  // Create a new SpriteBatch, which can be used to draw textures.
  spriteBatch = new SpriteBatch(GraphicsDevice);

  // TODO: use this.Content to load your game content here
  audioEngine = new AudioEngine(@"Content/LoopSample.xgs");
  soundBank = new SoundBank(audioEngine, "Content/Sound Bank.xsb");
  waveBank = new WaveBank(audioEngine, "Content/Wave Bank.xwb");


Run in this state and make sure the loop is playing from the middle. The actual loop control is completed in the WAVE file and XACT stages, so you don't need to make any special settings in the program.

About compressing audio files

XACT provides the ability to compress audio files to reduce file size. XNA Game Studio was able to play compressed files, but monogame does not support them, so you may get an exception or play unintended audio when playing. Only uncompressed WAVE files can be used in real terms. As you can see, the file size is considerably larger.

If you really want to reduce the file size, you need to adjust the sampling rate of the WAVE file, for example.

Support for iPhone, Android, Linux and OUYA

XACT is a tool for Windows and Xbox, so it's not clear if it works on other platforms. If necessary, ask them if they want to try it out and adopt it.