AudioStreamGenerator
Stream resource for programmatically supplied PCM.
Assign the resource to AudioStreamPlayer, start the player and obtain AudioStreamGeneratorPlayback. Regularly supply stereo frames through PushBuffer; the generator does not synthesize sound itself.
Set MixRateMode, source rate and BufferLength before creating playback. Oscillator pitch comes from your phase increment; MixRate supplies the PCM source-frame rate only in Custom mode. The mixer can resample to the device rate.
Refill according to writable space, preserve phase across blocks and monitor GetSkips. Queue size is not total output latency. Using C# alone is not a reason to automatically lower the rate: measure your generator on the target system.
Complete C# example and troubleshooting.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
AudioStreamGeneratorConstructor
public AudioStreamGenerator();Creates a generator resource with Custom mode, MixRate=44100 and BufferLength=0.5 seconds. It neither synthesizes PCM nor starts playback itself; use a player and fill its playback buffer.
Properties3
BufferLengthProperty
public float BufferLength { get; set; }Requested queue duration in seconds when playback is created. Ring-buffer sizing rounds capacity; this is not exact device output latency. A longer queue tolerates refill delays but can increase control latency. Configure before creating playback.
MixRateProperty
public float MixRate { get; set; }Source PCM frames per second in Custom mode only; defaults to 44100. This is neither oscillator frequency nor a command to change the device rate. The setter stores its value without enforcing the Inspector range: validate a finite positive rate before creating playback.
MixRateModeProperty
public AudioStreamGenerator.AudioStreamGeneratorMixRate MixRateMode { get; set; }Selects source PCM rate: Custom uses MixRate, Output uses AudioServer output rate, Input uses its input rate. Input neither enables a microphone nor feeds microphone data into the queue. Max is an enum sentinel, not a usable mode.
Methods6
GetBufferLengthfloat
public float GetBufferLength();Reads the BufferLength setting. This is requested duration, not actual queued audio or measured latency.
floatConfigured BufferLength in seconds, not queue size in frames.
GetMixRatefloat
public float GetMixRate();Returns the stored custom MixRate. In Output/Input modes the effective source rate comes from AudioServer, so this is not a general effective-rate query.
floatStored custom MixRate in frames/second; used as the rate provider in Custom mode.
GetMixRateModeAudioStreamGenerator.AudioStreamGeneratorMixRate
public AudioStreamGenerator.AudioStreamGeneratorMixRate GetMixRateMode();Returns the MixRateMode setting that selects the generator’s source-rate provider.
AudioStreamGenerator.AudioStreamGeneratorMixRateCurrent mode selecting the generator’s source rate.
SetBufferLengthvoid
public void SetBufferLength(float seconds);Sets BufferLength for subsequent playback creation. The setter does not recreate an existing playback’s queue. Validate a finite positive duration and reasonable memory use.
| Name | Type | Default |
|---|---|---|
seconds | float | — |
secondsFinite positive duration in seconds. Validate before playback creation; a very large queue requires corresponding memory.
SetMixRatevoid
public void SetMixRate(float hz);Stores custom MixRate for Custom mode. The generation formula must use that same source frame rate. Do not change it in a running stream without coordinated stopping and reconfiguration.
| Name | Type | Default |
|---|---|---|
hz | float | — |
hzFinite positive source PCM rate in frames/second. Applies in Custom mode and must match producer calculations.
SetMixRateModevoid
public void SetMixRateMode(AudioStreamGenerator.AudioStreamGeneratorMixRate mode);Sets MixRateMode. Selecting Output/Input does not fill the PCM buffer automatically; the producer must still supply data at the matching rate.
| Name | Type | Default |
|---|---|---|
mode | AudioStreamGenerator.AudioStreamGeneratorMixRate | — |
modeOutput, Input or Custom. Do not pass Max or arbitrary enum values.
AudioStreamGenerator.AudioStreamGeneratorMixRate
| Value | Description |
|---|---|
Custom = 2 | Custom mixing rate, specified by |
Input = 1 | Current |
Max = 3 | Maximum value for the mixing rate mode enum. |
Output = 0 | Current |