static DSPNode CreateMixer(DSPCommandBlock block)
    {
        var mixer = block.CreateDSPNode <MixerNode.Parameters, MixerNode.Providers, MixerNode>();

        block.AddInletPort(mixer, 16, SoundFormat.Mono); // input
        block.AddInletPort(mixer, 16, SoundFormat.Mono); // cv
        block.AddOutletPort(mixer, 1, SoundFormat.Mono);
        return(mixer);
    }
    static DSPNode CreateMonoToStereo(DSPCommandBlock block)
    {
        var mts = block.CreateDSPNode <MonoToStereoNode.Parameters, MonoToStereoNode.Providers, MonoToStereoNode>();

        block.AddInletPort(mts, 1, SoundFormat.Mono); // left
        block.AddInletPort(mts, 1, SoundFormat.Mono); // right
        block.AddOutletPort(mts, 2, SoundFormat.Stereo);
        return(mts);
    }
    static DSPNode CreateVCA(DSPCommandBlock block)
    {
        var vca = block.CreateDSPNode <VCANode.Parameters, VCANode.Providers, VCANode>();

        block.AddInletPort(vca, 16, SoundFormat.Mono); // voltage
        block.AddInletPort(vca, 16, SoundFormat.Mono); // input
        block.AddOutletPort(vca, 16, SoundFormat.Mono);
        return(vca);
    }
    static DSPNode CreateOscilator(DSPCommandBlock block)
    {
        var oscilator = block.CreateDSPNode <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>();

        block.AddInletPort(oscilator, 16, SoundFormat.Mono); // fm
        block.AddInletPort(oscilator, 16, SoundFormat.Mono); // pitch
        block.AddInletPort(oscilator, 16, SoundFormat.Mono); // phase reset
        block.AddOutletPort(oscilator, 16, SoundFormat.Mono);
        return(oscilator);
    }
    static DSPNode CreateSpectrum(DSPCommandBlock block)
    {
        var scope = block.CreateDSPNode <SpectrumNode.Parameters, SpectrumNode.Providers, SpectrumNode>();

        block.AddInletPort(scope, 1, SoundFormat.Mono);
        return(scope);
    }
    static DSPNode CreateAttenuator(DSPCommandBlock block)
    {
        var attenuator = block.CreateDSPNode <AttenuatorNode.Parameters, AttenuatorNode.Providers, AttenuatorNode>();

        block.AddInletPort(attenuator, 1, SoundFormat.Mono);
        block.AddOutletPort(attenuator, 1, SoundFormat.Mono);
        return(attenuator);
    }
    static DSPNode CreateADSR(DSPCommandBlock block)
    {
        var adsr = block.CreateDSPNode <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>();

        block.AddInletPort(adsr, 16, SoundFormat.Mono); // gate
        block.AddOutletPort(adsr, 16, SoundFormat.Mono);
        return(adsr);
    }
        public static DSPNode Create(DSPCommandBlock block, FilterType type)
        {
            var node = block.CreateDSPNode <AudioKernel.Parameters, AudioKernel.Providers, AudioKernel>();

            block.AddInletPort(node, 2);
            block.AddOutletPort(node, 2);
            block.SetFloat <AudioKernel.Parameters, AudioKernel.Providers, AudioKernel>(node,
                                                                                        AudioKernel.Parameters.FilterType, (float)type);

            return(node);
        }
Beispiel #9
0
        public static DSPNode Create(DSPCommandBlock block, FilterType type, float cutoff, float q, float gainInDbs, int channelsPerPort)
        {
            var node = block.CreateDSPNode <Parameters, Providers, StateVariableFilterNode>();

            block.AddInletPort(node, channelsPerPort);
            block.AddOutletPort(node, channelsPerPort);
            block.SetFloat <Parameters, Providers, StateVariableFilterNode>(node, Parameters.FilterType, (float)type);
            block.SetFloat <Parameters, Providers, StateVariableFilterNode>(node, Parameters.Cutoff, cutoff);
            block.SetFloat <Parameters, Providers, StateVariableFilterNode>(node, Parameters.Q, q);
            block.SetFloat <Parameters, Providers, StateVariableFilterNode>(node, Parameters.GainInDBs, gainInDbs);

            return(node);
        }
        public static NodeData CreatePassthroughNode(DSPCommandBlock block, DSPGraph graph, int channelCount, SoundFormat soundFormat)
        {
            var node = block.CreateDSPNode <NoParameters, NoProviders, PassThrough>();

            block.AddInletPort(node, channelCount, soundFormat);
            block.AddOutletPort(node, channelCount, soundFormat);
            var connection = block.Connect(node, 0, graph.RootDSP, 0);

            return(new NodeData
            {
                Node = node,
                Connection = connection
            });
        }
Beispiel #11
0
    // Script load constructor
    private void Awake()
    {
        AudioConfiguration audioConfig = AudioSettings.GetConfiguration();

        m_sampleRate = audioConfig.sampleRate;
        m_bufferSize = audioConfig.dspBufferSize;

        switch (audioConfig.speakerMode)
        {
        case AudioSpeakerMode.Mono:
        {
            m_channels = 1;
            break;
        }

        case AudioSpeakerMode.Stereo:
        {
            m_channels = 2;
            break;
        }

        default:
        {
            m_channels = 2;
            break;
        }
        }

        // Create output
        m_driver = new DSPGraphDriver();
        m_driver.Initialize(m_channels, SoundFormat.Stereo, m_sampleRate, m_bufferSize);
        int bufferAllocationSize = (m_channels * m_bufferSize);

        m_buffer = new NativeArray <float>(bufferAllocationSize, Allocator.Persistent, NativeArrayOptions.ClearMemory);

        // Connect internal node to the output
        DSPCommandBlock commandBlock = m_driver.m_graph.CreateCommandBlock();

        m_oscNode = commandBlock.CreateDSPNode <OscParameters, OscProviders, OscillatorNode>();
        commandBlock.AddOutletPort(m_oscNode, 1, SoundFormat.Mono);
        commandBlock.SetFloat <OscParameters, OscProviders, OscillatorNode>(m_oscNode, OscParameters.Wave, (float)OscWave.Sine);
        commandBlock.SetFloat <OscParameters, OscProviders, OscillatorNode>(m_oscNode, OscParameters.Frequency, 440.0f);

        // SVF (2nd order low pass) node
        m_filterNode = commandBlock.CreateDSPNode <SVFParameters, SVFProviders, SVFNode>();
        commandBlock.AddInletPort(m_filterNode, 1, SoundFormat.Mono);
        commandBlock.AddOutletPort(m_filterNode, 1, SoundFormat.Mono);
        commandBlock.SetFloat <SVFParameters, SVFProviders, SVFNode>(m_filterNode, SVFParameters.Cutoff, 100.0f);
        commandBlock.SetFloat <SVFParameters, SVFProviders, SVFNode>(m_filterNode, SVFParameters.Q, 0.707f);
        commandBlock.SetFloat <SVFParameters, SVFProviders, SVFNode>(m_filterNode, SVFParameters.Amplitude, 0.8f);

        // VCA (amplitude control) node
        m_vcaNode = commandBlock.CreateDSPNode <VCAParameters, VCAProviders, VCANode>();
        commandBlock.AddInletPort(m_vcaNode, 1, SoundFormat.Mono);
        commandBlock.AddOutletPort(m_vcaNode, 1, SoundFormat.Mono);
        commandBlock.SetFloat <VCAParameters, VCAProviders, VCANode>(m_vcaNode, VCAParameters.Amplitude, 0.0f);

        // Mono to stereo node setup
        m_stereoNode = commandBlock.CreateDSPNode <MonoToStereoParameters, MonoToStereoProviders, MonoToStereoNode>();
        commandBlock.AddInletPort(m_stereoNode, 1, SoundFormat.Mono);
        commandBlock.AddOutletPort(m_stereoNode, m_channels, SoundFormat.Stereo);
        commandBlock.SetFloat <MonoToStereoParameters, MonoToStereoProviders, MonoToStereoNode>(m_stereoNode, MonoToStereoParameters.Pan, 0.0f);

        // Connect the nodes together
        // VCO -> SVF -> VCA -> Pan -> Output
        commandBlock.Connect(m_oscNode, 0, m_filterNode, 0);
        commandBlock.Connect(m_filterNode, 0, m_vcaNode, 0);
        commandBlock.Connect(m_vcaNode, 0, m_stereoNode, 0);
        commandBlock.Connect(m_stereoNode, 0, m_driver.m_graph.RootDSP, 0);

        // Send the command the atomic/asynchronous handler
        commandBlock.Complete();
    }