Adding sound to track (asking)
-
- Posts: 2600
- Joined: Sat Feb 12, 2011 4:12 pm
- Team: FlowTech
- Location: New England USA
- Contact:
Adding sound to track (asking)
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.
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.
Re: Adding sound to track (asking)
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.
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.
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
-
- Posts: 2600
- Joined: Sat Feb 12, 2011 4:12 pm
- Team: FlowTech
- Location: New England USA
- Contact:
Re: Adding sound to track (asking)
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?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.
Re: Adding sound to track (asking)
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.
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
-
- Posts: 1161
- Joined: Fri Nov 24, 2017 3:16 am
- Team: Phil's
- Location: Cold
- Contact:
Re: Adding sound to track (asking)
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.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?
Jakob Hubbard#3334
-
- Posts: 2600
- Joined: Sat Feb 12, 2011 4:12 pm
- Team: FlowTech
- Location: New England USA
- Contact:
Re: Adding sound to track (asking)
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 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.
I’ll be getting in touch with you for sure. Much appreciated.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
Re: Adding sound to track (asking)
Not sure if there's a DirectSound limit but in any case it's not really meant for super long sounds.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.
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.
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
-
- Posts: 2600
- Joined: Sat Feb 12, 2011 4:12 pm
- Team: FlowTech
- Location: New England USA
- Contact:
Re: Adding sound to track (asking)
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.
Re: Adding sound to track (asking)
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?jlv wrote: ↑Tue Dec 28, 2021 2:32 amNot sure if there's a DirectSound limit but in any case it's not really meant for super long sounds.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 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.
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;
Re: Adding sound to track (asking)
Here you got some info, also some more info in JLV's first comment: viewtopic.php?t=9820
Discord: StorkeN#6883 - StorkenMXS Youtube - StorkenMXS Instagram - StorkenMXS Facebook - TMFR on Faceboook
Re: Adding sound to track (asking)
Thank you sirWahlamt wrote: ↑Thu Dec 30, 2021 7:03 amHere you got some info, also some more info in JLV's first comment: viewtopic.php?t=9820
Re: Adding sound to track (asking)
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.
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.