Welcome, Guest. Please login or register.

What openbor you prefer: Double dragon,battletoads or final fight !? by lirexpatrio
[December 07, 2012, 07:15:27 pm]


what are your favorite games OpenBOR?! by lirexpatrio
[December 07, 2012, 07:09:46 pm]


Post Some Awesome Videos by maxman
[December 07, 2012, 05:51:39 pm]


Can @cmd playmusic "aaaa" 1 also increse music sound ? by BeasTie
[December 07, 2012, 05:24:38 pm]


Streets of Rage: Silent Storm by mtrain
[December 07, 2012, 03:45:05 pm]


Site will be down for maintenance on 12/8/2012 thru 12/10/2012 by Damon Caskey
[December 07, 2012, 07:42:42 am]


Cancelled SOR 3d Remake by riccochet
[December 07, 2012, 03:58:33 am]


Dungeon Fighter: B.O.R. by msmalik681
[December 07, 2012, 03:24:27 am]


[TUTORIAL] How to create 4 Games of OpenBOR in 1 CD (650 MB) by magggas
[December 06, 2012, 09:46:25 pm]


custknife by Bloodbane
[December 06, 2012, 09:34:09 pm]


blockfx help by B.Kardi
[December 06, 2012, 04:09:14 pm]


street of age 4 hd by corradlo
[December 06, 2012, 01:41:36 pm]


ClaFan - Classic Fantasy ver 1.17 by soniczxblade
[December 06, 2012, 05:01:20 am]


Bug Archive by Bloodbane
[December 06, 2012, 02:00:44 am]


"Bio-Doom" and "Gears of Doom" by BulletBob
[December 05, 2012, 10:07:21 pm]


Contra Locked 'N' Loaded v2 by Bloodbane
[December 05, 2012, 09:39:43 pm]


Downloadable OpenBoR Manual by BeasTie
[December 05, 2012, 08:31:24 pm]


Having trouble testing changes by B.Kardi
[December 05, 2012, 03:05:53 pm]


DragonBall Absalon by msmalik681
[December 05, 2012, 02:52:13 pm]


[Hi-Res] Swamp by Vibrant
[December 05, 2012, 10:47:14 am]


  • Dot Guests: 178
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.



Author Topic: Quick Intro/Loop tutorial  (Read 2472 times)

0 Members and 1 Guest are viewing this topic.

Offline CE

  • Hero Member
  • *****
  • Posts: 1102
  • Working on Rage of the Streets v2
    • DCEvolution.net
Quick Intro/Loop tutorial
« on: December 06, 2008, 02:21:53 pm »
Here's a quick "How To" on using kbandressen's new Intro/loop feature:



Quote from: kbandressen
music data/path/file.bor {offset}

Offset is a position in bytes that the music will return to when it loops; for example if you had a 128000 byte bor file, setting offset to 64000 would put it almost exactly halfway through the song (there is a 160 byte header in the bor file).



[The formula is:]

(File Size in bytes - 160) * (Time to loop back to / Total song length)

So if your intro is 10.21 seconds long, the song is 1:41.32, and the file size is 2354543 bytes:

(2354543 - 160) * (10.21/101.32) = 237250


To apply this to one of my tracks, I opened my WAV file in my audio editor. I am currently using Soundforge. A great alternative would be Audacity which is free software, released under the GNU General Public License, and available for Windows, GNU/Linux, BSD and Mac: http://audacity.sourceforge.net/

I cut my file down so the main part loops like it should and checked where the intro ends. In my file that's exactly after 4.019 seconds. The entire file is 76.419 seconds long (1m and 16,419s).


Position of where the intro ends / Total song length:
4.019 / 76.419 = 0,052591632970858032688205812690561


I saved the WAV without header, or loop marks, etc. Then I converted it to .bor using convert.exe (or wav2bor.exe). The resulting file is 1.685.220 bytes big.


File Size in bytes - .bor file header (160 bytes):
1685220 - 160 = 1685060


Final calculation of the offset:
1685060 *  0,052591632970858032688205812690561 = 88620,057053874036561588086732357


Important is the number before the comma (88620). I copied it from calc.exe into memory with CRTL+C, and pasted it in 'mylevel.txt':


#music    data/path/file.bor {offset}
music      data/music/bar.bor 88620


...and the loop starts exactly at 4:019 seconds  :)
« Last Edit: December 07, 2008, 12:27:46 pm by CE »
http://dcemulation.org/index.php5?title=OpenBORManual


How to mod:
1 Pick an interesting game: There are plenty of 8-bit/16-bit classics waiting for a remake
2 Rip your own sprites & stages
3 Use a custom palette: http://borrevolution.vg-network.com/tutorial.htm
4 Check your offsets: http://lavalit.com:8080/index.php?topic=1099.0


Did you know?
Using void main()
{
playgif("data/my.gif", 0, -4, 1);
}

as spawnscript streams a GIF anim instead of loading it

Offline kbandressen

  • Developer
  • Hero Member
  • *****
  • Posts: 1347
Re: Quick Intro/Loop tutorial
« Reply #1 on: December 06, 2008, 05:43:25 pm »
Also note that you don't need the decimal point.  The engine will just round it off if you specify it.

Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Quick Intro/Loop tutorial
« Reply #2 on: December 07, 2008, 11:10:43 am »
 Thanks for the tutorial CE!  :cheers!:

Also note that you don't need the decimal point.  The engine will just round it off if you specify it.

 Ah, I've thought so.
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

Offline CE

  • Hero Member
  • *****
  • Posts: 1102
  • Working on Rage of the Streets v2
    • DCEvolution.net
Re: Quick Intro/Loop tutorial
« Reply #3 on: December 07, 2008, 12:30:41 pm »
Also note that you don't need the decimal point.  The engine will just round it off if you specify it.

 Ah, I've thought so.


Fixed. - I wasn't 100% sure if it would have made a difference, as in my test I tried to be as accurate as possible to see if I could get it to do what I wanted and was pleasantly surprised that it looped as perfectly as it did, so I didn't do any further tests.
http://dcemulation.org/index.php5?title=OpenBORManual


How to mod:
1 Pick an interesting game: There are plenty of 8-bit/16-bit classics waiting for a remake
2 Rip your own sprites & stages
3 Use a custom palette: http://borrevolution.vg-network.com/tutorial.htm
4 Check your offsets: http://lavalit.com:8080/index.php?topic=1099.0


Did you know?
Using void main()
{
playgif("data/my.gif", 0, -4, 1);
}

as spawnscript streams a GIF anim instead of loading it

Offline Edgeworth

  • Jr. Member
  • **
  • Posts: 3
Re: Quick Intro/Loop tutorial
« Reply #4 on: March 13, 2009, 07:35:31 pm »
a small refininement of the above method:

1. in your audio editor, switch the timescale view to Samples.
2. load wav, find loop points. make sure all audio is trimmed after the loop-end.
3. look at the loop-start value. voil?, your offset.
 
*click for pic*

e.g.,
Quote
Sample rate (Hz): 44100
Channels: 2

F = BOR file size (bytes): 4290950
h = BOR header size (bytes): 160
Ns = Loop start (samples): 668709
Nt = Total length (samples): 4290790

offset = (F - h) * (Ns / Nt)
= (4290950 - 160) * (668709 / 4290790)
= 668709
= Ns = Loop start (samples)
so if Total length = file size - header, it's fair to deduce that (for stereo) BOR ADPCM encoding allocates 1 byte per sample, which simplifies things greatly.
« Last Edit: March 14, 2009, 10:53:01 am by Edgeworth »

Offline Plombo

  • Hero Member
  • *****
  • Posts: 1724
  • Your source for useful modding tools!
Re: Quick Intro/Loop tutorial
« Reply #5 on: April 11, 2010, 08:06:38 pm »
a small refininement of the above method:

1. in your audio editor, switch the timescale view to Samples.
2. load wav, find loop points. make sure all audio is trimmed after the loop-end.
3. look at the loop-start value. voil?, your offset.
 
*click for pic*

e.g.,
Quote
Sample rate (Hz): 44100
Channels: 2

F = BOR file size (bytes): 4290950
h = BOR header size (bytes): 160
Ns = Loop start (samples): 668709
Nt = Total length (samples): 4290790

offset = (F - h) * (Ns / Nt)
= (4290950 - 160) * (668709 / 4290790)
= 668709
= Ns = Loop start (samples)
so if Total length = file size - header, it's fair to deduce that (for stereo) BOR ADPCM encoding allocates 1 byte per sample, which simplifies things greatly.

Not quite.  That number has to be divided by two because BOR ADPCM allocates 1 byte per 2 samples for mono (1-channel) sound.  So the loop offset in the above example would be 334353 if the song is mono, 668709 if it is stereo.
« Last Edit: April 21, 2010, 12:06:22 am by Plombo »

Offline Edgeworth

  • Jr. Member
  • **
  • Posts: 3
Re: Quick Intro/Loop tutorial
« Reply #6 on: April 21, 2010, 12:33:10 am »
a small refininement of the above method:

1. in your audio editor, switch the timescale view to Samples.
2. load wav, find loop points. make sure all audio is trimmed after the loop-end.
3. look at the loop-start value. voil?, your offset.
 
*click for pic*

e.g.,
Quote
Sample rate (Hz): 44100
Channels: 2

F = BOR file size (bytes): 4290950
h = BOR header size (bytes): 160
Ns = Loop start (samples): 668709
Nt = Total length (samples): 4290790

offset = (F - h) * (Ns / Nt)
= (4290950 - 160) * (668709 / 4290790)
= 668709
= Ns = Loop start (samples)
so if Total length = file size - header, it's fair to deduce that (for stereo) BOR ADPCM encoding allocates 1 byte per sample, which simplifies things greatly.

Not quite.  That number has to be divided by two because BOR ADPCM allocates 1 byte per 2 samples.  So the loop offset in the above example would be 334353, not 668709.

Thanks for the correction. The example should have read that loop point = offset if the sample rate is 22050Hz, not 44100Hz.

Offline Plombo

  • Hero Member
  • *****
  • Posts: 1724
  • Your source for useful modding tools!
Re: Quick Intro/Loop tutorial
« Reply #7 on: April 21, 2010, 05:53:40 pm »
Actually...the sample rate (the number of samples played every second) doesn't affect how samples are stored.  It only affects how fast they are played back.

Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Quick Intro/Loop tutorial
« Reply #8 on: April 22, 2010, 01:26:10 pm »
 Have you guys tried it? I have problem with setting this and even posted it in bugs section. Now after I think it over, maybe I didn't set it right.
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

Offline Edgeworth

  • Jr. Member
  • **
  • Posts: 3
Re: Quick Intro/Loop tutorial
« Reply #9 on: April 22, 2010, 11:57:05 pm »
Actually...the sample rate (the number of samples played every second) doesn't affect how samples are stored.  It only affects how fast they are played back.
Well yes, but a .wav with a sample rate of 22050Hz would have half the number of samples of a .wav of same length and bit-depth with a sample rate of 44100Hz. The former would be played back at half the rate of the latter.

What I should have said was that regardless of the actual source .wav's sample rate, the offset appears to be relative to 22050Hz. Basically:

Offset = Loop start * (22050 / Sample rate)

Since you've implemented ogg vorbis support (very useful, thanks :) ) we can now assume a sample rate of 44100Hz. Simplified:

Offset = Loop start / 2

which corresponds to your observation.

Bloodbane, I have tested for 11025, 22050 and 44100Hz, and can supply the test files if you need them. I couldn't figure out why only 22050Hz looped properly until now.

 



 0%




mighty
SimplePortal 2.3.3 © 2008-2010, SimplePortal