AudioStreamWav
A sampled-audio resource with format, sample rate and looping.
AudioStreamWav stores sound data and the settings needed to interpret it. The teaching example uses Format16Bits, mono little-endian PCM: two bytes per sample without a RIFF/WAV header in Data. MixRate specifies sample rate; player position uses seconds.
LoopBegin and LoopEnd use audio-frame indices, not seconds or bytes. A stereo frame contains two channels. Imported resources may use another supported compression format: do not interpret all Data as PCM16. Resources can be shared; changing settings affects their users.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
AudioStreamWavConstructor
public AudioStreamWav();Properties8
DataProperty
public byte[] Data { get; set; }Audio bytes in the encoding identified by Format. For QOA and IMA ADPCM these are compressed data, not raw 16-bit PCM. This is not an ordinary source WAV header plus payload; account for Stereo and MixRate when interpreting PCM.
FormatProperty
public AudioStreamWav.FormatEnum Format { get; set; }Audio format.
LoopBeginProperty
public int LoopBegin { get; set; }Loop start in sample frames of the processed resource, not seconds. At 48000 Hz, frame 12000 is 0.25 seconds; do not multiply by channel count for stereo.
LoopEndProperty
public int LoopEnd { get; set; }Loop end in resource sample frames. A negative import setting such as −1 is resolved by the importer before storing this property; do not confuse it with Ogg/MP3 LoopOffset seconds.
LoopModeProperty
public AudioStreamWav.LoopModeEnum LoopMode { get; set; }The loop mode.
MixRateProperty
public int MixRate { get; set; }Resource sample rate in Hz. After an import rate cap, inspect both MixRate and data size; setting force/max_rate_hz without enabling force/max_rate does not activate conversion.
StereoProperty
public bool Stereo { get; set; }If true, audio is stereo.
TagsProperty
public Reckfell.Collections.Dictionary Tags { get; set; }Contains user-defined tags if found in the WAV data.
Commonly used tags include title, artist, album, tracknumber, and date (date does not have a standard date format).
Note: No tag is guaranteed to be present in every file, so make sure to account for the keys not always existing.
Note: Only WAV files using a LIST chunk with an identifier of INFO to encode the tags are currently supported.
Methods21
GetDatabyte[]
public byte[] GetData();byte[]GetFormatAudioStreamWav.FormatEnum
public AudioStreamWav.FormatEnum GetFormat();AudioStreamWav.FormatEnumGetLoopBeginint
public int GetLoopBegin();intGetLoopEndint
public int GetLoopEnd();intGetLoopModeAudioStreamWav.LoopModeEnum
public AudioStreamWav.LoopModeEnum GetLoopMode();AudioStreamWav.LoopModeEnumGetMixRateint
public int GetMixRate();intGetTagsReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary GetTags();Reckfell.Collections.DictionaryIsStereobool
public bool IsStereo();boolLoadFromBuffer2 overloads
public static AudioStreamWav LoadFromBuffer(byte[] streamData, Reckfell.Collections.Dictionary options = null);Creates a new AudioStreamWav instance from the given buffer. The buffer must contain WAV data.
The keys and values of options match the properties of ResourceImporterWav. The usage of options is identical to AudioStreamWav.LoadFromFile.
| Name | Type | Default |
|---|---|---|
streamData | byte[] | — |
options | Reckfell.Collections.Dictionary | null |
AudioStreamWavpublic static AudioStreamWav LoadFromBuffer(ReadOnlySpan<byte> streamData, Reckfell.Collections.Dictionary options);Creates a new AudioStreamWav instance from the given buffer. The buffer must contain WAV data.
The keys and values of options match the properties of ResourceImporterWav. The usage of options is identical to AudioStreamWav.LoadFromFile.
| Name | Type | Default |
|---|---|---|
streamData | ReadOnlySpan<byte> | — |
options | Reckfell.Collections.Dictionary | — |
AudioStreamWavLoadFromFileAudioStreamWav
public static AudioStreamWav LoadFromFile(string path, Reckfell.Collections.Dictionary options = null);Reads a raw audio file directly without applying editor .import settings. Use ResourceLoader.Load for a project asset with its imported settings. Pass WAV conversion settings in options; default compression without options is PCM, not the editor importer’s QOA.
| Name | Type | Default |
|---|---|---|
path | string | — |
options | Reckfell.Collections.Dictionary | null |
pathPath to the actual source file. Ensure it is available in the chosen build; an imported resource path does not guarantee the original bytes are shipped.
optionsConversion settings such as force/mono and compress/mode. This is an explicit dictionary; .import values are not supplied automatically.
AudioStreamWavLoaded audio resource, or null on a reading/format error. Check the result before playback.
SaveToWavError
public Error SaveToWav(string path);Saves existing stream data as WAV. Does not start microphone capture or verify useful signal. The checked PCM16 file reloaded with matching rate, stereo, and duration.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathOutput path, usually user://recording.wav. The implementation appends .wav when missing; check directory access.
ErrorError.Ok on success; handle other codes. This method cannot save IMA ADPCM or QOA; the example creates PCM16.
SetData2 overloads
public void SetData(byte[] data);| Name | Type | Default |
|---|---|---|
data | byte[] | — |
public void SetData(ReadOnlySpan<byte> data);| Name | Type | Default |
|---|---|---|
data | ReadOnlySpan<byte> | — |
SetFormatvoid
public void SetFormat(AudioStreamWav.FormatEnum format);| Name | Type | Default |
|---|---|---|
format | AudioStreamWav.FormatEnum | — |
SetLoopBeginvoid
public void SetLoopBegin(int loopBegin);| Name | Type | Default |
|---|---|---|
loopBegin | int | — |
SetLoopEndvoid
public void SetLoopEnd(int loopEnd);| Name | Type | Default |
|---|---|---|
loopEnd | int | — |
SetLoopModevoid
public void SetLoopMode(AudioStreamWav.LoopModeEnum loopMode);| Name | Type | Default |
|---|---|---|
loopMode | AudioStreamWav.LoopModeEnum | — |
SetMixRatevoid
public void SetMixRate(int mixRate);| Name | Type | Default |
|---|---|---|
mixRate | int | — |
SetStereovoid
public void SetStereo(bool stereo);| Name | Type | Default |
|---|---|---|
stereo | bool | — |
SetTagsvoid
public void SetTags(Reckfell.Collections.Dictionary tags);| Name | Type | Default |
|---|---|---|
tags | Reckfell.Collections.Dictionary | — |
AudioStreamWav.FormatEnum
| Value | Description |
|---|---|
Format16Bits = 1 | 16-bit PCM audio codec. |
Format8Bits = 0 | 8-bit PCM audio codec. |
ImaAdpcm = 2 | Audio is lossily compressed as IMA ADPCM. |
Qoa = 3 | Audio is lossily compressed as Quite OK Audio. |
AudioStreamWav.LoopModeEnum
| Value | Description |
|---|---|
Backward = 3 | Audio loops the data between |
Disabled = 0 | Audio does not loop. |
Forward = 1 | Audio loops the data between |
Pingpong = 2 | Audio loops the data between |