⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 note.c

📁 dsp AD公司ADSP21的代码,里面有FFT FIR IIR EQULIZER G722_21F 等可以在项目中直接应用的代码.此代码的来源是ADI公司自己出版的书籍,此书在美国购得
💻 C
字号:
#include <stdlib.h>
#include <math.h>
#include "rtdspc.h"

/* Function to generate samples from a second order oscillator */

/* key constant is 1/12 */
#define KEY_CONSTANT 0.083333333333333

/* this sets the A above middle C reference frequency of 440 Hz */
#define TWO_PI_DIV_FS_440  (880.0 * PI / SAMPLE_RATE)

/* cw is the cosine constant required for fast changes of envelope */
/* a and b are the coefficients for the difference equation */
/* y1 and y0 are the history values */
/* t is time index for this note */
/* cindex is the index into rate and tbreak arrays (reset when t=0) */

typedef struct {
    int key,t,cindex;
    float cw,a,b;
    float y1,y0;
} NOTE_STATE;

/*
key:
    semi-tone pitch to generate,
    number 69 will give A above middle C at 440 Hz.
rate_array:
    rate constants determines decay or rise of envelope (close to 1)
tbreak_array:
    determines time index when to change rate
*/

/* NOTE_STATE structure, time break point array, rate parameter array */

float note(NOTE_STATE *s,int *tbreak_array,float *rate_array)
{
    register int ti,ci;
    float wosc,rate,out;

    ti = s->t;
/* t=0 re-start case, set state variables */
    if(!ti) {
        wosc = TWO_PI_DIV_FS_440 * pow(2.0,(s->key-69) * KEY_CONSTANT);
        s->cw = 2.0 * cos(wosc);
        rate = rate_array[0];
        s->a = s->cw * rate;     /* rate change */
        s->b = -rate * rate;
        s->y0 = 0.0;
        out = rate*sin(wosc);
        s->cindex = 0;
    }
    else {
        ci = s->cindex;
    /* rate change case */
        if(ti == tbreak_array[ci]) {
            rate = rate_array[++ci];
            s->a = s->cw * rate;
            s->b = -rate * rate;
            s->cindex = ci;
        }

    /* make new sample */
        out = s->a * s->y1 + s->b * s->y0;
        s->y0 = s->y1;
    }
    s->y1 = out;
    s->t = ++ti;
    return(out);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -