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:
"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.
Last edited by Fritz on Tue Dec 08, 2015 7:10 pm, edited 1 time in total.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
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.
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.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
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.
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).
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
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.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
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...
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
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.
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.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
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.
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.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"