Adding sound to track (asking)

All about making tracks for MX Simulator
Post Reply
mxrewind665
Posts: 2600
Joined: Sat Feb 12, 2011 4:12 pm
Team: FlowTech
Location: New England USA
Contact:

Adding sound to track (asking)

Post by mxrewind665 »

I’m working on a detailed project. I’ve been out of the community for a couple years and have returned. I played the new RF MXGP tracks and to my surprise there were horns, fans screaming ect all around the track. I would love to add this element to my coming project but I have no clue where to start or have any open source material to reference.

So my question is, how do you do it? Or is there a track with a open folder I could peek into to learn it and see how it was done?

Thank you.
Image
jlv
Site Admin
Posts: 14912
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Adding sound to track (asking)

Post by jlv »

Here's an example:
https://mxsimulator.com/tracks/jstest2.zip

The sound stuff starts at line 814 in "frills.js".

The javascript interface is described here.
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.
mxrewind665
Posts: 2600
Joined: Sat Feb 12, 2011 4:12 pm
Team: FlowTech
Location: New England USA
Contact:

Re: Adding sound to track (asking)

Post by mxrewind665 »

jlv wrote: Sun Dec 26, 2021 2:59 am Here's an example:
https://mxsimulator.com/tracks/jstest2.zip

The sound stuff starts at line 814 in "frills.js".

The javascript interface is described here.
Thank you. My JS knowledge is 0. However I was able to create a 1:48 .sw file using Awave Audio. When it came to actually getting that file to read in game I have no understanding of any of it. Do I have to attach the sound to an object/billboard or can I have it just play in game constantly?
Image
jlv
Site Admin
Posts: 14912
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Adding sound to track (asking)

Post by jlv »

If you just want it to play continuously this should do it:

Code: Select all

var g_mysound = mx.add_sound("@mytrack/mysound.sw")
mx.set_sound_freq(g_mysound, 22050);
mx.set_sound_vol(g_mysound, 1.0);
mx.set_sound_pos(g_mysound, 512, 0, 512);
mx.set_sound_loop(g_mysound, 1);
mx.start_sound(g_mysound);
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.
Jakob Hubbard
Posts: 1148
Joined: Fri Nov 24, 2017 3:16 am
Team: Phil's
Location: Cold
Contact:

Re: Adding sound to track (asking)

Post by Jakob Hubbard »

mxrewind665 wrote: Sun Dec 26, 2021 10:53 pm Thank you. My JS knowledge is 0. However I was able to create a 1:48 .sw file using Awave Audio. When it came to actually getting that file to read in game I have no understanding of any of it. Do I have to attach the sound to an object/billboard or can I have it just play in game constantly?
If you ever want to learn how to use the javascript interface like triggering a sound from a hook message me on discord and I'd be happy to help.

Jakob Hubbard#3334
Image
mxrewind665
Posts: 2600
Joined: Sat Feb 12, 2011 4:12 pm
Team: FlowTech
Location: New England USA
Contact:

Re: Adding sound to track (asking)

Post by mxrewind665 »

jlv wrote: Mon Dec 27, 2021 12:51 am If you just want it to play continuously this should do it
That helped me eliminate the fact it was the .sw file. I found one that works but it is too short and loops a car horn too often to not be annoying :lol: is there a limit to the length of time the audio can be? But this did help and I got something so thank you a ton.
Jakob Hubbard wrote: Mon Dec 27, 2021 1:25 pmIf you ever want to learn how to use the javascript interface like triggering a sound from a hook message me on discord and I'd be happy to help.

Jakob Hubbard#3334
I’ll be getting in touch with you for sure. Much appreciated.
Image
jlv
Site Admin
Posts: 14912
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Adding sound to track (asking)

Post by jlv »

mxrewind665 wrote: Mon Dec 27, 2021 4:55 pm That helped me eliminate the fact it was the .sw file. I found one that works but it is too short and loops a car horn too often to not be annoying :lol: is there a limit to the length of time the audio can be? But this did help and I got something so thank you a ton.
Not sure if there's a DirectSound limit but in any case it's not really meant for super long sounds.

Here's a completely untested script to repeat a sound at an interval.

Code: Select all

var g_mysound = mx.add_sound("@mytrack/mysound.sw")
mx.set_sound_freq(g_mysound, 22050);
mx.set_sound_vol(g_mysound, 1.0);
mx.set_sound_pos(g_mysound, 512, 0, 512);
mx.set_sound_loop(g_mysound, 0);

var g_mysound_last_played = 0;

function play_mysound(seconds) {
	var repeat_time = 1; /* set this to the interval it should repeat at in seconds */

        g_play_mysound_prev(seconds);

	if (Math.floor(seconds / repeat_time) == Math.floor(g_mysound_last_played / repeat_time))
		return;

	mx.start_sound(g_mysound);

	g_mysound_last_played = seconds;
}

var g_play_mysound_prev = mx.frame_handler;
mx.frame_handler = play_mysound;
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.
mxrewind665
Posts: 2600
Joined: Sat Feb 12, 2011 4:12 pm
Team: FlowTech
Location: New England USA
Contact:

Re: Adding sound to track (asking)

Post by mxrewind665 »

jlv wrote: Tue Dec 28, 2021 2:32 am Not sure if there's a DirectSound limit but in any case it's not really meant for super long sounds.

Here's a completely untested script to repeat a sound at an interval.
I got that to work perfect. It does help. I was also able to use the sproing.sw as a test to add multiple sounds at different time intervals and that worked. I’m just trying now to create another sound file that will work like this current one I made. Thank you again for that.
Image
baker
Posts: 283
Joined: Sat Jul 30, 2011 1:43 pm

Re: Adding sound to track (asking)

Post by baker »

jlv wrote: Tue Dec 28, 2021 2:32 am
mxrewind665 wrote: Mon Dec 27, 2021 4:55 pm That helped me eliminate the fact it was the .sw file. I found one that works but it is too short and loops a car horn too often to not be annoying :lol: is there a limit to the length of time the audio can be? But this did help and I got something so thank you a ton.
Not sure if there's a DirectSound limit but in any case it's not really meant for super long sounds.

Here's a completely untested script to repeat a sound at an interval.

Code: Select all

var g_mysound = mx.add_sound("@mytrack/mysound.sw")
mx.set_sound_freq(g_mysound, 22050);
mx.set_sound_vol(g_mysound, 1.0);
mx.set_sound_pos(g_mysound, 512, 0, 512);
mx.set_sound_loop(g_mysound, 0);

var g_mysound_last_played = 0;

function play_mysound(seconds) {
	var repeat_time = 1; /* set this to the interval it should repeat at in seconds */

        g_play_mysound_prev(seconds);

	if (Math.floor(seconds / repeat_time) == Math.floor(g_mysound_last_played / repeat_time))
		return;

	mx.start_sound(g_mysound);

	g_mysound_last_played = seconds;
}

var g_play_mysound_prev = mx.frame_handler;
mx.frame_handler = play_mysound;
Any suggestions on how to convert to sw or find sw files? I’m not so familiar with that file format. Is that all that is supported, or are mp3s or wav files supported?
Wahlamt
Posts: 7934
Joined: Mon Sep 13, 2010 3:15 pm
Team: MLG Compton
Location: Sweden
Contact:

Re: Adding sound to track (asking)

Post by Wahlamt »

baker wrote: Thu Dec 30, 2021 2:14 am
Any suggestions on how to convert to sw or find sw files? I’m not so familiar with that file format. Is that all that is supported, or are mp3s or wav files supported?
Here you got some info, also some more info in JLV's first comment: viewtopic.php?t=9820
baker
Posts: 283
Joined: Sat Jul 30, 2011 1:43 pm

Re: Adding sound to track (asking)

Post by baker »

Wahlamt wrote: Thu Dec 30, 2021 7:03 am
baker wrote: Thu Dec 30, 2021 2:14 am
Any suggestions on how to convert to sw or find sw files? I’m not so familiar with that file format. Is that all that is supported, or are mp3s or wav files supported?
Here you got some info, also some more info in JLV's first comment: viewtopic.php?t=9820
Thank you sir 🙂
jlv
Site Admin
Posts: 14912
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Adding sound to track (asking)

Post by jlv »

baker wrote: Thu Dec 30, 2021 2:14 am Any suggestions on how to convert to sw or find sw files? I’m not so familiar with that file format. Is that all that is supported, or are mp3s or wav files supported?
It's just raw 16 bit samples. In Audacity, from the menu choose File / Export / Export Audio, then set "Header" to "RAW (headerless)" and set "Encoding" to "Signed 16-bit PCM".
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.
Post Reply