C# Class kOS.Sound.ProceduralSoundWave

Creates an arbitrary audio wave reference example note and populates an AudioClip with it.
These are used with the SoundMaker class to provide a means to do crude FM wave sounds.
Each of the "FM wave generators" in the kOS computer's "audio chip" is a derived class of this.
To make a new FM wave type, just inherit from this class and override SampleFunction with your own mathematical function that describes the sound wave in the time domain. The base class should populate the audio clip for you from that.
Inheritance: IProceduralSoundWave
ファイルを表示 Open project: KSP-KOS/KOS Class Usage Examples

Public Methods

Method Description
InitSettings ( ) : void

Meant to be overridden if a derived type has to change settings before GenerateClip() is called.

IMPORTANT: When making a derivative of ProceduralSoundWave, put your initializations HERE not in the constructor, because the base constructor will call this before it does things, where if you set them in your derived constructor, then GenerateClip() would be getting called before your settings in your constructor happened.

If you override it, be sure to explicitly call the base version too.

ProceduralSoundWave ( ) : kOS.Safe.Sound

Important: when making a derivative of ProceduralSoundWave, put your initializations of important things inside InitSettings(), not in your constructor. Instead make your constructor call the base constructor and do nothing else. The base constructor will call your InitSettings() for you. This is important because you need to populate your settings BEFORE the base constructor tries to call GenerateClip(). If you populated your settings inside your own constructor, that would be too late.

SampleFunction ( float t ) : float

Override this in your derived class to make a wave generator of whatever type you like. It should be a time-domain picture of the sound wave over one wave period, outputting values from -1 to +1 for a given time t.

Private Methods

Method Description
FillBuffer ( float sampleData, int numChannels ) : void

The workhorse under the hood for GenerateClip().

GenerateClip ( ) : void

Generates the AudioClip (happens as part of the constructor).
It does this by querying your SampleFunction() to build a reference wave in memory.

Method Details

InitSettings() public method

Meant to be overridden if a derived type has to change settings before GenerateClip() is called.

IMPORTANT: When making a derivative of ProceduralSoundWave, put your initializations HERE not in the constructor, because the base constructor will call this before it does things, where if you set them in your derived constructor, then GenerateClip() would be getting called before your settings in your constructor happened.

If you override it, be sure to explicitly call the base version too.
public InitSettings ( ) : void
return void

ProceduralSoundWave() public method

Important: when making a derivative of ProceduralSoundWave, put your initializations of important things inside InitSettings(), not in your constructor. Instead make your constructor call the base constructor and do nothing else. The base constructor will call your InitSettings() for you. This is important because you need to populate your settings BEFORE the base constructor tries to call GenerateClip(). If you populated your settings inside your own constructor, that would be too late.
public ProceduralSoundWave ( ) : kOS.Safe.Sound
return kOS.Safe.Sound

SampleFunction() public method

Override this in your derived class to make a wave generator of whatever type you like. It should be a time-domain picture of the sound wave over one wave period, outputting values from -1 to +1 for a given time t.
public SampleFunction ( float t ) : float
t float
return float