File: sampler.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 (62 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download | duplicates (2)
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
61
62
(SAMPLER-ALG
(NAME "sampler")
(ARGUMENTS ("sound_type" "s") ("double" "step") ("double" "loop_start") 
        ("rate_type" "sr") ("double" "hz") ("time_type" "t0") 
        ("sound_type" "s_fm") ("long" "npoints"))
(TABLE "s")
(NOT-IN-INNER-LOOP "s")
(STATE 
       ("double" "loop_to" "loop_start * s->sr")
       ("table_type" "the_table" "sound_to_table(s)")
       ("sample_type *" "table_ptr" "susp->the_table->samples")
       ("double" "table_len" "susp->the_table->length;")
       ("double" "phase" "0.0")
       ("double" "ph_incr" "(s->sr / sr) * hz / step_to_hz(step);
    s_fm->scale = (sample_type) (s_fm->scale * (susp->ph_incr / hz));
    /* make sure parameters are ok
     *  the table must have samples
     *  the loop_start must be before the end of the table
     *  ph_incr must be positive
     *  sr should be positive
     */
    { long index = (long) susp->loop_to;
      double frac = susp->loop_to - index;
       if (susp->the_table->length <= 1) { 
             xlfail(\"sampler table length <= 1\");
       }
      if (index > round(susp->table_len) - 2 ||
          index < 0) {
          xlfail(\"sampler loop start not within samples\");
      }
      if (susp->ph_incr <= 0) {
          xlfail(\"sampler phase increment <= 0\");
      }
      if (sr <= 0) {
          xlfail(\"sampler sample rate <= 0\");
      }
      /* copy interpolated start to last entry */
      susp->table_ptr[round(susp->table_len)] =
          (sample_type) (susp->table_ptr[index] * (1.0 - frac) + 
                         susp->table_ptr[index + 1] * frac);}")
 )

(ALWAYS-SCALE s_fm)
(STEP-FUNCTION s_fm)
(TERMINATE (MIN s_fm))
(LOGICAL-STOP (MIN s_fm))
(INNER-LOOP-LOCALS "	    long table_index;
            double x1;
")
(INNER-LOOP "table_index = (long) phase;
            x1 = table_ptr[table_index];
            output = (sample_type) (x1 + (phase - table_index) * 
                          (table_ptr[table_index + 1] - x1));
            phase += ph_incr + s_fm;
            while (phase > table_len) phase -= (table_len - loop_to);
            /* watch out for negative frequencies! */
            if (phase < 0) phase = 0")
(CONSTANT "ph_incr" "table_len" "table_ptr" "loop_to")
(SAMPLE-RATE "sr")
(FINALIZATION "    table_unref(susp->the_table);\n")
)