File: tapv.alg

package info (click to toggle)
audacity 1.2.4b-2.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 24,136 kB
  • ctags: 20,445
  • sloc: ansic: 139,567; cpp: 55,998; sh: 24,963; lisp: 3,772; makefile: 1,683; python: 272
file content (53 lines) | stat: -rw-r--r-- 1,990 bytes parent folder | download | duplicates (3)
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
(TAPV-ALG
(NAME "tapv")
(ARGUMENTS ("sound_type" "s1") ("double" "offset") ("sound_type" "vardelay")
           ("double" "maxdelay"))
(INLINE-INTERPOLATION T)
(INTERNAL-SCALING vardelay)
(ALWAYS-SCALE s1)
(START (MAX s1 vardelay))
(TERMINATE (MIN s1 vardelay))
(LOGICAL-STOP (MIN s1))
(STATE ("double" "offset" "offset * s1->sr")
       ("double" "vdscale" "vardelay->scale * s1->sr")
       ("double" "maxdelay" "maxdelay * s1->sr")
       ("long" "bufflen" "MAX(2, (long) (susp->maxdelay + 1.5))")
       ("long" "index" "susp->bufflen")
       ("sample_type *" "buffer" 
        "(sample_type *) calloc(susp->bufflen + 1, sizeof(sample_type))"))
(SAMPLE-RATE (MAX s1))
(CONSTANT "maxdelay" "offset" "vdscale" "buffer")
(INNER-LOOP-LOCALS "            double phase;
            long i;
")
(INNER-LOOP "        phase = vardelay * vdscale + offset;
        /* now phase should give number of samples of delay */
        if (phase < 0) phase = 0;
        else if (phase > maxdelay) phase = maxdelay;
        phase = (double) index - phase;
        /* now phase is a location in the buffer (before modulo) */

        /* Time out to update the buffer:
         * this is a tricky buffer: buffer[0] == buffer[bufflen]
         * the logical length is bufflen, but the actual length
         * is bufflen + 1 to allow for a repeated sample at the
         * end. This allows for efficient interpolation.
         */ 
        buffer[index++] = s1;
        if (index > bufflen) {
            buffer[0] = buffer[bufflen];
            index = 1;
        }

        /* back to the phase calculation: 
         * use conditional instead of modulo
         */
        if (phase < 0) phase += bufflen;
        i = (long) phase;    /* put integer part in i */
        phase -= (double) i; /* put fractional part in phase */	     
            output = (sample_type) (buffer[i] * (1.0 - phase) + 
                                    buffer[i + 1] * phase);")
(FINALIZATION "    free(susp->buffer);
")
)