File: convolve.alg

package info (click to toggle)
audacity 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 129,312 kB
  • sloc: ansic: 373,350; cpp: 276,880; sh: 56,060; python: 18,922; makefile: 10,309; lisp: 8,365; xml: 1,888; perl: 1,798; java: 1,551; asm: 545; pascal: 395; sed: 58; awk: 35
file content (60 lines) | stat: -rw-r--r-- 1,924 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(CONVOLVE-ALG
(NAME "convolve")
(SUPPORT-FUNCTIONS "
void h_reverse(sample_type *h, long len)
{
    sample_type temp;
    int i;
    
    for (i = 0; i < len; i++) {
        temp = h[i];
        h[i] = h[len - 1];
        h[len - 1] = temp;
        len--;
    }
}
")

(ARGUMENTS ("sound_type" "x_snd") ("sound_type" "h_snd") )
(TABLE "h_snd")
(START (MIN x_snd))
(NOT-IN-INNER-LOOP "h_snd")
(STATE 
        ("table_type" "table" "sound_to_table(h_snd)")
        ("sample_type *" "h_buf" "susp->table->samples")
        ("double" "length_of_h" "susp->table->length")
        ("long" "h_len" "(long) susp->length_of_h;
         h_reverse(susp->h_buf, susp->h_len)")
        ("long" "x_buf_len" "2 * susp->h_len")
        ("sample_type *" "x_buffer_pointer" 
         "calloc((2 * (susp->h_len)), sizeof(float))")
        ("sample_type *" "x_buffer_current" "susp->x_buffer_pointer")  )
(ALWAYS-SCALE x_snd)
(TERMINATE (MIN x_snd))
(LOGICAL-STOP (MIN x_snd))
(INNER-LOOP-LOCALS 
  "            long i; double sum;")
(INNER-LOOP "/* see if we've reached end of x_buffer */
            if ((x_buffer_pointer + x_buf_len) <= (x_buffer_current + h_len)) {
                /* shift x_buffer from current back to base */
                for (i = 1; i < h_len; i++) {
                    x_buffer_pointer[i-1] = x_buffer_current[i];
                }    
                /* this will be incremented back to x_buffer_pointer below */
                x_buffer_current = x_buffer_pointer - 1;
            }
    
            x_buffer_current++;
    
            x_buffer_current[h_len - 1] = x_snd;
    
            sum = 0.0;
            for (i = 0; i < h_len; i++) {
                sum += x_buffer_current[i] * h_buf[i];
            }
            output = (sample_type) sum")
(CONSTANT "h_buf" "h_len" "x_buf_len" "table")
(SAMPLE-RATE "x_snd->sr")
(FINALIZATION "    table_unref(susp->table); 
    free(susp->x_buffer_pointer);\n")
)