devNotes 8-15-16 Note Collision Latency – Multi Voice – Multi Instrument – Filter Adjustment

https://www.eimacs.com/blog/2012/08/ball-of-whacks-puzzle/

Cool-Rubiks-Cubes-Google-Chrome-Edition

 

dfgdfgf


//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: This file contains C#/managed code bindings for the OpenVR interfaces
// This file is auto-generated, do not edit it.
//
//=============================================================================

using System;
using System.Runtime.InteropServices;
using Valve.VR;

namespace Valve.VR
{

[StructLayout(LayoutKind.Sequential)]
public struct IVRSystem
{
	[UnmanagedFunctionPointer(CallingConvention.StdCall)]
	internal delegate void _GetRecommendedRenderTargetSize(ref uint pnWidth, ref uint pnHeight);
	[MarshalAs(UnmanagedType.FunctionPtr)]
	internal _GetRecommendedRenderTargetSize GetRecommendedRenderTargetSize;

	[UnmanagedFunctionPointer(CallingConvention.StdCall)]
	internal delegate HmdMatrix44_t _GetProjectionMatrix(EVREye eEye, float fNearZ, float fFarZ, EGraphicsAPIConvention eProjType);
	[MarshalAs(UnmanagedType.FunctionPtr)]
	internal _GetProjectionMatrix GetProjectionMatrix;

	[UnmanagedFunctionPointer(CallingConvention.StdCall)]
	internal delegate void _GetProjectionRaw(EVREye eEye, ref float pfLeft, ref float pfRight, ref float pfTop, ref float pfBottom);
	[MarshalAs(UnmanagedType.FunctionPtr)]
	internal _GetProjectionRaw GetProjectionRaw;

	[UnmanagedFunctionPointer(CallingConvention.StdCall)]
	internal delegate DistortionCoordinates_t _ComputeDistortion(EVREye eEye, float fU, float fV);
	[MarshalAs(UnmanagedType.FunctionPtr)]
	internal _ComputeDistortion ComputeDistortion;

	[UnmanagedFunctionPointer(CallingConvention.StdCall)]
	internal delegate HmdMatrix34_t _GetEyeToHeadTransform(EVREye eEye);
	[MarshalAs(UnmanagedType.FunctionPtr)]
	internal _GetEyeToHeadTransform GetEyeToHeadTransform;

	[UnmanagedFunctionPointer(CallingConvention.StdCall)]
	internal delegate bool _GetTimeSinceLastVsync(ref float pfSecondsSinceLastVsync, ref ulong pulFrameCounter);
	[MarshalAs(UnmanagedType.FunctionPtr)]
	internal _GetTimeSinceLastVsync GetTimeSinceLastVsync;

	[UnmanagedFunctionPointer(CallingConvention.StdCall)]
	internal delegate int _GetD3D9AdapterIndex();
	[MarshalAs(UnmanagedType.FunctionPtr)]
	internal _GetD3D9AdapterIndex GetD3D9AdapterIndex;


using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;

[RequireComponent(typeof(AudioSource))]
public class Argos_Sound_Gen : MonoBehaviour
{
    AudioSource audioSource;

    public float estimatedLatency { get; protected set; }

    public int globalSampleRate;

    [Range(0, 5)]
    public double gain = 1;

    [Range(0.01f, 0.02f)]
    public double phase1base = 0.01;

    [Range(0.0f, 1f)]
    public double attack1 = 0.01;

    [Range(0.0f, 1f)]
    public double decay1 = 0.01;


    double phase1;


    double amp1;

    private double amp = 0.0F;
    private double phase = 0.0F;

    private int accent;
    private bool running = false;

    private float[] _freqs = { 249.66f, 264.505f, 280.235f, 296.9f, 314.55f, 333.255f, 353.075f, 374.07f, 396.31f, 419.875f, 444.845f, 471.295f, 499.32f };
    private float[] _dtime = { 0.004124562f, 0.00389302f, 0.003674579f, 0.003468248f, 0.003273644f, 0.003089948f, 0.002916472f,
                                0.002752773f, 0.00259828f, 0.002452483f, 0.002314815f, 0.002184885f, 0.002062281f};

    public void playNote(int idx, float vel)
    {
        time1 = accumTime;//Attack
        phasemult1 = idx;
        dTIME = _dtime[(int)phasemult1];
    }

    public void playNote(int idx)
    {
        time1 = accumTime;//Attack
        phasemult1 = idx;
        dTIME = _dtime[(int)phasemult1];
    }


    void Awake()
    {
        // Create an audio source.
        audioSource = gameObject.GetComponent<AudioSource>();
        audioSource.playOnAwake = false;
        audioSource.loop = true;
    }

    void Start()
    {

            globalSampleRate = AudioSettings.outputSampleRate;

    }

    void OnApplicationPause(bool paused)
    {

    }

    int count1 = 0;

    double phasemult1 = 3.0f;

    bool switch1 = true;

    double time1;

    double accumTime;

    bool aOn = true;

    double ampSamp(int voice, double sampTime)
    {
        amp = 0;

        if (voice == 1)
        {
            if (sampTime - time1 < attack1)
            {
                amp = CubicEaseIn(sampTime - time1, 0, 1, attack1);
            }
            else if (accumTime - time1 < attack1 + decay1)
            {
                amp = CubicEaseOut((sampTime - time1 - attack1), 1, -1, decay1);
            }
            else
            {
                amp = 0;
            }
        }
        return amp;
    }


    float dTIME = 0f;
    double dt;
    void OnAudioFilterRead(float[] data, int channels)
    {
        accumTime = (double)AudioSettings.dspTime;

        double samples = AudioSettings.dspTime * globalSampleRate;
        int dataLen = data.Length / channels;
        double deltTime = (AudioSettings.dspTime / samples);
        int n = 0;

        double a;

        double sampTime = accumTime;

        dt = deltTime / dTIME * 2f * Mathf.PI;

        while (n < dataLen)
        {
            sampTime += deltTime;

            a =  gain * ampSamp(1, sampTime)* Math.Sin(phase1);
 
           float x = (float)(a);
           int i = 0;

            while (i < channels)
            {
                data[n * channels + i] = x;
                i++;
            }

            phase1 += dt;
            if (phase1 > Math.PI * 2f) phase1 = 0f;

            n++;
        }
    }
    /// </summary>
    /// <param name= t  "current">how long into the ease are we</param>
    /// <param name= b  "initialValue">starting value if current were 0</param>
    /// <param name= c  "totalChange">total change in the value (not the end value, but the end - start)</param>
    /// <param name= d  "duration">the total amount of time (when current == duration, the returned value will == initial + totalChange)</param>
    /// <returns></returns>

    public static double CubicEaseOut(double t, double b, double c, double d)
    {
        if (t < d)
        {
            return c * ((t = t / d - 1) * t * t + 1) + b;
        }
        else
        {
            return b + c;
        }
    }

    public static double CubicEaseIn(double t, double b, double c, double d)
    {
        if (t < d)
        {
            return c * (t /= d) * t * t + b;
        }
        else
        {
            return b + c;
        }
    }
}

 

 

 

 

Screenshot_194.6111_