Ejemplo n.º 1
0
    void Update()
    {
        // Single element native array used to share structs with the job.
        var tempFilter = new NativeArray <MultibandFilter>
                             (1, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        var tempLevel = new NativeArray <float4>
                            (1, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        // Filter update
        _filter.SetParameter(960.0f / _selector.SampleRate, 0.15f);
        tempFilter[0] = _filter;

        // Run the job on the main thread.
        new FilterRmsJob {
            Input  = _selector.AudioDataSlice,
            Filter = tempFilter, Output = tempLevel
        }.Run();

        // Preserve the filter state.
        _filter = tempFilter[0];

        // Meter scale
        var sc = math.max(0, _range + tempLevel[0]) / _range;

        // Apply to rect-transforms.
        _bypassMeter.transform.localScale   = new Vector3(sc.x, 1, 1);
        _lowPassMeter.transform.localScale  = new Vector3(sc.y, 1, 1);
        _bandPassMeter.transform.localScale = new Vector3(sc.z, 1, 1);
        _highPassMeter.transform.localScale = new Vector3(sc.w, 1, 1);

        // Cleaning the temporaries up.
        tempFilter.Dispose();
        tempLevel.Dispose();
    }
Ejemplo n.º 2
0
    float4 ExecuteDFT(ref NativeSlice <float> slice, int sampleRate)
    {
        // Single element native array used to share structs with the job.
        var tempFilter = new NativeArray <MultibandFilter>
                             (1, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        var tempLevel = new NativeArray <float4>
                            (1, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        // Filter update
        _filter.SetParameter(_bandPassFreq / sampleRate, _bandPassQ);
        tempFilter[0] = _filter;

        // Run the job on the main thread.
        new FilterRmsJob
        {
            Input  = slice,
            Filter = tempFilter,
            Output = tempLevel
        }.Run();

        // Preserve the filter state.
        _filter = tempFilter[0];

        float4 sc = tempLevel[0];

        tempFilter.Dispose();
        tempLevel.Dispose();

        return(sc);
    }
Ejemplo n.º 3
0
    private void Update()
    {
        // Single element native array used to share structs with the job.
        var tempFilter = new NativeArray <MultibandFilter>
                             (1, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        var tempLevel = new NativeArray <float4>
                            (1, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        // Filter update
        float sampleRate = _source.clip.frequency;

        _filter.SetParameter(_bandPassFreq / sampleRate, _bandPassQ);
        tempFilter[0] = _filter;

        _source.GetOutputData(_rawSamples, 0);
        var samples      = new NativeArray <float>(_rawSamples, Allocator.TempJob);
        var sliceSamples = new NativeSlice <float>(samples);


        // Run the job on the main thread.
        new FilterRmsJob
        {
            Input  = sliceSamples,
            Filter = tempFilter,
            Output = tempLevel
        }.Run();

        // Preserve the filter state.
        _filter = tempFilter[0];

        // Meter scale
        var sc = math.max(0, _range + tempLevel[0]) / _range;

        // Apply to rect-transforms.
        _bypassMeter.transform.localScale   = new Vector3(sc.x, 1, 1);
        _lowPassMeter.transform.localScale  = new Vector3(sc.y, 1, 1);
        _bandPassMeter.transform.localScale = new Vector3(sc.z, 1, 1);
        _highPassMeter.transform.localScale = new Vector3(sc.w, 1, 1);

        // Cleaning the temporaries up.
        tempFilter.Dispose();
        tempLevel.Dispose();

        samples.Dispose();
    }