Esempio n. 1
0
    void Start()
    {
        var graph = DSPGraph.Create(SoundFormat.Stereo, 2, 1024, 48000);

        var driver = new DefaultDSPGraphDriver {
            Graph = graph
        };

        _outputHandle = driver.AttachToDefaultOutput();

        MidiMaster.noteOnDelegate += (MidiChannel channel, int noteNumber, float velocity) => {
            var block = graph.CreateCommandBlock();

            notesNode[noteNumber] = block.CreateDSPNode <SineOscillatorNodeJob.Params, NoProvs, SineOscillatorNodeJob>();
            block.AddOutletPort(notesNode[noteNumber], 2, SoundFormat.Stereo);
            block.SetFloat <SineOscillatorNodeJob.Params, NoProvs, SineOscillatorNodeJob>(
                notesNode[noteNumber],
                SineOscillatorNodeJob.Params.Frequency, math.pow(2, (noteNumber - 69) / 12.0f) * 440.0f
                );

            block.Connect(notesNode[noteNumber], 0, graph.RootDSP, 0);

            block.Complete();
        };

        MidiMaster.noteOffDelegate += (MidiChannel channel, int noteNumber) => {
            var block = graph.CreateCommandBlock();

            block.ReleaseDSPNode(notesNode[noteNumber]);

            block.Complete();
        };
    }
        void OnGUI()
        {
            if (GUI.Button(new Rect(10, 10, 150, 100), "Play"))
            {
                var output = new SineToneOutput {
                    Frequency = Frequency
                };

                if (m_Handle.Valid)
                {
                    m_Handle.Dispose();
                }
                m_Handle = output.AttachToDefaultOutput();
                StartCoroutine(TimeoutSine(Duration));
            }
        }
    void Start()
    {
        var format   = ChannelEnumConverter.GetSoundFormatFromSpeakerMode(AudioSettings.speakerMode);
        var channels = ChannelEnumConverter.GetChannelCountFromSoundFormat(format);

        AudioSettings.GetDSPBufferSize(out var bufferLength, out var numBuffers);

        var sampleRate = AudioSettings.outputSampleRate;

        m_Graph = DSPGraph.Create(format, channels, bufferLength, sampleRate);

        var driver = new DefaultDSPGraphDriver {
            Graph = m_Graph
        };

        m_Output = driver.AttachToDefaultOutput();

        // Add an event handler delegate to the graph for ClipStopped. So we are notified
        // of when a clip is stopped in the node and can handle the resources on the main thread.
        m_HandlerID = m_Graph.AddNodeEventHandler <ClipStopped>((node, evt) =>
        {
            Debug.Log("Received ClipStopped event on main thread, cleaning resources");
        });

        // All async interaction with the graph must be done through a DSPCommandBlock.
        // Create it here and complete it once all commands are added.
        var block = m_Graph.CreateCommandBlock();

        m_Node = block.CreateDSPNode <PlayClipNode.Parameters, PlayClipNode.SampleProviders, PlayClipNode>();

        // Currently input and output ports are dynamic and added via this API to a node.
        // This will change to a static definition of nodes in the future.
        block.AddOutletPort(m_Node, 2, SoundFormat.Stereo);

        // Connect the node to the root of the graph.
        m_Connection = block.Connect(m_Node, 0, m_Graph.RootDSP, 0);

        // We are done, fire off the command block atomically to the mixer thread.
        block.Complete();
    }
Esempio n. 4
0
    void Start()
    {
        var graph = DSPGraph.Create(SoundFormat.Stereo, 2, 1024, 48000);

        var driver = new DefaultDSPGraphDriver {
            Graph = graph
        };

        driver.Initialize(2, SoundFormat.Stereo, 48000, 1024);

        _outputHandle = driver.AttachToDefaultOutput();

        var block = graph.CreateCommandBlock();
        var node  = block.CreateDSPNode <SineOscillatorNodeJob.Params, NoProvs, SineOscillatorNodeJob>();

        block.AddOutletPort(node, 2, SoundFormat.Stereo);
        block.SetFloat <SineOscillatorNodeJob.Params, NoProvs, SineOscillatorNodeJob>(
            node, SineOscillatorNodeJob.Params.Frequency, 440.0f);

        var connection = block.Connect(node, 0, graph.RootDSP, 0);

        block.Complete();
    }
Esempio n. 5
0
        protected override void OnCreate()
        {
            this._available = new NativeQueue <DSPNode>(Allocator.Persistent);
            this._all       = new NativeList <DSPNode>(Allocator.Persistent);

            var format   = ChannelEnumConverter.GetSoundFormatFromSpeakerMode(AudioSettings.speakerMode);
            var channels = ChannelEnumConverter.GetChannelCountFromSoundFormat(format);

            AudioSettings.GetDSPBufferSize(out var bufferLength, out _);

            var sampleRate = AudioSettings.outputSampleRate;

            Debug.Log($"Audio SampleRate will be {sampleRate}");

            this._graph = DSPGraph.Create(format, channels, bufferLength, sampleRate);

            var driver = new DefaultDSPGraphDriver {
                Graph = this._graph
            };

            this._output = driver.AttachToDefaultOutput();

            this._graph.AddNodeEventHandler <AudioSampleNodeCompleted>(this.ReleaseNode);
        }
Esempio n. 6
0
    void Awake()
    {
        AudioConfiguration audioConfig = AudioSettings.GetConfiguration();

        Debug.LogFormat("BufferSize={0} SampleRate={1}", audioConfig.dspBufferSize, audioConfig.sampleRate);

        _Graph  = DSPGraph.Create(SoundFormat.Stereo, 2, audioConfig.dspBufferSize, audioConfig.sampleRate);
        _Driver = new MyAudioDriver {
            Graph = _Graph
        };
        _OutputHandle = _Driver.AttachToDefaultOutput();

        WidgetGraph.OnEnable();
        for (int i = WidgetGraph.nodes.Count - 1; i >= 0; --i)
        {
            WidgetGraph.nodes[i].Init();
        }
        for (int i = WidgetGraph.nodes.Count - 1; i >= 0; --i)
        {
            DSPNodeWidget dspNodeWidget = WidgetGraph.nodes[i] as DSPNodeWidget;
            if (dspNodeWidget == null)
            {
                continue;
            }
            foreach (var inputPort in dspNodeWidget.Ports)
            {
                if (!inputPort.IsInput)
                {
                    continue;
                }
                var dspInlet = dspNodeWidget.GetDSPPortAttribute(inputPort);
                if (dspInlet == null)
                {
                    continue;
                }

                var outputPorts = inputPort.GetConnections();
                foreach (var outputPort in outputPorts)
                {
                    if (!outputPort.IsOutput)
                    {
                        continue;
                    }
                    DSPNodeWidget dspNodeWidget2 = outputPort.node as DSPNodeWidget;
                    if (dspNodeWidget2 == null)
                    {
                        continue;
                    }
                    var dspOutlet = dspNodeWidget2.GetDSPPortAttribute(outputPort);
                    if (dspOutlet == null)
                    {
                        continue;
                    }

                    using (var block = DSPGraph.CreateCommandBlock())
                    {
                        block.Connect(dspNodeWidget2.DSPNode, dspOutlet.portIndex, dspNodeWidget.DSPNode, dspInlet.portIndex);
                    }
                }
            }
        }
    }
Esempio n. 7
0
    void Start()
    {
        var graph = DSPGraph.Create(SoundFormat.Stereo, 2, 1024, 48000);

        var driver = new DefaultDSPGraphDriver {
            Graph = graph
        };

        driver.Initialize(2, SoundFormat.Stereo, 48000, 1024);

        _outputHandle = driver.AttachToDefaultOutput();

        var block = graph.CreateCommandBlock();

        var midiCvNode = block.CreateDSPNode <MIDICVNode.Params, MIDICVNode.Providers, MIDICVNode>();

        block.AddOutletPort(midiCvNode, 1, SoundFormat.Mono);
        block.AddOutletPort(midiCvNode, 1, SoundFormat.Mono);
        block.SetFloat <MIDICVNode.Params, MIDICVNode.Providers, MIDICVNode>(midiCvNode, MIDICVNode.Params.Note, -1.0f);

        var vcoNode = block.CreateDSPNode <VCONode.Params, VCONode.Providers, VCONode>();

        block.AddInletPort(vcoNode, 1, SoundFormat.Mono);
        block.AddOutletPort(vcoNode, 1, SoundFormat.Mono);

        var adsrNode = block.CreateDSPNode <ADSRNode.Params, ADSRNode.Providers, ADSRNode>();

        block.AddInletPort(adsrNode, 1, SoundFormat.Mono);
        block.AddOutletPort(adsrNode, 1, SoundFormat.Mono);
        block.SetFloat <ADSRNode.Params, ADSRNode.Providers, ADSRNode>(adsrNode, ADSRNode.Params.Attack, 0.2f);
        block.SetFloat <ADSRNode.Params, ADSRNode.Providers, ADSRNode>(adsrNode, ADSRNode.Params.Decay, 2.0f);
        block.SetFloat <ADSRNode.Params, ADSRNode.Providers, ADSRNode>(adsrNode, ADSRNode.Params.Sustain, 3.0f);
        block.SetFloat <ADSRNode.Params, ADSRNode.Providers, ADSRNode>(adsrNode, ADSRNode.Params.Release, 0.5f);

        var vcaNode = block.CreateDSPNode <VCANode.Params, VCANode.Providers, VCANode>();

        block.AddInletPort(vcaNode, 1, SoundFormat.Mono);
        block.AddInletPort(vcaNode, 1, SoundFormat.Mono);
        block.AddOutletPort(vcaNode, 1, SoundFormat.Mono);

        var monoToStereoNode = block.CreateDSPNode <MonoToStereoNode.Params, MonoToStereoNode.Providers, MonoToStereoNode>();

        block.AddInletPort(monoToStereoNode, 1, SoundFormat.Mono);
        block.AddOutletPort(monoToStereoNode, 2, SoundFormat.Stereo);

        block.Connect(midiCvNode, 0, vcoNode, 0);
        block.Connect(midiCvNode, 1, adsrNode, 0);
        block.Connect(vcoNode, 0, vcaNode, 0);
        block.Connect(adsrNode, 0, vcaNode, 1);
        block.Connect(vcaNode, 0, monoToStereoNode, 0);
        block.Connect(monoToStereoNode, 0, graph.RootDSP, 0);

        block.Complete();

        MidiMaster.noteOnDelegate += (MidiChannel channel, int noteNumber, float velocity) => {
            var noteOnBlock = graph.CreateCommandBlock();

            noteOnBlock.SetFloat <MIDICVNode.Params, MIDICVNode.Providers, MIDICVNode>(midiCvNode, MIDICVNode.Params.Note, (float)noteNumber);

            noteOnBlock.Complete();
        };

        MidiMaster.noteOffDelegate += (MidiChannel channel, int noteNumber) => {
            var noteOffBlock = graph.CreateCommandBlock();

            noteOffBlock.SetFloat <MIDICVNode.Params, MIDICVNode.Providers, MIDICVNode>(midiCvNode, MIDICVNode.Params.Note, -1.0f);

            noteOffBlock.Complete();
        };
    }
Esempio n. 8
0
    void ConfigureDSP()
    {
        AudioConfiguration audioConfig = AudioSettings.GetConfiguration();

        Debug.LogFormat("BufferSize={0} SampleRate={1}", audioConfig.dspBufferSize, audioConfig.sampleRate);
        _MicrophoneClip = Microphone.Start(Microphone.devices[0], true, 1, audioConfig.sampleRate);
        Debug.LogFormat("Microphone Channels={0} Frequency={1} Samples={2} Ambisonic={3}", _MicrophoneClip.channels, _MicrophoneClip.frequency, _MicrophoneClip.samples, _MicrophoneClip.ambisonic);
        _MicrophoneBuffer    = new NativeArray <float>(_MicrophoneClip.samples, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        _MicrophoneDataArray = new float[_MicrophoneClip.samples];

        _Graph  = DSPGraph.Create(SoundFormat.Stereo, 2, audioConfig.dspBufferSize, audioConfig.sampleRate);
        _Driver = new MyAudioDriver {
            Graph = _Graph
        };
        _OutputHandle = _Driver.AttachToDefaultOutput();

        // create graph structure
        using (var block = _Graph.CreateCommandBlock())
        {
            //
            // create nodes
            //
            _Microphone = block.CreateDSPNode <MicrophoneNode.Parameters, MicrophoneNode.Providers, MicrophoneNode>();
            block.AddOutletPort(_Microphone, 1, SoundFormat.Mono);

            _Scope = block.CreateDSPNode <ScopeNode.Parameters, ScopeNode.Providers, ScopeNode>();
            block.AddInletPort(_Scope, 1, SoundFormat.Mono);

            _Spectrum = block.CreateDSPNode <SpectrumNode.Parameters, SpectrumNode.Providers, SpectrumNode>();
            block.AddInletPort(_Spectrum, 1, SoundFormat.Mono);

            _MonoToStereo = block.CreateDSPNode <MonoToStereoNode.Parameters, MonoToStereoNode.Providers, MonoToStereoNode>();
            block.AddInletPort(_MonoToStereo, 1, SoundFormat.Mono); // left
            block.AddInletPort(_MonoToStereo, 1, SoundFormat.Mono); // right
            block.AddOutletPort(_MonoToStereo, 2, SoundFormat.Stereo);

            //
            // connect nodes
            //
            block.Connect(_Microphone, 0, _MonoToStereo, 0);
            block.Connect(_Microphone, 0, _MonoToStereo, 1);

            block.Connect(_MonoToStereo, 0, _Graph.RootDSP, 0);

            block.Connect(_Microphone, 0, _Scope, 0);
            block.Connect(_Microphone, 0, _Spectrum, 0);

            //
            // set parameters
            //
            block.SetFloat <ScopeNode.Parameters, ScopeNode.Providers, ScopeNode>(_Scope, ScopeNode.Parameters.Time, 1f);
            block.SetFloat <ScopeNode.Parameters, ScopeNode.Providers, ScopeNode>(_Scope, ScopeNode.Parameters.TriggerTreshold, 0f);

            block.SetFloat <SpectrumNode.Parameters, SpectrumNode.Providers, SpectrumNode>(_Spectrum, SpectrumNode.Parameters.Window, (float)SpectrumNode.WindowType.Hamming);
        }

        _ScopeRenderer        = SpawnScopeRenderer(_Scope);
        _ScopeRenderer.Height = 5.0f;
        _ScopeRenderer.Offset = 0.0f;

        _SpectrumRenderer = SpawnSpectrumRenderer(_Spectrum);

        StartCoroutine(InitMicCoroutine());
    }
Esempio n. 9
0
    void Start()
    {
        var graph = DSPGraph.Create(SoundFormat.Stereo, 2, 1024, 48000);

        var driver = new DefaultDSPGraphDriver {
            Graph = graph
        };

        _outputHandle = driver.AttachToDefaultOutput();

        MidiMaster.noteOnDelegate += (MidiChannel channel, int noteNumber, float velocity) => {
            var block = graph.CreateCommandBlock();

            modulatorNode[noteNumber] = block.CreateDSPNode <SineOscillatorNodeJob.Params, NoProvs, SineOscillatorNodeJob>();
            block.AddOutletPort(modulatorNode[noteNumber], 2, SoundFormat.Stereo);
            block.SetFloat <SineOscillatorNodeJob.Params, NoProvs, SineOscillatorNodeJob>(
                modulatorNode[noteNumber],
                SineOscillatorNodeJob.Params.Frequency, 1.34f * math.pow(2, (noteNumber - 69) / 12.0f) * 440.0f
                );

            modulatorADSNode[noteNumber] = block.CreateDSPNode <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>();
            block.AddInletPort(modulatorADSNode[noteNumber], 2, SoundFormat.Stereo);
            block.AddOutletPort(modulatorADSNode[noteNumber], 2, SoundFormat.Stereo);
            block.SetFloat <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>(
                modulatorADSNode[noteNumber],
                AttackDecaySustainNodeJob.Params.Attack, 0.3f
                );

            block.SetFloat <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>(
                modulatorADSNode[noteNumber],
                AttackDecaySustainNodeJob.Params.Decay, 0.1f
                );

            block.SetFloat <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>(
                modulatorADSNode[noteNumber],
                AttackDecaySustainNodeJob.Params.Sustain, 1.2f
                );

            carrierNode[noteNumber] = block.CreateDSPNode <ModulatableSineOscillatorNodeJob.Params, NoProvs, ModulatableSineOscillatorNodeJob>();
            block.AddInletPort(carrierNode[noteNumber], 2, SoundFormat.Stereo);
            block.AddOutletPort(carrierNode[noteNumber], 2, SoundFormat.Stereo);
            block.SetFloat <ModulatableSineOscillatorNodeJob.Params, NoProvs, ModulatableSineOscillatorNodeJob>(
                carrierNode[noteNumber],
                ModulatableSineOscillatorNodeJob.Params.Frequency, math.pow(2, (noteNumber - 69) / 12.0f) * 440.0f
                );

            carrierADSNode[noteNumber] = block.CreateDSPNode <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>();
            block.AddInletPort(carrierADSNode[noteNumber], 2, SoundFormat.Stereo);
            block.AddOutletPort(carrierADSNode[noteNumber], 2, SoundFormat.Stereo);
            block.SetFloat <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>(
                carrierADSNode[noteNumber],
                AttackDecaySustainNodeJob.Params.Attack, 0.1f
                );

            block.SetFloat <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>(
                carrierADSNode[noteNumber],
                AttackDecaySustainNodeJob.Params.Decay, 1.0f
                );

            block.SetFloat <AttackDecaySustainNodeJob.Params, NoProvs, AttackDecaySustainNodeJob>(
                carrierADSNode[noteNumber],
                AttackDecaySustainNodeJob.Params.Sustain, 0.0f
                );

            block.Connect(modulatorNode[noteNumber], 0, modulatorADSNode[noteNumber], 0);
            block.Connect(modulatorADSNode[noteNumber], 0, carrierNode[noteNumber], 0);
            block.Connect(carrierNode[noteNumber], 0, carrierADSNode[noteNumber], 0);
            block.Connect(carrierADSNode[noteNumber], 0, graph.RootDSP, 0);

            block.Complete();
        };

        MidiMaster.noteOffDelegate += (MidiChannel channel, int noteNumber) => {
            var block = graph.CreateCommandBlock();

            block.ReleaseDSPNode(modulatorNode[noteNumber]);
            block.ReleaseDSPNode(carrierNode[noteNumber]);

            block.Complete();
        };
    }
    void ConfigureDSP()
    {
        AudioConfiguration audioConfig = AudioSettings.GetConfiguration();

        Debug.LogFormat("BufferSize={0} SampleRate={1}", audioConfig.dspBufferSize, audioConfig.sampleRate);

        _Graph  = DSPGraph.Create(SoundFormat.Stereo, 2, audioConfig.dspBufferSize, audioConfig.sampleRate);
        _Driver = new MyAudioDriver {
            Graph = _Graph
        };
        _OutputHandle = _Driver.AttachToDefaultOutput();

        // create graph structure
        using (var block = _Graph.CreateCommandBlock())
        {
            //
            // create nodes
            //
            _Oscilator1 = CreateOscilator(block);
            _Oscilator2 = CreateOscilator(block);
            _Oscilator3 = CreateOscilator(block);
            _Oscilator4 = CreateOscilator(block);

            _ADSR1 = CreateADSR(block);
            _ADSR2 = CreateADSR(block);
            _ADSR3 = CreateADSR(block);
            _ADSR4 = CreateADSR(block);

            _VCA1 = CreateVCA(block);
            _VCA2 = CreateVCA(block);

            _Mixer3 = CreateMixer(block);
            _Mixer4 = CreateMixer(block);

            _Midi = CreateMidi(block);

            _Attenuator = CreateAttenuator(block);

            _MonoToStereo = CreateMonoToStereo(block);

            _Scope    = CreateMonoScope(block);
            _Spectrum = CreateSpectrum(block);

            //
            // connect nodes
            //
            block.Connect(_Midi, 0, _ADSR1, 0); // midi gate to adsr
            block.Connect(_Midi, 0, _ADSR2, 0);
            block.Connect(_Midi, 0, _ADSR3, 0);
            block.Connect(_Midi, 0, _ADSR4, 0);

            block.Connect(_Midi, 1, _Oscilator1, 1); // midi note to oscilator pitch
            block.Connect(_Midi, 1, _Oscilator2, 1);
            block.Connect(_Midi, 1, _Oscilator3, 1);
            block.Connect(_Midi, 1, _Oscilator4, 1);

            block.Connect(_Midi, 2, _Oscilator1, 2); // midi retrigger to oscilator reset phase
            block.Connect(_Midi, 2, _Oscilator2, 2);
            block.Connect(_Midi, 2, _Oscilator3, 2);
            block.Connect(_Midi, 2, _Oscilator4, 2);

            block.Connect(_ADSR1, 0, _VCA1, 0); // adsr gate to vca voltage
            block.Connect(_ADSR2, 0, _VCA2, 0);

            block.Connect(_Oscilator1, 0, _VCA1, 1); // oscilator out to vca in
            block.Connect(_Oscilator2, 0, _VCA2, 1);

            block.Connect(_VCA1, 0, _Oscilator3, 0); // vca out to oscilator fm
            block.Connect(_VCA2, 0, _Oscilator4, 0);

            block.Connect(_ADSR3, 0, _Mixer3, 1); // adsr gate to mixer cv
            block.Connect(_ADSR4, 0, _Mixer4, 1);

            block.Connect(_Oscilator3, 0, _Mixer3, 0); // oscilator out to mixer in
            block.Connect(_Oscilator4, 0, _Mixer4, 0);

            block.Connect(_Mixer3, 0, _Attenuator, 0); // mixer out to attenuator in
            block.Connect(_Mixer4, 0, _Attenuator, 0);

            block.Connect(_Attenuator, 0, _MonoToStereo, 0);    // attenuator out to monotostereo left
            block.Connect(_Attenuator, 0, _MonoToStereo, 1);    // attenuator out to monotostereo right

            block.Connect(_MonoToStereo, 0, _Graph.RootDSP, 0); // monotostereo out to output

            block.Connect(_Attenuator, 0, _Scope, 0);
            block.Connect(_Attenuator, 0, _Spectrum, 0);

            //
            // parameters
            //
            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator1, OscilatorNode.Parameters.Frequency, 130.813f);
            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator1, OscilatorNode.Parameters.Mode, (float)OscilatorNode.Mode.Sine);

            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator2, OscilatorNode.Parameters.Frequency, 130.813f);
            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator2, OscilatorNode.Parameters.Mode, (float)OscilatorNode.Mode.Sine);

            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator3, OscilatorNode.Parameters.Frequency, 261.626f);
            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator3, OscilatorNode.Parameters.Mode, (float)OscilatorNode.Mode.Sine);
            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator3, OscilatorNode.Parameters.FMMultiplier, 0.5f);

            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator4, OscilatorNode.Parameters.Frequency, 130.813f);
            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator4, OscilatorNode.Parameters.Mode, (float)OscilatorNode.Mode.Sine);
            block.SetFloat <OscilatorNode.Parameters, OscilatorNode.Providers, OscilatorNode>(_Oscilator4, OscilatorNode.Parameters.FMMultiplier, 0.4f);

            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR1, ADSRNode.Parameters.Attack, 0.1f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR1, ADSRNode.Parameters.Decay, 0.05f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR1, ADSRNode.Parameters.Sustain, 0.5f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR1, ADSRNode.Parameters.Release, 0.2f);

            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR2, ADSRNode.Parameters.Attack, 0.1f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR2, ADSRNode.Parameters.Decay, 0.05f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR2, ADSRNode.Parameters.Sustain, 0.5f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR2, ADSRNode.Parameters.Release, 0.2f);

            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR3, ADSRNode.Parameters.Attack, 0.05f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR3, ADSRNode.Parameters.Decay, 0.05f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR3, ADSRNode.Parameters.Sustain, 0.5f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR3, ADSRNode.Parameters.Release, 0.1f);

            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR4, ADSRNode.Parameters.Attack, 0.05f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR4, ADSRNode.Parameters.Decay, 0.05f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR4, ADSRNode.Parameters.Sustain, 0.5f);
            block.SetFloat <ADSRNode.Parameters, ADSRNode.Providers, ADSRNode>(_ADSR4, ADSRNode.Parameters.Release, 0.1f);

            block.SetFloat <VCANode.Parameters, VCANode.Providers, VCANode>(_VCA1, VCANode.Parameters.Multiplier, 1.0f);
            block.SetFloat <VCANode.Parameters, VCANode.Providers, VCANode>(_VCA2, VCANode.Parameters.Multiplier, 1.0f);

            block.SetFloat <AttenuatorNode.Parameters, AttenuatorNode.Providers, AttenuatorNode>(_Attenuator, AttenuatorNode.Parameters.Multiplier, 1.0f);

            block.SetFloat <ScopeNode.Parameters, ScopeNode.Providers, ScopeNode>(_Scope, ScopeNode.Parameters.Time, 0.05f);
            block.SetFloat <ScopeNode.Parameters, ScopeNode.Providers, ScopeNode>(_Scope, ScopeNode.Parameters.TriggerTreshold, 0f);

            block.SetFloat <SpectrumNode.Parameters, SpectrumNode.Providers, SpectrumNode>(_Spectrum, SpectrumNode.Parameters.Window, (float)SpectrumNode.WindowType.BlackmanHarris);
        }

        _ScopeRenderer        = SpawnScopeRenderer(_Scope);
        _ScopeRenderer.Height = 5.01f;
        _ScopeRenderer.Offset = 0f;

        _SpectrumRenderer = SpawnSpectrumRenderer(_Spectrum);
    }
Esempio n. 11
0
        protected override void OnCreate()
        {
            //Initialize containers first
            m_mixNodePortFreelist        = new NativeList <int>(Allocator.Persistent);
            m_mixNodePortCount           = new NativeReference <int>(Allocator.Persistent);
            m_ildNodePortCount           = new NativeReference <int>(Allocator.Persistent);
            m_packedFrameCounterBufferId = new NativeReference <long>(Allocator.Persistent);
            m_audioFrame       = new NativeReference <int>(Allocator.Persistent);
            m_lastReadBufferId = new NativeReference <int>(Allocator.Persistent);
            m_buffersInFlight  = new List <ManagedIldBuffer>();

            worldBlackboardEntity.AddComponentDataIfMissing(new AudioSettings {
                audioFramesPerUpdate = 3, audioSubframesPerFrame = 1, logWarningIfBuffersAreStarved = false
            });

            //Create graph and driver
            var format   = ChannelEnumConverter.GetSoundFormatFromSpeakerMode(UnityEngine.AudioSettings.speakerMode);
            var channels = ChannelEnumConverter.GetChannelCountFromSoundFormat(format);

            UnityEngine.AudioSettings.GetDSPBufferSize(out m_samplesPerSubframe, out _);
            m_sampleRate = UnityEngine.AudioSettings.outputSampleRate;
            m_graph      = DSPGraph.Create(format, channels, m_samplesPerSubframe, m_sampleRate);
            m_driver     = new LatiosDSPGraphDriver {
                Graph = m_graph
            };
            m_outputHandle = m_driver.AttachToDefaultOutput();

            var commandBlock = m_graph.CreateCommandBlock();

            m_mixNode = commandBlock.CreateDSPNode <MixStereoPortsNode.Parameters, MixStereoPortsNode.SampleProviders, MixStereoPortsNode>();
            commandBlock.AddOutletPort(m_mixNode, 2);
            m_mixToOutputConnection = commandBlock.Connect(m_mixNode, 0, m_graph.RootDSP, 0);
            m_ildNode = commandBlock.CreateDSPNode <ReadIldBuffersNode.Parameters, ReadIldBuffersNode.SampleProviders, ReadIldBuffersNode>();
            unsafe
            {
                commandBlock.UpdateAudioKernel <SetReadIldBuffersNodePackedFrameBufferId, ReadIldBuffersNode.Parameters, ReadIldBuffersNode.SampleProviders, ReadIldBuffersNode>(
                    new SetReadIldBuffersNodePackedFrameBufferId {
                    ptr = (long *)m_packedFrameCounterBufferId.GetUnsafePtr()
                },
                    m_ildNode);
            }
            commandBlock.Complete();

            //Create queries
            m_aliveListenersQuery = Fluent.WithAll <AudioListener>(true).Build();
            m_deadListenersQuery  = Fluent.Without <AudioListener>().WithAll <ListenerGraphState>().Build();
            m_oneshotsToDestroyWhenFinishedQuery = Fluent.WithAll <AudioSourceOneShot>().WithAll <AudioSourceDestroyOneShotWhenFinished>(true).Build();
            m_oneshotsQuery = Fluent.WithAll <AudioSourceOneShot>().Build();
            m_loopedQuery   = Fluent.WithAll <AudioSourceLooped>().Build();

            //Force initialization of Burst
            commandBlock = m_graph.CreateCommandBlock();
            var dummyNode = commandBlock.CreateDSPNode <MixPortsToStereoNode.Parameters, MixPortsToStereoNode.SampleProviders, MixPortsToStereoNode>();

            StateVariableFilterNode.Create(commandBlock, StateVariableFilterNode.FilterType.Bandpass, 0f, 0f, 0f, 1);
            commandBlock.UpdateAudioKernel <MixPortsToStereoNodeUpdate, MixPortsToStereoNode.Parameters, MixPortsToStereoNode.SampleProviders, MixPortsToStereoNode>(
                new MixPortsToStereoNodeUpdate {
                leftChannelCount = 0
            },
                dummyNode);
            commandBlock.UpdateAudioKernel <ReadIldBuffersNodeUpdate, ReadIldBuffersNode.Parameters, ReadIldBuffersNode.SampleProviders, ReadIldBuffersNode>(new ReadIldBuffersNodeUpdate
            {
                ildBuffer = new IldBuffer(),
            },
                                                                                                                                                             m_ildNode);
            commandBlock.Cancel();
        }