Page 3 of 5
Re: Sound effects
Posted: Sat Dec 05, 2015 3:18 pm
by Fritz
This is an array version changing volume only. I'll just post the code here, so others can see what we're talking about. Please install Norby's OXP and replace engine_sounds.js by this one:
Code: Select all
"use strict";
this.name = "engine_sound";
this.author = "Norby"; // strongly modified by Fritz G.
this.copyright = "2015 Norby";
this.description= "The tone of engine sound follow the speed of your ship.";
this.licence = "CC BY-NC-SA 4.0";
//internal properties, should not touch
this.$Last = 1; //last played sound
this.$SS = []; //soundsource array
this.$SST = null; //soundsource torus drive
this.$ST = []; //sounds torus drive
this.$torusOn = false;
//worldscript events
this.startUp = function()
{
// initialize engine sounds.
for(var i=1; i<26; i++)
{
this.$SS[i] = new SoundSource;
this.$SS[i].sound = Sound.load("bgs-m_ambi_engine1-"+i+".ogg");
this.$SS[i].loop = true;
this.$SS[i].volume = 0;
this.$SS[i].play();
}
// initialize torus sounds
this.$ST[1] = Sound.load("bgs-m_fx_enginedown1.ogg");
this.$ST[2] = Sound.load("bgs-m_fx_engineup1.ogg");
this.$SST = new SoundSource;
this.$SST.sound = this.$ST[2];
this.$SST.loop = false;
this.$torusOn = false;
// initialise timer. 0.25 is the minimal value so we need two timers
this.$T = new Timer(this, this.$Play, 0, 0.25);
this.$T2 = new Timer(this, this.$Play, 0.125, 0.25);
}
// timer function called every 1/8 s
this.$Play = function()
{
var p = player.ship;
if( !p || !p.isValid || p.docked)
{
// if (this.$SS[this.$Last].isPlaying) this.$SS[this.$Last].stop();
this.$SS[this.$Last].volume = 0;
return;
}
var pSpeed = p.speed/p.maxSpeed;
if (pSpeed >= 1)
{
if (pSpeed > 8 && !this.$torusOn)
{
// torus drive started
this.$torusOn = true;
this.$SST.sound = this.$ST[ 2 ];
this.$SST.play();
}
else if (pSpeed <= 8 && this.$torusOn)
{
// torus drive stopped
this.$torusOn = false;
this.$SST.sound = this.$ST[ 1 ];
this.$SST.play();
}
pSpeed = 1; // keeps engines running at full speed (sound #25)
}
// To get a standby sound we need sound #1 for speed 0 and sound #2 for speeds even slightly higher than 0.
if (pSpeed === 0)
{
var l = 1;
var vol = 0.5;
}
else
{
var l = Math.ceil(pSpeed*24)+1; // [2..25]
var vol = 1;
}
if(l != this.$Last)
{
// log ("Engine Sound: l = " + l + ", last = " + this.$Last + ", vol = " + vol);
// this.$SS[l].play();
// this.$SS[this.$Last].stop();
this.$SS[l].volume = vol;
this.$SS[this.$Last].volume = 0;
this.$Last = l;
}
}
Please note that it contains my torus sound modification but this doesn't have any effect on the crackling problem. And sorry, the forum messes up the tab indents.
Re: Sound effects
Posted: Sat Dec 05, 2015 3:38 pm
by ocz
My bet is, that even though you removed the start() and stop() functions they still are called from deeper in the java libraries, when you switch between the samples.
Re: Sound effects
Posted: Sat Dec 05, 2015 3:46 pm
by Fritz
But I don't really switch anymore, all 25 samples play continuously, and I only change the volume. And as I said, if I use 0.01 instead of 0 (a volume you can actually hear already), the crackling still occurs.
Re: Sound effects
Posted: Sat Dec 05, 2015 5:43 pm
by Fritz
The keyboard isn't the problem.
Re: Sound effects
Posted: Sat Dec 05, 2015 7:41 pm
by ocz
I created my own take on it, but I couldn't get rid of it either. I reduced the steps to 5 different engine sounds, took one timer out, played 2 sounds in transition and tried it with smooth transition sounds in between. The transition sounds of 25ms even made it worse, as now each step has a double crackling with 25ms in between. Turning down the volume to 0.5 instead to 0.1 seems actually to lower the volume of the crackling (did the volume decrease 1->0.1 cause the sound and not 0.1->stop()?), but I might be wrong there.
Code: Select all
"use strict";
this.name = "engine_sound";
this.author = "ocz"; // Edited engine_sound.js based on engine_sound.js by norby.
this.copyright = "2015 ocz";
this.description= "The tone of engine sound follow the speed of your ship.";
this.licence = "CC BY-NC-SA 4.0";
//internal properties, should not touch
this.$Last = 0; //last played sound
this.$EngineSound = []; //sound objects storing sound files
this.$AccelerationSound = [];
this.$DecelerationSound = [];
this.$SS = []; //soundsource
this.$Switch = false;
this.$Change = false;
//worldscript events
this.startUp = function() {
//$EngineSound[0]
for(var i=0; i<5; i++) {
this.$EngineSound[i] = Sound.load("bgs-m_ambi_engine_"+i+".ogg");
this.$AccelerationSound[i] = Sound.load("bgs-m_ambi_engine_acceleration_"+i+".ogg");
this.$DecelerationSound[i] = Sound.load("bgs-m_ambi_engine_deceleration_"+i+".ogg");
}
this.$EngineSound[5] = Sound.load("bgs-m_ambi_engine_5.ogg");
this.$SS[0] = new SoundSource;
this.$SS[1] = new SoundSource;
this.$SS[0].sound = this.$EngineSound[0];
this.$SS[1].sound = this.$EngineSound[0];
this.$SS[0].loop = true;
this.$SS[1].loop = true;
this.$T = new Timer(this, this.$Play, -1, 0.25);
}
this.gamePaused = this.shipDockedWithStation = this.shipDied = this.shipWillEnterWitchspace = function() {
$T.stop();
this.$SS[this.$Switch + false].stop();
this.$SS[!(this.$Switch) + false].stop();
}
this.gameResumed = this.shipWillLaunchFromStation = this.shipExitedWitchspace = function() {
this.$Change = true;
$T.start();
}
this.startUpComplete = function() {
var b = worldScripts["BGS-M"];
// if( b ) b.ambientSounds = false; //turn off BGS engine sound but chatter too
if (player.ship.status === "STATUS_IN_FLIGHT") $T.start();
}
//engine sound methods
this.$Play = function() {
var l = Math.ceil((player.ship.speed/player.ship.maxSpeed) * 5);
if( !this.$EngineSound[ l ] ) l = 5; //speed over maxSpeed;
if( this.$Last != l ) {
this.$Switch = !this.$Switch;
if (l < $Last) this.$SS[this.$Switch + false].sound = this.$DecelerationSound[l];
else this.$SS[this.$Switch + false].sound = this.$AccelerationSound[l-1];
this.$Last = l;
this.$SS[this.$Switch + false].volume = 1;
this.$SS[this.$Switch + false].loop = false;
this.$SS[this.$Switch + false].play();
this.$SS[!this.$Switch + false].volume = 0.5;
this.$Change = true;
}
else if (this.$Change) {
this.$Switch = !this.$Switch;
this.$SS[this.$Switch + false].sound = this.$EngineSound[l];
this.$SS[this.$Switch + false].volume = 1;
this.$SS[this.$Switch + false].loop = true;
this.$SS[this.$Switch + false].play();
this.$SS[!this.$Switch + false].volume = 0.5;
this.$Change = false;
}
}
Norby's OXP with my modifications (including other soundfiles).
Engine_Sound_1.1_mod_by_ocz_0.1.oxz
Engine Sound v1.2
Posted: Sat Dec 05, 2015 11:07 pm
by Norby
In [wiki]Engine Sound[/wiki] v1.2 I changed the volume within sound files and use variable volume during play to reduce scraping a bit.
Re: Sound effects
Posted: Sat Dec 05, 2015 11:08 pm
by Fritz
I've uploaded my current version (
http://wiki.alioth.net/index.php/Engine_Sound_FG). Because it is significantly different from Norby's version (see wiki page), I've decided to make a separate OXP. After many tries to avoid the slight switching sound, I've returned to the original way of using only one SoundSource to keep it simple.
I have tested my OXP together with BGS, but because the BGS engine sounds have to be disabled for obvious reasons, it disables the radio chatter and possibly some other sound effects too (BGS doesn't have a switch for every single sound effect).
Re: Sound effects
Posted: Sun Dec 06, 2015 1:18 am
by Fritz
I had the idea of adding a sound effect for maneuvering, and this made it obvious that the crackling sound isn't connected in any way to playing different sounds without pause or playing several sounds at once. The maneuvering sound (I simply use one of the 25 sound files) crackles slightly even when no other sound is playing, sometimes when starting and sometimes when stopping. There seems to be no difference between using play() and stop() or changing the volume.
I'll probably implement Norby's Idea of using louder files and reducing the volume. The currently used value of 1 is a little too loud anyhow, compared to other in-game sounds.
Re: Sound effects
Posted: Sun Dec 06, 2015 2:41 pm
by Fritz
I've uploaded version 1.1 (
http://wiki.alioth.net/index.php/Engine_Sound_FG) including the maneuvering sound. I've reduced the volume levels a little bit, but the OXP still uses the original sound files.
Now that I know that even 25 sounds can play simultaneously without affecting performance, I'm planning to add sounds for energy and shield generators - they should be "spinning up" when energy or shields go down and be quiet when everything is ok. Perhaps even a cooler can be implemented, spinning up if it gets hotter during sunskimming. Or a fuel pump that keeps running for a while after injector use and before (during countdown) and after witch jumping. Or an electric motor that opens/closes a cover flap during missile arming/disarming. Sadly there is no landing gear that could make nice noises too!
The combination of all sounds should give you the impression that you are sitting inside a metal box filled with machinery. I'll probably have to rename the OXP to "Equipment Sounds" sooner or later...
Re: Sound effects
Posted: Sun Dec 06, 2015 9:40 pm
by pagroove
I've tried the Norby version. Very good.
I will also try your version Fritz.
Great work!
If I have the time I can synthesize some new engine sounds. My fantasy is that every ship in the game has an unique engine sound.
Re: Sound effects
Posted: Sun Dec 06, 2015 10:04 pm
by pagroove
Back..
I did try the other version. I like it too. But to me the ideal situation is a oxo that combines the extra sounds by Fritz and the system by Norby as I don't like that the chatter and the in-station ambient sounds are now disabled.
Re: Sound effects
Posted: Sun Dec 06, 2015 10:17 pm
by Cody
pagroove wrote:My fantasy is that every ship in the game has an unique engine sound.
Music to my ears!
Re: Sound effects
Posted: Sun Dec 06, 2015 10:26 pm
by Fritz
I played around with Audacity, and it is great! It is probably no problem to change the sound files to fit any ship. I think they are perfect for a Python Gunship
, but for a smaller ship the lower frequencies (the files with the lower numbers) could be eliminated.
@pagroove: The missing chatter is a problem caused by BGS having a common "switch" for ambient noises (this.ambientSounds). If is it set to true, chatter and crowd noise can be disabled separately (as far as I have understood it), but not the engines. It is probably easy to fix in BGS itself, but I don't know how another OXP could change this.
Re: Sound effects
Posted: Sun Dec 06, 2015 10:40 pm
by pagroove
To prevent clicks in audio files one should take the approach of applying an inverse exponential fade in (also called 'Logarithmic Fade')at the start of the audio file and a exponential fade out at the end. Sound Forge has this as presets and Audacity also does come with a lot of options.
So this could help but sometimes this approach softens the sound files too much.
See here about fade ins/outs in Audacity:
http://manual.audacityteam.org/o/man/fa ... xponential
Re: Sound effects
Posted: Sun Dec 06, 2015 11:28 pm
by Fritz
I think we have the problem because the files have to be looped. So there can't be any fading, and that's why the problem doesn't occur with other sounds.
But then we have the injector sound (afterburner1.ogg). This has fading on both ends, and yet it can be played continuously. So the oolite core seems to have a way to play and loop only the middle part of a sound file. Strange.