Jump to content

[1.0.x (partial)] Atmospheric Sound Enhancement v2.2 (2015-05-05)


pizzaoverhead

Recommended Posts

True, but since all parts have that property you just get all vessel parts in that List.

Huh, that's very weird. It's true, but weird :P I guess it might be the case so that all parts can make sound when they explode or something. I'll have to look into that further (but if it is for the explosions, then I suppose it's what we want, after all you shouldn't hear explosions in space).

In any case it shouldn't be too much of a hassle (at least with my version) since all calculations happen once per frame (not per part). But I will definitely look into this a bit. Although we should focus on functionality first, you know how it goes with premature optimizations.

Edited by SZDarkhack
Link to comment
Share on other sites

I see that I'm not the only one working on this (other than pizzaoverhead of course), which is great news. Perhaps pizza could put the project on GitHub for easier cooperation?

Yes, I plan on setting up GitHub projects. It would certainly make this kind of collaboration easier.

audio parts detection seems to grab all parts. Was that intentional? This could be troublesome with high part counts.
Huh, that's very weird. It's true, but weird :P I guess it might be the case so that all parts can make sound when they explode or something.
Could we have a sample video as a rocket flies into orbit? I spend a lot of time in space so mostly curious what things sound like out there. The sonic boom is a very cool effect though. :)

In space, there are no sounds at all in external views. I'll see about making a video in future.

Unintentional, I hadn't tested it. Explosion sounds aren't silenced, so it doesn't even have that benefit as a side effect! It also doesn't modify the low-frequency portion of jet engine sounds, which is separate to the high-pitched whine.

Although we should focus on functionality first, you know how it goes with premature optimizations.

This is true! My current goal is a configuration file so people can choose their level of realism. The AudioMuffler mod keeps low-frequency sounds in vacuum, which is atmospheric, if unrealistic. I'd like to make an option for something similar.

That performance testing is per what? Per frame?

Yes, per frame.

Alternatively, seek out only the noisiest parts; engines. Nothing else should be heard over jets/rockets anyway, so I think this is a fair compromise.

A lot of the current audio issues come from having many engines play the same sound at the same phase and intensity at the same time. I plan on working on sound combination in future. For example, if you have a cluster of 50 engines playing the same sound at the same level, silence them and play a single sound at their average location. This would cut out the interference and performance losses, and allow having two engines be twice as loud as one (playing with fade-off distance and volume). I can see some difficulty in deciding what constitutes a cluster however.

Could we have a sample video as a rocket flies into orbit? I spend a lot of time in space so mostly curious what things sound like out there. The sonic boom is a very cool effect though. :)

In space, there are no sounds in outside views. I'll look at making a video in future.

EDIT: The project is now on github. Check it out here:

https://github.com/pizzaoverhead/AtmosphericSoundEnhancement

Edited by pizzaoverhead
Added link.
Link to comment
Share on other sites

I think I found a bug in KSP which might yield why this mod fails to work 'sometimes'.

It appears as though the ActiveVessel.parts reference is not always updated internally. So it's useless to use it when checking for noisy parts. I still have some coding to do, but I'll at least share some test code using a new technique for finding noisy parts: (this test only seeks out engines to add filters)


AudioSource[] audioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
foreach (AudioSource s in audioSources)
{
Part part = s.gameObject.GetComponent<Part>();
if(part != null)
{
IEnumerable<ModuleEngines> enginesList = part.Modules.OfType<ModuleEngines>();
if(enginesList.Count() > 0)
audioParts.Add(part);
}
}
foreach(Part p in audioParts)
AddKnobs(p, Knobs.lowpass | Knobs.distortion | Knobs.reverb);
lastPartCount = FlightGlobals.ActiveVessel.parts.Count;

Link to comment
Share on other sites

Nice work Velusip! That's interesting. Hopefully we can gather enough information for a bug report. FindObjectsOfType(typeof(AudioSource)) seems to be a better solution all round, as the previous method wasn't catching some sounds.

EDIT: Project update

I've found a rough method* of controlling when the mach effects kick in. For the next release, they'll only appear during transonic flight. It should look something like

.

*varying AerodynamicsFX.fudge1

Edited by pizzaoverhead
Link to comment
Share on other sites

Finally got some time for this! Lots of changes. Mostly for readability and comprehension.

I integrated your code into mine, SZDarkhack. I hope you don't mind. I think your ideas/changes are excellent. I was thinking of renaming the variables 'inbound' and 'outbound' to 'trailingBoundary' and 'leadingBoundary' respectively, but I am not entirely convinced I got it right. Does this awful diagram summarize what's going on? e.g. theta L would be leadingBoundary.

5X03KDf.png

I'll send a pull request. I put some TODO tags in the code to indicate some minor issues that need work still. https://github.com/velusip/AtmosphericSoundEnhancement/tree/velu-refactor/AtmosphericSoundEnhancement


Changes:

* simplified condition logic (used SZDarkhack's model, reordered for speed)
* reduced work during some states (weak DRP logic)
* added filter reference caching (speed)
* added filter management methods (Think potentiometers knobs.)
* integrated SZDarkhack's transonic code (nice work!)
* integrated SZDarkhack's AtmoDataProvider (future FAR support, very cool)
* fixed "this mod is not working for me" bug: (next 3)
* avoiding bug in FlightGlobals.ActiveVessel.parts.audio in KSP
* avoiding an Addon initializing bug in KSP
* avoiding a revert-flight bug in KSP
* fixed rare null exceptions after unloading parts (bugfix)
* processes effects on stray parts until unloaded/destroyed (side effect)
* reduced reverb usage -- only inner shock cone.
* put variable initialization into Awake() method
* added namespace ASE and split classes into files
* stuff I forgot

Link to comment
Share on other sites

Finally got some time for this! Lots of changes. Mostly for readability and comprehension.

I integrated your code into mine, SZDarkhack. I hope you don't mind. I think your ideas/changes are excellent. I was thinking of renaming the variables 'inbound' and 'outbound' to 'trailingBoundary' and 'leadingBoundary' respectively, but I am not entirely convinced I got it right. Does this awful diagram summarize what's going on? e.g. theta L would be leadingBoundary.

5X03KDf.png

Yeap, that's pretty much it. I certainly don't mind you using the code, that's why I shared it in the first place :) Also, I apologize for the code being completely uncommented, I'll make sure to be much nicer to anyone else working on it and properly explain confusing parts (for instance that volume lerp is pretty cryptic if you don't know what's happening outside the cone, which is half a page later :P ). I'm glad that you found it useful anyway. The changes (from a quick source read) look very nice by the way :)

Link to comment
Share on other sites

Great work both of you! I've merged the combined changes that velusip submitted. Once I've finished work on the visual effect and configuration file code I'll make a 2.0 release. Thanks, this is a great improvement!

For future reference, could you expand on these issues?

  • avoiding an Addon initializing bug in KSP
  • avoiding a revert-flight bug in KSP
  • fixed rare null exceptions after unloading parts (bugfix)
  • processes effects on stray parts until unloaded/destroyed (side effect)

I'm not sure if Unity knows to bypass effects which are operating on AudioSources of zero volume, but I may change OnPause()'s silencing line to match Sparse()'s to be on the safe side:

aPanel.SetKnobs(Knobs.volume, 0);

aPanel.SetKnobs(Knobs.volume | Knobs.lowpass | Knobs.distortion | Knobs.reverb, -1);

Link to comment
Share on other sites

  • avoiding an Addon initializing bug in KSP
  • avoiding a revert-flight bug in KSP
  • fixed rare null exceptions after unloading parts (bugfix)
  • processes effects on stray parts until unloaded/destroyed (side effect)

Sorry about the vagueness. They are all related.

The first one (initialization) seems to be an inconsistent bug in KSP. KSPAddon.Startup.Flight sometimes gets run before FlightGlobals fully populates it's references. In turn, this was 'sometimes' causing no parts to be detected on the first run of the plugin using the old audio parts detection method. So now there's a bruteforce hack that simply checks if no audio parts are found. Obviously, this could be done with a lot more finesse.

The second bug (revert flight) is consistent. When reverting a flight to the launchpad, the audio components are are not re-associated with references in FlightGlobals. So all I did was stop using FlightGlobals for finding audio components completely.

The third (null) might be something I introduced during testing and later squashed. It had something to do with filtered parts drifting out of the scene or smashing, but the plugin was still trying to update the components by reference.

Link to comment
Share on other sites

I could've sworn I asked this before, but I can't find my post. The boom is unreal, no? A pilot cannot hear his own sonic boom. Please correct me if wrong. Love the other effects thought. A sonic boom would be cool if you could somehow get a fly-by camera.

Link to comment
Share on other sites

I could've sworn I asked this before, but I can't find my post. The boom is unreal, no? A pilot cannot hear his own sonic boom. Please correct me if wrong. Love the other effects thought. A sonic boom would be cool if you could somehow get a fly-by camera.

You are correct, you cannot hear the boom inside the ship (and the addon models that properly in the IVA views). The exterior views are from the camera's perspective, so if you move the camera into the sonic boom then you can hear it.

Edited by SZDarkhack
Link to comment
Share on other sites

I could've sworn I asked this before, but I can't find my post. The boom is unreal, no? A pilot cannot hear his own sonic boom. Please correct me if wrong. Love the other effects thought. A sonic boom would be cool if you could somehow get a fly-by camera.

This mod treats the game camera as an external fly-by camera, so you can hear the shock if you pass through it. While there is no boom for the pilot, there is some change in the sound of the airflow when transonic, similar to the sound the mach effects in the stock game make. You can hear a real-life example

. The next update of this mod will be adjusting the mach effects so that they only occur when transonic.
Sorry about the vagueness. They are all related.

The first one (initialization) seems to be an inconsistent bug in KSP. KSPAddon.Startup.Flight sometimes gets run before FlightGlobals fully populates it's references. In turn, this was 'sometimes' causing no parts to be detected on the first run of the plugin using the old audio parts detection method. So now there's a bruteforce hack that simply checks if no audio parts are found. Obviously, this could be done with a lot more finesse.

The second bug (revert flight) is consistent. When reverting a flight to the launchpad, the audio components are are not re-associated with references in FlightGlobals. So all I did was stop using FlightGlobals for finding audio components completely.

The third (null) might be something I introduced during testing and later squashed. It had something to do with filtered parts drifting out of the scene or smashing, but the plugin was still trying to update the components by reference.

Thanks for the explanation! I've spotted only one issue with the patch (poor documentation on my part): 0.0089 kg/m^3 isn't the air density below which no sounds can be heard, it's the density above which all sounds that the game can model can be heard. Below that density, the mean path between air molecules increases, attenuating higher frequencies. Sound intensity remains the same at all densities as it's the movement of the molecules (even if there's only one of them). I'll add fixes for this in the next commit.

Edited by pizzaoverhead
Link to comment
Share on other sites

0.0089 kg/m^3 isn't the air density below which no sounds can be heard, it's the density above which all sounds that the game can model can be heard. Below that density, the mean path between air molecules increases, attenuating higher frequencies.

Heh, I should have caught that. The audio seemed to be cutting out really early when testing. Just to confirm, two things must be wrong with my last commit:

* dynamic use of a low bandpass filter should only begin cutting high frequency sounds (<22050Hz) at an atmospheric density of 0.0089 kg/m^3 and gradually shrink the bandpass region until vacuum (at which point the state changes and the lowpass calculations stop)

* and the "Sparse" state can be renamed to simply Vacuum, and the logic entering the Vacuum state update to match.

Link to comment
Share on other sites

Is there a way to get the boom without the lack of sound in space? I know the latter isn't realistic but I don't just want music all the time.

EDIT: Alternatively, since what you hear from the external camera is arguably from a mic inside the ship, could we have the internal sounds play when in space?

Edited by codepants
Link to comment
Share on other sites

Somewhat nasty bug that needs to be tamed rather than fixed. The sound clips quite badly with lots of parts. Especially noticable with jet engines (either type). I'm not sure why that is, but it might be that they have multiple concurrent AudioSource components. I figure this can be fixed with a feature we touched on discussing earlier -- part discrimination and selective suppression. (World leaders would be proud!)

See step 4 in the list I've been working on. Please feel free to jump in and offer ideas or recommend against anything you see here.


################################################################################
1 Soundscape logic (complete)

See diagram Soundscapes.png for hierarchical logic in play.
- Each leaf of the logic tree is a state.
- Changes in state can be detected with DRP logic. e.g. (current != last)

New states require the hierarchy rewritten.

If necessary, flatten condition detection for early detection to make smart
decisions in other parts of the code. This is a matter of optimization based on
features. So it can wait.

################################################################################
2 Cache filter component references (complete)
Using part.gameObject.GetComponent<t>() is way too slow. Need a cache of
references to every filter in use for quick retrieval.

Created new structure for containing sets of references to audio parts and
their filters.

################################################################################
3 Early filter management (complete)
Filters are added on part detection rather than inline with conditional logic.
- filters adjusted amid per Soundscape.
- error checking every frame during update parts list.

################################################################################
4 Discriminate
Discriminate part types and add filters where needed.
- two sets; engines and other
- distortion and reverb on Engine parts.
- lowpass and volume on all audio parts.

################################################################################
5 Soundscape configuration (in progress)
Control knobs conveniently adjust filter settings per Soundscape. Each
Soundscape has a preset. See chart below -- up for discussion.

Key:
(V)olume, (l)owpass, (d)istortion, (r)everb
1 enable, 0 disable, d(y)namic realtime, (h)old position

Soundscape | Engine Part Knobs | Quiet Part Knobs*
| V Lh Ly D Dy R Ry | V Lh Ly D Dy R Ry
-------------+----------------------+---------------------
Paused | 0 | 0
Interior | 1 1 0 0 0 0 0 | 1 1 0 0 0 0 0
Sparse Atm | 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0
Before Shock | 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0
After Shock | 1 0 1 0 0 0 0 | 1 0 1 0 0 0 0
Lead Shock | 1 0 1 0 1 0 0 | 1 0 1 0 0 0 0
Trail Shock | 1 0 1 0 1 0 1 | 1 0 1 0 0 0 0
Dense Atm | 1 0 1 0 0 0 0 | 1 0 1 0 0 0 0

* quiet part list depends on the Part Discrimination feature.

################################################################################
6 Suppression
Mute a percentage of parts over a threshold number. This ensures that only a
small number of parts are ever making noise, and thus only so many filters need
to exist. The update-audio-parts-routine automatically reassesses which parts
get a voice.
- May involve vessel node logic (ensure most suitable parts are making noise).
- Depends on Part Discrimination feature.


################################################################################

Something to note, I only noticed today that the reverb filter has a whole bunch of settings I don't understand. I might try making another toy to adjust filters in-game and get a sense for what everything does.

* AudioReverbFilter - script reference

* AudioReverbFilter - editor reference

Edited by velusip
added links to reverb filter docs
Link to comment
Share on other sites

Something to note, I only noticed today that the reverb filter has a whole bunch of settings I don't understand. I might try making another toy to adjust filters in-game and get a sense for what everything does.

* AudioReverbFilter - script reference

* AudioReverbFilter - editor reference

I'm familiar with reverb settings (from music experience) but It's easier to understand them by playing with them and seeing what they do. If you do need some clarification though, feel free to ask.

Link to comment
Share on other sites

Is there a way to get the boom without the lack of sound in space? I know the latter isn't realistic but I don't just want music all the time.

EDIT: Alternatively, since what you hear from the external camera is arguably from a mic inside the ship, could we have the internal sounds play when in space?

This isn't possible in the current version, but I plan for a future release to have options for this available in a config file so you can customise it however you like:

  • Microphone at the camera.
  • Microphone on the outside of the ship.
  • Microphone inside the ship.
  • No sound in vacuum.
  • Muffled sound in vacuum.
  • Full sound in vacuum.
  • No sound in front of supersonic craft.
  • Muffled sound in front of supersonic craft.
  • Full sound in front of supersonic craft.
  • No sonic boom.

Somewhat nasty bug that needs to be tamed rather than fixed. The sound clips quite badly with lots of parts. Especially noticable with jet engines (either type). I'm not sure why that is, but it might be that they have multiple concurrent AudioSource components.

This often happens if the sound is disabled or reduced for a fraction of a frame, exacerbated by longer Update() times. If this is the case, it can be tracked by logging AudioPanel changes. Either way, better identification of what objects need to be worked on would help. For example, AudioSource.clip is null for some parts.

I might try making another toy to adjust filters in-game and get a sense for what everything does.

I recommend this. As SZDarkhack said, it's much more intuitive to modify it for yourself than read a description. I have a similar tool for adjusting the re-entry and condensation effects; It sped up the process considerably.

Link to comment
Share on other sites

Version 2.0 has now been released at http://kerbalspaceprogram.com/atmospheric-sound-enhancement.

  • Added a configuration file.
  • Added the ability to choose between silence or muffled sound when supersonic or in a vacuum (muffled by default).
  • Customised condensation and re-entry effects.
  • Fixed issues with the Mach sounds not always being played at the correct angles.

Link to comment
Share on other sites

Now the effect sound doesn't turn on at all during transonic and supersonic flight (even vacuum). I see the condensation effects (cool), but the sound keeps playing normally after mach 1 no matter where the camera is. It doesn't seem to work with B9 saber engines either.

Link to comment
Share on other sites

Now the effect sound doesn't turn on at all during transonic and supersonic flight (even vacuum). I see the condensation effects (cool), but the sound keeps playing normally after mach 1 no matter where the camera is. It doesn't seem to work with B9 saber engines either.

The sounds are now muffled rather than silenced by default. You can change it back by replacing settings.cfg with the contents of the realistic example settings file.

Link to comment
Share on other sites

The sounds are now muffled rather than silenced by default. You can change it back by replacing settings.cfg with the contents of the realistic example settings file.

Nope, the sounds when I go supersonic no longer change at ALL for all spaceplanes. I still hear the engines at normal level throughout the entire flight, with both stock and B9 engine parts.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...