Beispiel #1
0
    void SendCommand(OscWave wave, float frequency, float amplitude, float cutoff, float q, float filterAmplitude, float pan)
    {
        DSPCommandBlock commandBlock = m_driver.m_graph.CreateCommandBlock();

        commandBlock.SetFloat <OscParameters, OscProviders, OscillatorNode>(m_oscNode, OscParameters.Wave, (float)wave);
        commandBlock.SetFloat <OscParameters, OscProviders, OscillatorNode>(m_oscNode, OscParameters.Frequency, frequency);
        commandBlock.SetFloat <SVFParameters, SVFProviders, SVFNode>(m_filterNode, SVFParameters.Cutoff, cutoff);
        commandBlock.SetFloat <SVFParameters, SVFProviders, SVFNode>(m_filterNode, SVFParameters.Q, q);
        commandBlock.SetFloat <SVFParameters, SVFProviders, SVFNode>(m_filterNode, SVFParameters.Amplitude, filterAmplitude);
        commandBlock.SetFloat <VCAParameters, VCAProviders, VCANode>(m_vcaNode, VCAParameters.Amplitude, amplitude);
        commandBlock.SetFloat <MonoToStereoParameters, MonoToStereoProviders, MonoToStereoNode>(m_stereoNode, MonoToStereoParameters.Pan, pan);
        commandBlock.Complete();
    }
Beispiel #2
0
    private void OnDestroy()
    {
        // Disconnect all the node input/outputs
        DSPCommandBlock commandBlock = m_driver.m_graph.CreateCommandBlock();

        commandBlock.ReleaseDSPNode(m_stereoNode);
        commandBlock.ReleaseDSPNode(m_vcaNode);
        commandBlock.ReleaseDSPNode(m_filterNode);
        commandBlock.ReleaseDSPNode(m_oscNode);
        commandBlock.Complete();

        // Deallocate
        m_driver.Dispose();
        m_buffer.Dispose();
    }
Beispiel #3
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();
    }