- - GBA Music Looping
(https://www.pokecommunity.com/showthread.php?t=118722)
clonex25
December 7th, 2007 9:49 PM
GBA Music Looping
4 Attachment(s)
WARNING:
The following steps may or may not affect the performance of your operating system. These may include DLL-related errors.
USE IT AT YOUR OWN RISK (But dont tell me I didn't warn you).
- Before anything else, convert your custom MIDI to a GBA S file through the MIDI2GBA tool. After conversion, just open the text editor (you may choose WordPad or NotePad), Click File>Open, choose "All Documents" in "Files of Type" option, and select the S File.
REMINDERS: Associating S files with the text editor may affect the performance of Sappy especially in its assembling feature. You may get a permanent kernel32 error upon assembly.
Let's familiarize ourselves with the code (The items necessary for the looping procedure will be boldfaced):
- To make the loop, you must first find the end of the track, and it usually ends with:
Code:
.byte FINE
-Place the following code before the “.byte FINE” code line:
Code:
.byte GOTO @ ----> Unconditional jump Ref. Sappy’s Help file
.word <name of loop label/pointer> @ ----> loop label name
.byte W06
REMINDERS: Although an option to place in the code, the purpose of the ".byte W06" after the GOTO and label statement is to give the GBA processor and memory enough time to go at the specified label's position, avoiding crashes at runtime. Adding an additional measure name before the “.byte FINE” code line is also optional, but recommended to avoid confusion. Besides the “@” sign signifies commenting in the S file. I also recommend using a label name which is similar to what is already in there (e.g. frlgmbattlb_1, newbark_2...).
The end of track must look like this:
Code:
.byte GOTO
.word frlgmbattlb_1_loop
.byte W06
.byte FINE
-and place the exact same label name (in this case, frlgmbattlb_1_loop) followed by a colon (:) in the place or measure you want to consider as the start of the loop. If a measure has a pattern statement (begins with a pattern label, format: <filename>_<track number>_<measure number>, and ends with .byte PEND), place the loop label before the pattern label.
-----------
Now, if you think looping a single-tracked S file is easy, think of looping a multi-tracked S file a bit complicated. Because unlike looping a single-tracked file, looping a multi-tracked file requires that you must loop EACH AND EVERY TRACK inside it. It means that if you looped one track doesn’t mean that the others will loop as well. What makes it more complicated is that not all tracks end with the same number and the same W<xx> values (contrary to what I’ve posted previously). To know more about it, click the file tes.zip in the Attachments part of the thread (thanks to megiddo for the code). Once you’ve extracted it, open the file “tes.txt”. Upon thorough examination of the file, you will notice that some tracks end with “@ 042” measure while others end with “@ 050”. Also, some of the tracks don’t have W<xx> values that equal to 96, the “whole rest” value for a 4/4 metered file (to be explained later on).
In this kind of situation, we must adjust the other tracks to align with the track which has the highest amount of length (in this case the longest track has a measure of @ 050 and has W<xx> values equal to 96).
Let's say this code above (taken from Track 2 of tes.txt) is your track’s last measure. To make this track equal to the longest track in the file, we will add the following code lines:
But we’re not done yet. It may look aligned to the longest track for now, but let’s go back to measure @ 042. If you add the W<xx> values, it would be: 24+24+24+23=95. We must also remember that the measure’s meter is 4/4, which has a W<xx> value of 96. Ignoring this fact may cause crashing at runtime (which we don’t want to happen). To make the W<xx> bytecodes equal to 96, simply change the value of the last W<xx> bytecode to a value that would make them equal to 96. In this code, we will change “.byte W23” to “.byte W24”. You will have a code that looks like:
After that, you may start looping the file. Always remember upon looping a multi-tracked S file, you must loop each and every track of the file. Open “tes_r.txt” to see the results.
WHAT’S IN THE W<xx>?
-----------
You may ask “You keep mentioning about this W<xx> and the 4/4 meter stuff, but what exactly is it?”
Actually, here’s the definition for the W<xx> from Sappy 2006’s help file:
Wxx (0x80++)
Wait for the specified number of clock ticks
The value of W<xx> varies on its use, and it adds up to a total of:
96 – for 4/4 metered measure (4 beats per measure/beat value of 4)
72 – for 3/4 metered measure, and
48 – for 3/4 metered measure
In a W96 measure:
96 – whole (note if .byte W96 has N<xx> line before it/rest if none)
48 – half
24 – quarter
12 – half quarter
- Save the file when you're done. The next step is to insert it in Sappy. Follow the help file or Search the Forum for instructions.
NOTES:
You may preview the S file using Sappy. Just be warned that it may close the program upon playing the file on the first run. Preview using GBA emulator for safety.
If you are about to use a multi-track S file, you may want to shorten the length of your MIDI to a single repetition for easier loop coding.
Always check everything about the loop statement (the spelling, location, etc.) to avoid crashes or erroneous loops at runtime. Do so by pressing Ctrl+F, typing the loop label name, and cilck Find Next.
You must also refer to the "Event List" of your MIDI software to know where to loop in your S file (e.g. knowing the measure number, the formula is (MIDI measure number)-1).
About knowing where to (start and end a) loop, always ask yourself: “Which part of this song do I want to hear over and over again?” and “Which particular measure number does the looping start?” Simple questions that need tough answers, but you’ll be able to push through when you do.
Always backup your files.
EXAMPLES:
I have included some reference files and examples below. Use them as guides for music looping.
GOOD LUCK IN YOUR GBA MUSIC LOOPING!!!
Dan13x
December 8th, 2007 2:24 PM
I don't get it but it could be useful!
clonex25
December 8th, 2007 5:45 PM
Quote:
Originally Posted by dan123410
(Post 3153644)
I don't get it but it could be useful!
I'm sorry for that. IMO, it is the simplest explanation I can give. Even I had a hard time figuring this out.
Chiaki Shinichi
December 8th, 2007 6:11 PM
Nice work there clonex25!!!
I knew about the:
.byte GOTO
.word "song"
but not the:
.byte W06
So the song didn't loop properly, anyways its nice to know how to loop songs!
Νιτραμ
December 9th, 2007 12:07 AM
And where exactly you put the W96 byte? And did I understand correctly that it fills space to make all tracks have same length? How many should be used? I am sorry, this is completely new area of hacking for me (Not really, as I can already successfully transfer music from game to game and put in custom MIDI without looping). I made up a MIDI for one project and it has around 7 or 8 tracks, can you tell me more specifically how to put it into the game without some problems with looping e.g. one track starts looping before another?
And I know this isn't related to this tutorial, but how do I change instruments of the song by hex (in game)? Can you answer me either here or via PM?
clonex25
December 10th, 2007 4:05 AM
Quote:
Originally Posted by Martin²
(Post 3155333)
And where exactly you put the W96 byte? And did I understand correctly that it fills space to make all tracks have same length? How many should be used? I am sorry, this is completely new area of hacking for me (Not really, as I can already successfully transfer music from game to game and put in custom MIDI without looping). I made up a MIDI for one project and it has around 7 or 8 tracks, can you tell me more specifically how to put it into the game without some problems with looping e.g. one track starts looping before another?
And I know this isn't related to this tutorial, but how do I change instruments of the song by hex (in game)? Can you answer me either here or via PM?
Actually, the MIDI2GBA tool automatically fills up empty spaces (such as measures) with a W96 (or any W [wait] value needed to make each measure having a 96 total W value). By the way, the W thing here is a delay command in the S file programming (similar to delay() in C/C++ and Sleep in Visual Basic, <sigh> too technical, isn't it?). As I have said in my additional notes, you must aslo refer to your MIDI software. If you can see loop markers in the MIDI, then it's the right place to insert the loop label (beginning of the loop) and the GOTO statement (before the end of track). To fully understand the looping thing, try clicking the attachments above. Those may serve as guide in GBA looping.
As for the instrumentation by hex, I doubt I can help you. I just made a song test MIDI (playing notes in different patches), inserted it in GBA, and listened carefully at each patch. I think there is "Export samples" in Sappy. Hope it can help you. :)
Tré
April 11th, 2008 6:26 AM
hey
thanks bud.... this can help me looping musics
Platinum Lucario
May 2nd, 2008 9:58 AM
I've had some problems assembling songs, you see when I insert
the music not all of the instruments are inserted... :(
will you please help me, clonex25?
clonex25
May 7th, 2008 3:15 AM
Quote:
Originally Posted by PokémonShinySilver
(Post 3549408)
I've had some problems assembling songs, you see when I insert
the music not all of the instruments are inserted... :(
will you please help me, clonex25?
Could that be:
1. Your instruments doesn't sound the way you expect it? Or
2. You've placed too many instruments after all.
I'll forward a message if you have problems regarding the instruments. ;)
destinedjagold
May 21st, 2008 6:53 AM
hey... I got a question, but before that, I noticed this in your first post...
Quote:
newbark_1_010:
from that, is it the last track in new bark song?
if so, then does that mean we can only add music which is only up to 10?
other than that, it's a great tutorial. :)
Master_Track
May 21st, 2008 7:19 AM
i'm sry to ask this, but can anyone loop the following song for me?
I tryed but failed, maybe it would help me to understand O.o
should loop from track 2 I think.
if nobody can do it I'll just try again and again..
i see... you haven't looped all the tracks in the S file.
if you're looping a multi-track file, you must loop all the tracks in it. Meaning the first track has its own loop command, and so as the 2nd, the 3rd, up to the nth track. Download any of the attachments above to learn more of multi-track looping.
destinedjagold
May 21st, 2008 9:09 PM
I got to admit, this is an awesome tutorial. :)
I can loop D/P Music now, but I can't lower their volumes. :P
Oh well.., I need to make further experiments.
Thankies for this tutorial...
But, I got a question... :\
Everytime I loop D/P Music and insert them in the ROM, it works, but if I loop non-pokemon music, it won't work in neither Sappy nor VBA... :\
@DJG: Try to download Anvil Studio.
I did it because I searched for programs which loop automatically (I was even able to loop a song, but only one instrument and that sounded odd..so I make it manually now ^^)
However, I was able to change the volume of my sound easily, and u can choose which instrument should have which volume.
E: didn't work :'(
what did I do wrong?
I think I just don't understand WHERE to put the songname_1_loop:
a few notes are played, maybe a second long, and then the game freezes.
I know I inserted it right O.o
It only looks like spaces would be wrong in the whole thing, in the original file they're okay. It's because of copying.
clonex25
May 22nd, 2008 7:42 PM
Quote:
Originally Posted by Master_Track
(Post 3599900)
thx, I'll try it out now ^^
@DJG: Try to download Anvil Studio.
I did it because I searched for programs which loop automatically (I was even able to loop a song, but only one instrument and that sounded odd..so I make it manually now ^^)
However, I was able to change the volume of my sound easily, and u can choose which instrument should have which volume.
E: didn't work :'(
what did I do wrong?
I think I just don't understand WHERE to put the songname_1_loop:
a few notes are played, maybe a second long, and then the game freezes.
I know I inserted it right O.o
It only looks like spaces would be wrong in the whole thing, in the original file they're okay. It's because of copying.
Code:
@ 000 ---------------------------------------- zalda2_2_loop: --- This is where things went wrong...
.byte VOICE , 71
.byte VOL , 95*zelda2_mvl/mxv
.byte PAN , c_v-1
.byte N48 , Dn3 , v060
Always check the spelling of your labels before inserting it in Sappy. Also, i recommend to place the labels AFTER the track's major info. Like this:
One more question: Do you expect that the looping starts at @001 (Measure 2 in MIDI)? If yes, then you should place the loop in it and place it BEFORE the pattern labels for example:
@DJG: I've checked your code and I found no problems regarding the loop placements. Can you PM me for a link to the files you want to insert so that I may know the problem (actually, zel has encountered no porblem for Cyrus' Battle theme, which is from D/P and some Final Fantasy music, for Carlos' battle theme).
Master_Track
May 23rd, 2008 12:42 AM
wow thx, I think I understand it now :)
try it out today.
And now I'll check the spelling 2 times xD
clonex25
May 23rd, 2008 7:11 PM
Quote:
Originally Posted by destinedjagold
(Post 3598053)
hey... I got a question, but before that, I noticed this in your first post...
from that, is it the last track in new bark song?
if so, then does that mean we can only add music which is only up to 10?
other than that, it's a great tutorial. :)
No, the one you showed me (newbark_1_010:) is a pattern label. You may use any number of tracks as you want (just like in Zoids Legacy, which has 12 tracks) butI recommend to limit it to 10 tracks, as the Pokemon ROMs suggest.
destinedjagold
May 23rd, 2008 8:35 PM
hm.., I see, so ten tracks, ei, so I guess it's the safest. :3
also, yeah, I'll PM you the link. thankies in advance...
Magnius
May 29th, 2008 8:25 AM
I think I've pretty much given up on successfully looping. Just too hard a concept for me to grasp. I mean it's like, how do you know what measure it is? How do you know where to loop? Too complicated. When the thing started crashing I pretty much said screw it because looping doesn't make sense to me(Could've sworn I put a loop in like 3 different places on a track and it still looped the same thing, I mean what sense does that make?).
Master_Track
May 29th, 2008 11:17 AM
I tryed loopin quite often now, and again instead of looping, the game freezes when the sound ends and the last note keeps on playing...
I'm really sure I looped it right, I did it exactly like in ur examples O.o
but well, then I'll have to try again..and again..and again, untill it works.
clonex25
May 30th, 2008 2:18 AM
Quote:
Originally Posted by Magnius
(Post 3623063)
I think I've pretty much given up on successfully looping. Just too hard a concept for me to grasp. I mean it's like, how do you know what measure it is? How do you know where to loop? Too complicated. When the thing started crashing I pretty much said screw it because looping doesn't make sense to me(Could've sworn I put a loop in like 3 different places on a track and it still looped the same thing, I mean what sense does that make?).
I know, it's hard to know exactly where to loop. But to make things simple, know the parts which you want to hear over and over again. Then, place a marker (in the MIDI) to mark the parts you want to loop. Open the S file and find the measure number of the loop start (mark it Start/Begin in the MIDI) and subtract it by 1. For example, the measure is at 10, you must find @009 in the S file and place the loop label.
Hardy Har Har
May 31st, 2008 1:41 AM
confused
hi, can this work only on the first track?
destinedjagold
May 31st, 2008 6:49 AM
nope...
you can put those to all tracks...
or at least, that's what I know... :\
Magnius
May 31st, 2008 7:11 AM
Quote:
Originally Posted by clonex25
(Post 3625339)
I know, it's hard to know exactly where to loop. But to make things simple, know the parts which you want to hear over and over again. Then, place a marker (in the MIDI) to mark the parts you want to loop. Open the S file and find the measure number of the loop start (mark it Start/Begin in the MIDI) and subtract it by 1. For example, the measure is at 10, you must find @009 in the S file and place the loop label.
I think it might even be giving me the wrong track numbers in the s file though. For instance I found something like "Fs, G, A" which is exactly the notes the song plays where I want to loop, but then I put the loop before that and nothing happens.
clonex25
May 31st, 2008 10:11 PM
Quote:
Originally Posted by psyduck007
(Post 3628381)
hi, can this work only on the first track?
it may work for all tracks, provided that each track has its own loop (i will be updating the thread for the multi-track looping, for i still can't get the time due to my job demands).