• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Mar 31st, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. #include <stdlib.h>
3. #include <math.h>
4. #define PI (3.14159265358979323846)
5. #define Q 32768
6.
7. long s1, s2, amp;
8. long a, b, a_base;
9. long sa, sa1, sa2, sb, sb1, sb2;
10. float r;
11.
12.
13. void genIIR(float freq) {
14.     a = round(2 * r * cos(2*PI * freq)*Q);
15.     b = round(-r * r * Q);
16.     sa2 = 0;
17.     sa1 = round(sin(2 * PI * freq)*Q);
18. }
19.
20. void genIIRBase(float freq) {
21.     a_base = round(2 * r * cos(2*PI * freq)*Q);
22.     b = round(-r * r * Q);
23.     sb2 = 0;
24.     sb1 = round(sin(2 * PI * freq)*Q);
25. }
26.
27. void getBase() {
28.     sb = (a_base * sb1 >> 15) + (b * sb2 >> 15);
29.     sb2 = sb1;
30.     sb1 = sb;
31. }
32.
33. void getSample() {
34.     sa = (a * sa1 >> 15) + (b * sa2 >> 15);
35.     sa2 = sa1;
36.     sa1 = sa;
37. }
38.
39. int main() {
40.     FILE *fptrIn, *fptrOut;
41.
42.     amp = 32000;
43.     r = 1.0f;
44.     float f_sampl = 48000.0;
45.
46.     const float f_selected = 1336.0/f_sampl;
47.         const float f_tab[] = {
48.             697.0/f_sampl,
49.             770.0/f_sampl,
50.             852.0/f_sampl,
51.             941.0/f_sampl
52.             };
53.
54.
55.     fptrIn = fopen("dataIn.txt", "r");
56.     if (fptrIn == NULL) {
57.         printf("Error! Problem with dataIn file!");
58.         exit(1);
59.     }
60.     fptrOut = fopen("dataOut.txt", "w");
61.     if (fptrOut == NULL) {
62.         printf("Error! Problem with dataOut file!");
63.         exit(1);
64.     }
65.
66.     {
67.         genIIRBase(f_selected);
68.         int j = 0;
69.         for (int i = 0; i < 48000; i++) {
70.             if (i % 12000 == 0) {
71.                 genIIR(f_tab[j]);
72.                 j++;
73.             }
74.             getBase();
75.             getSample();
76.
77.             s1 = amp * sb;
78.             s2 = amp * sa;
79.             fprintf(fptrOut, "%d\n", (int) (s1 + s2));
80.         }
81.     }
82.
83.     fclose(fptrIn);
84.     fclose(fptrOut);
85.
86.     printf("Hello world!\n");
87.     return 0;
88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top