Debian Codegraph @

EXAMPLES/stapgames/tapset/audio.stp

raw
1 # systemtap audio tapset
2 # Copyright (C) 2008 Masami Hiramatsu <[email protected]>
3 #
4 # This file is free software and is distributed under the terms of the GNU
5 # General Public License (GPL); either version 2, or (at your option) any
6 # later version.
7
8 %{
9 #include <linux/vt_kern.h>
10 %}
11
12 %( kernel_v >= "2.6.25" %?
13 function game_beep(hz:long, ms:long)
14 %{
15 unsigned int tick = msecs_to_jiffies((unsigned int)THIS->ms);
16 kd_mksound((unsigned int)THIS->hz, tick);
17 %}
18 %)
19
20 function game_nobeep()
21 {
22 game_beep(0,0)
23 }
24
25 global __GM_scale
26 global __GM_merody
27 global __GM_merody_nth
28 global __GM_merody_seq
29 global __GM_merody_cnt
30
31 probe begin(-1001) {
32 __GM_scale["c"] = 262
33 __GM_scale["c+"] = 277
34 __GM_scale["d"] = 294
35 __GM_scale["d+"] = 311
36 __GM_scale["e"] = 330
37 __GM_scale["f"] = 349
38 __GM_scale["f+"] = 370
39 __GM_scale["g"] = 392
40 __GM_scale["g+"] = 415
41 __GM_scale["a"] = 440
42 __GM_scale["a+"] = 466
43 __GM_scale["b"] = 494
44 delete __GM_merody
45 }
46
47 function game_tone(tone:string, nth:long, ms:long)
48 {
49 if ([tone] in __GM_scale) {
50 tone2 = __GM_scale[tone];
51 for (i=0;i<nth-3;i++) tone2*=2
52 for (i=0;i>nth-3;i--) tone2/=2
53 game_beep(tone2, ms)
54 }
55 }
56
57 function game_merody(merody:string)
58 {
59 i = 0
60 delete __GM_merody
61 c = tokenize(merody, " ")
62 while (c != "") {
63 __GM_merody[i, 0] = c
64 c = tokenize("",",")
65 __GM_merody[i, 1] = c
66 c = tokenize(""," ")
67 i++
68 }
69 __GM_merody_seq = 0
70 __GM_merody_nth = 3
71 __GM_merody_cnt = 1
72 }
73
74 probe timer.ms(64) {
75 if (__GM_merody_cnt-- > 0) next;
76 seq = __GM_merody_seq;
77 while ([seq, 0] in __GM_merody) {
78 c = __GM_merody[seq, 0]
79 l = strtol(__GM_merody[seq, 1], 10)
80 seq++
81 if (c == ">") {
82 __GM_merody_nth += l
83 } else if (c == "<" ) {
84 __GM_merody_nth -= l
85 } else {
86 break;
87 }
88 }
89 game_tone(c, __GM_merody_nth, l*64)
90 __GM_merody_cnt = l
91 __GM_merody_seq = seq
92 }
93