Assets/Plugins/Unity.DSPGraph/Runtime/DSPGraph.cs
/// <summary>
/// Create and return a DSPGraph container
/// </summary>
/// <param name="outputFormat">SoundFormat of type Enum whose values are: Raw, Mono, Stereo, Quad, Surround, FiveDot1 or SevenDot1</param>
/// <param name="outputChannels">Specify the number of output channels</param>
/// <param name="dspBufferSize">Specify the buffer size </param>
/// <param name="sampleRate">Specify the sample rate of the graph </param>
/// <returns>A DSPGraph object</returns>
Create and return a DSPGraph container
Create and return a DSPGraph container
public static DSPGraph Create(SoundFormat outputFormat, int outputChannels, int dspBufferSize, int sampleRate)
        {
            switch (outputFormat)
            {
                case SoundFormat.SevenDot1:
                    if (outputChannels != 8)
                        throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Output format {outputFormat} requires exactly 8 channels");
                    break;
                case SoundFormat.FiveDot1:
                    if (outputChannels != 6)
                        throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Output format {outputFormat} requires exactly 6 channels");
                    break;
                case SoundFormat.Surround:
                    if (outputChannels != 5)
                        throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Output format {outputFormat} requires exactly 5 channels");
                    break;
                case SoundFormat.Quad:
                    if (outputChannels != 4)
                        throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Output format {outputFormat} requires exactly 4 channels");
                    break;
                case SoundFormat.Stereo:
                    if (outputChannels != 2)
                        throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Output format {outputFormat} requires exactly 2 channels");
                    break;
                case SoundFormat.Mono:
                    if (outputChannels != 1)
                        throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Output format {outputFormat} requires exactly 1 channel");
                    break;
                case SoundFormat.Raw:
                    if (outputChannels < 2)
                        throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Output format {outputFormat} requires at least 2 channels");
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(outputFormat), $"Unknown output format {outputFormat}");
            }
            if (outputChannels < 1)
                throw new ArgumentOutOfRangeException(nameof(outputChannels), $"Invalid output channel count {outputChannels}");
            if (dspBufferSize <= 0)
                throw new ArgumentOutOfRangeException(nameof(dspBufferSize), $"Invalid DSP buffer size {dspBufferSize}");
            if ((dspBufferSize % outputChannels) != 0)
                throw new ArgumentOutOfRangeException(nameof(dspBufferSize), "DSP buffer size must be a multiple of the channel count");
            if (sampleRate <= 0)
                throw new ArgumentOutOfRangeException(nameof(sampleRate), $"Invalid sample rate {sampleRate}");
            var graph = new DSPGraph(outputFormat, outputChannels, dspBufferSize, sampleRate);
            graph.Register();
            return graph;
        }
public static DSPGraph Create ( SoundFormat outputFormat , int outputChannels , int dspBufferSize , int sampleRate ) { switch ( outputFormat ) { case SoundFormat . SevenDot1 : if ( outputChannels != 8 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Output format  { outputFormat }  requires exactly 8 channels " ) ; break ; case SoundFormat . FiveDot1 : if ( outputChannels != 6 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Output format  { outputFormat }  requires exactly 6 channels " ) ; break ; case SoundFormat . Surround : if ( outputChannels != 5 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Output format  { outputFormat }  requires exactly 5 channels " ) ; break ; case SoundFormat . Quad : if ( outputChannels != 4 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Output format  { outputFormat }  requires exactly 4 channels " ) ; break ; case SoundFormat . Stereo : if ( outputChannels != 2 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Output format  { outputFormat }  requires exactly 2 channels " ) ; break ; case SoundFormat . Mono : if ( outputChannels != 1 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Output format  { outputFormat }  requires exactly 1 channel " ) ; break ; case SoundFormat . Raw : if ( outputChannels < 2 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Output format  { outputFormat }  requires at least 2 channels " ) ; break ; default : throw new ArgumentOutOfRangeException ( nameof ( outputFormat ) , $" Unknown output format  { outputFormat } " ) ; } if ( outputChannels < 1 ) throw new ArgumentOutOfRangeException ( nameof ( outputChannels ) , $" Invalid output channel count  { outputChannels } " ) ; if ( dspBufferSize <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( dspBufferSize ) , $" Invalid DSP buffer size  { dspBufferSize } " ) ; if ( ( dspBufferSize % outputChannels ) != 0 ) throw new ArgumentOutOfRangeException ( nameof ( dspBufferSize ) , " " ) ; if ( sampleRate <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( sampleRate ) , $" Invalid sample rate  { sampleRate } " ) ; var graph = new DSPGraph ( outputFormat , outputChannels , dspBufferSize , sampleRate ) ; graph . Register ( ) ; return graph ; }
Create and return a DSPGraph container
Create and return a DSPGraph container
A DSPGraph object
A DSPGraph object
outputFormat
SoundFormat
SoundFormat of type Enum whose values are: Raw, Mono, Stereo, Quad, Surround, FiveDot1 or SevenDot1
SoundFormat of type Enum whose values are : Raw Mono Stereo Quad Surround FiveDot1 or SevenDot1
outputChannels
int
Specify the number of output channels
Specify the number of output channels
dspBufferSize
int
Specify the buffer size
Specify the buffer size
sampleRate
int
Specify the sample rate of the graph
Specify the sample rate of the graph