File: tapf.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 (49 lines) | stat: -rw-r--r-- 1,757 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
(TAPF-ALG
(NAME "tapf")
(ARGUMENTS ("sound_type" "s1") ("double" "offset") ("sound_type" "vardelay")
           ("double" "maxdelay"))
(INLINE-INTERPOLATION T)
(STEP-FUNCTION "vardelay")
(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")
       ("long" "maxdelay" "(long)(maxdelay * s1->sr)")
       ("long" "bufflen" "MAX(2, (long) (susp->maxdelay + 0.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 "            long phase;
")
(INNER-LOOP "        phase = (long) (vardelay * vdscale + offset);
        /* now phase should give number of samples of delay */
        if (phase < 0) phase = 0;
        else if (phase > maxdelay) phase = maxdelay;
        phase = 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) {
            index = 0;
        }

        /* back to the phase calculation: 
         * use conditional instead of modulo
         */
        if (phase < 0) phase += bufflen;
        output = (sample_type) (buffer[phase]);")
(FINALIZATION "    free(susp->buffer);
")
)