Sound effect OXPs

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post 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.
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!"
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: Sound effects

Post 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.
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post 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.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post by Fritz »

The keyboard isn't the problem.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: Sound effects

Post 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
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Engine Sound v1.2

Post 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.
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post 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).
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post 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.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post 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...
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
User avatar
pagroove
---- E L I T E ----
---- E L I T E ----
Posts: 3035
Joined: Wed Feb 21, 2007 11:52 pm
Location: On a famous planet

Re: Sound effects

Post 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.
For P.A. Groove's music check
https://soundcloud.com/p-a-groove
Famous Planets v 2.7. (for Povray)
Image
https://bb.oolite.space/viewtopic.php?f=4&t=13709
User avatar
pagroove
---- E L I T E ----
---- E L I T E ----
Posts: 3035
Joined: Wed Feb 21, 2007 11:52 pm
Location: On a famous planet

Re: Sound effects

Post 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.
For P.A. Groove's music check
https://soundcloud.com/p-a-groove
Famous Planets v 2.7. (for Povray)
Image
https://bb.oolite.space/viewtopic.php?f=4&t=13709
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sound effects

Post by Cody »

pagroove wrote:
My fantasy is that every ship in the game has an unique engine sound.
Music to my ears!
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post 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 :D, 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!"
User avatar
pagroove
---- E L I T E ----
---- E L I T E ----
Posts: 3035
Joined: Wed Feb 21, 2007 11:52 pm
Location: On a famous planet

Re: Sound effects

Post 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
For P.A. Groove's music check
https://soundcloud.com/p-a-groove
Famous Planets v 2.7. (for Povray)
Image
https://bb.oolite.space/viewtopic.php?f=4&t=13709
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Sound effects

Post 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.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
Post Reply