Crossfading file formats

Post anything about MX Simulator here. Please. I'm begging you.
jlv
Site Admin
Posts: 14931
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Crossfading file formats

Post by jlv »

IF YOU DON'T KNOW WHAT YOU'RE DOING, PLEASE DO NOT DOWNLOAD THIS! IT WILL PREVENT FUTURE SOUND UPDATES FROM WORKING FOR YOU!
First off, here are the new sound samples in a regular zip file: http://mxsimulator.com/junk/sndsrc-2011-07-23.zip

The three new file types are:

.sw
This is just a raw 16 bit mono sound file. (16 bit signed little endian)

.soundtable
This defines the table of patches used to generate the engine sound.
The header has this format:

Code: Select all

SOUNDTABLE rpm_count torque_count
rpm1
rpm2
rpm3
... (repeated up to rpm_count)
torque1
torque2
... (repeated up to torque_count)
rpm_count is the number of RPM steps and torque_count is the number of torque steps.
rpm1 rpm2 etc and torque1 torque2 etc are the RPM and torque levels where the upcoming patches will be played. The torques aren't actual torques. For the torque values, 0 represents negative torque/engine braking, and 1 represents loaded. The negative torque and loaded torque values can be set in the .braap file with the lowtorque and hightorque settings.

After that, the patches are defined in rpm order. E.g. first torque1 .. torqueN for rpm1, then torque1 .. torqueN for rpm2 etc.

Each patch definition looks like this:

Code: Select all

-1 pulse_count patch_filename
patch_filename is a raw 16 bit sound file. pulse_count is how many power strokes are in the sample.

Here's a complete example. This defines 3 RPM levels and 2 torque levels.
"idleoff.sw" would be played at 1000 RPM during negative torque loads.
"idleon.sw" would be played at 1000 RPM during positive torque loads.
"midoff.sw" would be played at 3000 RPM during negative torque loads.
"midon.sw" would be played at 3000 RPM during positive torque loads.
"highoff.sw" would be played at 9000 RPM during negative torque loads.
"highon.sw" would be played at 9000 RPM during positive torque loads.

Code: Select all

SOUNDTABLE 3 2
1000
3000
9000
0.25
0.75
-1 1 @simplesound/idleoff.sw
-1 1 @simplesound/idleon.sw
-1 1 @simplesound/midoff.sw
-1 1 @simplesound/midon.sw
-1 1 @simplesound/highoff.sw
-1 1 @simplesound/highon.sw
.braap
This is the same as the old .pipeinfo files except there are some new options -
minrpm which sets the minimum RPM the sound will be played at. E.g. minrpm 1500
lowtorque which sets the negative torque value. E.g. lowtorque -4.0
hightorque which sets the loaded torque value. E.g. hightorque 4.0
soundtable which sets the sound table. E.g. soundtable my125.soundtable

What? Not complicated enough?
In addition to that, you can add a table that remaps the cycle count before a multi cycle patch definition. This can help make sounds be less repetitive without using huge files.

Normally, the game will decide which cycle to play by taking the engine's cycle count modulo the number of cycles in the patch. If the patch has a cycle remapping table, it will use the table to decide the cycle count. Here's an example.

Say you have a patch with two cycles in it, and the second one has a pop from a backfire in it. With a standard patch definition like this:

Code: Select all

-1 2 @popper.sw
It will play the cycles like this (using zero based indexing to keep things simple): 0 1 0 1 0 1 0 1 0 1 ...
Giving you a backfire every other cycle.

If you add an 8 entry remap table like this:

Code: Select all

0 0 0 0 0 0 0 1
-1 2 @popper.sw
It will play in this order instead: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 ...

If you do this, make sure there's a zero crossing at the cycle you cut at. You'll get ugly pops otherwise.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Crossfading file formats

Post by DJ99X »

Interesting... thanks!

I'll have to give this a go in a couple of weekends.

I'll have to record my brothers postie though :lol: It'll be easy to put some load on it, I'll just get him to do burnouts in the backyard :lol:
jlv
Site Admin
Posts: 14931
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Crossfading file formats

Post by jlv »

BTW, if you're having trouble converting the .sw files, SoX can do it -

sox -c 1 -r 88200 mysound.sw mysound.wav

-c sets the channels and -r sets the sample rate. (I use a very high rate in these samples but 44100 will probably work OK too.)

To convert back just reverse the parameters:

sox mysound.wav -c 1 -r 88200 mysound.sw

There's a copy of SoX in here: http://mxsimulator.com/scripts/mjpeg4mxsim.zip

Audacity can do it too. Just choose Import/Raw Data. You might find that a few bat scripts and SoX will make things easier with so many files though.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Crossfading file formats

Post by DJ99X »

jlv wrote:You might find that a few bat scripts and SoX will make things easier with so many files though.
Seeing as you have to make the sound loopable, you might as well export it from Audacity
jlv
Site Admin
Posts: 14931
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Crossfading file formats

Post by jlv »

I guess so. I find it easier to use SoX in a script than to import/export 50 files through a GUI when I want to adjust volume/bass/whatever. But I'm a typical lazy programmer. :D
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
staydown
Posts: 558
Joined: Mon Feb 02, 2009 7:53 pm
Team: Building Tracks Only
Location: Lehigh Valley, Pa

Re: Crossfading file formats

Post by staydown »

Can't wait for some new recordings. I do like the sounds that are included in the snapshot, but they do have a muffled sound which people have stated already. It actually sounds somewhat like you are wearing a helmet. Maybe you could do some kind of code to change the bike sounds when you switch from first person to chase cam and use the current sounds for first person mode. Just an simple yet realistic idea.
Baboobeats
Posts: 405
Joined: Mon Jul 25, 2011 12:08 am
Team: MXSP

Re: Crossfading file formats

Post by Baboobeats »

too complicated for my small brain. i wish there was one or more wav files i could play with, not convert here and there to that and greek to him and those. if my idea was possible i would release a mutch better 2 stroker sounds. And yes dj it sounds Baboobeaaaaattssbaboobaboobaboobaboooo
Jonee589
Posts: 290
Joined: Fri Dec 10, 2010 3:22 am

Re: Crossfading file formats

Post by Jonee589 »

so there is no way to open the .sw file in audacity?
jlv wrote:lol. I'm such a noob!
Phathry25
Posts: 7481
Joined: Sat Dec 01, 2007 1:09 am
Team: No Frills Racing
Location: WI
Contact:

Re: Crossfading file formats

Post by Phathry25 »

jlv wrote:Audacity can do it too. Just choose Import/Raw Data. You might find that a few bat scripts and SoX will make things easier with so many files though.
:roll:
Jonee589
Posts: 290
Joined: Fri Dec 10, 2010 3:22 am

Re: Crossfading file formats

Post by Jonee589 »

Phathry25 wrote:
jlv wrote:Audacity can do it too. Just choose Import/Raw Data. You might find that a few bat scripts and SoX will make things easier with so many files though.
:roll:
god, i am such a goon
jlv wrote:lol. I'm such a noob!
Jonee589
Posts: 290
Joined: Fri Dec 10, 2010 3:22 am

Re: Crossfading file formats

Post by Jonee589 »

How can I export a .sw file from Audacity?
jlv wrote:lol. I'm such a noob!
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Crossfading file formats

Post by DJ99X »

File>Export File

Choose "Other uncompressed files" as the file type, then choose Options, and select

Header: RAW
Encoding: 16 bit signed PCM
Jonee589
Posts: 290
Joined: Fri Dec 10, 2010 3:22 am

Re: Crossfading file formats

Post by Jonee589 »

DJ99X wrote:File>Export File

Choose "Other uncompressed files" as the file type, then choose Options, and select

Header: RAW
Encoding: 16 bit signed PCM
Just worked it out before, thanks.

What do the A B C after the Rev Level mean? Is it just one sound clip per rev, split into 3?
jlv wrote:lol. I'm such a noob!
Jonee589
Posts: 290
Joined: Fri Dec 10, 2010 3:22 am

Re: Crossfading file formats

Post by Jonee589 »

Also JLV, would you be willing to share your 250t and 450f samples?
jlv wrote:lol. I'm such a noob!
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Crossfading file formats

Post by DJ99X »

3 different torque values. You could think of it as 3 different throttle positions, where 0 is closed, 1 is wide open
Post Reply