コード例 #1
0
    // Use this for initialization
    void Start()
    {
        // Hook up trombone components
        sampleRate = AudioSettings.outputSampleRate;// / downsampling;
        bufferSize = AudioSettings.GetConfiguration().dspBufferSize;
        glottis    = new Glottis(this);
        tract      = new Tract(this, glottis);
        tractUI    = new TractUI(this, tract);

        aspirateFilter  = BiQuadFilter.BandPassFilterConstantSkirtGain(sampleRate, 500, 0.5f);
        fricativeFilter = BiQuadFilter.BandPassFilterConstantSkirtGain(sampleRate, 1000, 0.5f);

        SetDownsamplingLevel(downsamplingLevel);

        // Dispatch thread if requested
        if (DO_THREADING)
        {
            _thread = new Thread(ThreadedWork);
            _thread.IsBackground = true;
            _thread.Start();
        }
    }
コード例 #2
0
    public Tract(Trombone trombone, Glottis glottis)
    {
        this.trombone = trombone;
        this.glottis  = glottis;

        blockTime = (float)trombone.bufferSize / trombone.sampleRate;

        bladeStart     = (int)Mathf.Floor(bladeStart * (float)n / 44.0f);
        tipStart       = (int)Mathf.Floor(tipStart * (float)n / 44.0f);
        lipStart       = (int)Mathf.Floor(lipStart * (float)n / 44.0f);
        diameter       = new float[n];
        restDiameter   = new float[n];
        targetDiameter = new float[n];
        for (int i = 0; i < n; i++)
        {
            float diam = 0.0f;
            if (i < 7.0f * n / 44.0f - 0.5f)
            {
                diam = 0.6f;
            }
            else if (i < 12.0f * n / 44.0f)
            {
                diam = 1.1f;
            }
            else
            {
                diam = 1.5f;
            }
            diameter[i] = restDiameter[i] = targetDiameter[i] = diam;
        }
        R               = new float[n];
        L               = new float[n];
        reflection      = new float[n + 1];
        newReflection   = new float[n + 1];
        junctionOutputR = new float[n + 1];
        junctionOutputL = new float[n + 1];
        A               = new float[n];

        noseLength          = (int)Mathf.Floor(28.0f * n / 44.0f);
        noseStart           = n - noseLength + 1;
        noseR               = new float[noseLength];
        noseL               = new float[noseLength];
        noseJunctionOutputR = new float[noseLength + 1];
        noseJunctionOutputL = new float[noseLength + 1];
        noseReflection      = new float[noseLength + 1];
        noseDiameter        = new float[noseLength];
        noseA               = new float[noseLength];
        for (int i = 0; i < noseLength; i++)
        {
            float diam;
            float d = 2.0f * ((float)i / noseLength);
            if (d < 1.0f)
            {
                diam = 0.4f + 1.6f * d;
            }
            else
            {
                diam = 0.5f + 1.5f * (2.0f - d);
            }
            diam            = Mathf.Min(diam, 1.9f);
            noseDiameter[i] = diam;
        }
        newReflectionLeft = newReflectionRight = newReflectionNose = 0;
        CalculateReflections();
        CalculateNoseReflections();
        noseDiameter[0] = velumTarget;
    }