docs.unity3d.com
    Show / Hide Table of Contents

    Struct SampleProvider

    A helper for reading samples from a native Unity resource, such as an AudioClip or a VideoPlayer

    Inherited Members
    ValueType.Equals(Object)
    ValueType.GetHashCode()
    ValueType.ToString()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    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
    IValidatable.Valid

    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()
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023