Custom audio data

AdvancedProgrammer

You can generate audio using your own mechanism. To do this, create a subclass of DynamicSoundSource.For an example of how to implement this, see the CompressedSoundSource` source code.

Example code

To play a custom DynamicSoundSource at runtime, use:

  1. int sampleRate = 48000;
  2. bool mono = false;
  3. bool spatialized = false;
  4. DynamicSoundSource myCustomSource = new MyCustomSource(...);
  5. AudioListener listener = Audio.AudioEngine.DefaultListener;
  6. AudioEngine audioEngine = Audio.AudioEngine;
  7. SoundInstance myCustomInstance = new SoundInstance(audioEngine, listener, myCustomSource, sampleRate, mono, spatialized);
  8. await myCustomInstance.ReadyToPlay();
  9. myCustomInstance.Play();

See also