Struct SampleProvider
A helper for reading samples from a native Unity resource, such as an AudioClip or a VideoPlayer
Inherited Members
Namespace: Unity.Audio
Syntax
public struct SampleProvider : IValidatable
Properties
ChannelCount
Gets the number of channels in the decoded sound.
Declaration
public readonly short ChannelCount { get; }
Property Value
Type | Description |
---|---|
Int16 |
NativeFormat
Gets the format of the samples used internally by the system. This will likely be the format that yields best performance because conversion can be skipped.
Declaration
public readonly SampleProvider.NativeFormatType NativeFormat { get; }
Property Value
Type | Description |
---|---|
SampleProvider.NativeFormatType |
SampleRate
Get the sample rate of the decoded sound.
Declaration
public readonly int SampleRate { get; }
Property Value
Type | Description |
---|---|
Int32 |
Valid
Whether the provider is valid and readable
Declaration
public readonly bool Valid { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
Methods
Read(SampleBuffer, Int32, Int32, BufferWriteMode)
Reads a part of the samples as floats from the sample provider.
Declaration
public int Read(SampleBuffer destination, int start = 0, int length = -1, BufferWriteMode writeMode = BufferWriteMode.Overwrite)
Parameters
Type | Name | Description |
---|---|---|
SampleBuffer | destination | A sample buffer that decoded samples are written to. |
Int32 | start | The frame index at which to start writing to the buffer. |
Int32 | length | The number of frames to write to the buffer, -1 to fill the buffer completely. |
BufferWriteMode | writeMode | The mode for writing samples to the buffer |
Returns
Type | Description |
---|---|
Int32 | The number of samples that could be read. Will be less than the requested size when the end of the sound is reached. |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException |
Read(NativeSlice<Byte>, SampleProvider.NativeFormatType)
Reads a part of the samples as bytes in the specified output format from the sample provider.
Declaration
public int Read(NativeSlice<byte> destination, SampleProvider.NativeFormatType format)
Parameters
Type | Name | Description |
---|---|---|
NativeSlice<Byte> | destination | The destination buffer that decoded samples are written to. |
SampleProvider.NativeFormatType | format | The destination format that the samples are decoded to. |
Returns
Type | Description |
---|---|
Int32 | The number of samples that could be read. Will be less than the destination size when the end of the sound is reached. |
Remarks
Unlike the float overloads, here the buffer is written in interleaved order
Read(NativeSlice<Int16>, SampleProvider.NativeFormatType)
Reads a part of the samples as short integers in the specified output format from the sample provider.
Declaration
public int Read(NativeSlice<short> destination, SampleProvider.NativeFormatType format)
Parameters
Type | Name | Description |
---|---|---|
NativeSlice<Int16> | destination | The destination buffer that decoded samples are written to. |
SampleProvider.NativeFormatType | format | The destination format that the samples are decoded to. |
Returns
Type | Description |
---|---|
Int32 | The number of samples that could be read. Will be less than the destination size when the end of the sound is reached. |
Remarks
Unlike the float overloads, here the buffer is written in interleaved order
Read(NativeSlice<Single>)
Reads a part of the samples as floats from the sample provider.
Declaration
public int Read(NativeSlice<float> destination)
Parameters
Type | Name | Description |
---|---|---|
NativeSlice<Single> | destination | The destination buffer that decoded samples are written to. |
Returns
Type | Description |
---|---|
Int32 | The number of samples that could be read. Will be less than the destination size when the end of the sound is reached. |
Release()
Deallocates the sample provider.
Declaration
public void Release()