Table of Contents

自定义音频数据

高级 程序员

你可以使用自己的机制生成音频。为此,请创建 DynamicSoundSource 的一个子类。 有关实现示例,请参阅 CompressedSoundSource` 源代码。

示例代码

要在运行时播放自定义的 DynamicSoundSource,请使用:

int sampleRate = 48000;
bool mono = false;
bool spatialized = false;
DynamicSoundSource myCustomSource = new MyCustomSource(...);
AudioListener listener = Audio.AudioEngine.DefaultListener;
AudioEngine audioEngine = Audio.AudioEngine;
SoundInstance myCustomInstance = new SoundInstance(audioEngine, listener, myCustomSource, sampleRate, mono, spatialized);
await myCustomInstance.ReadyToPlay();
myCustomInstance.Play();

另请参阅