Rev 265 | Rev 493 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 265 | Rev 269 | ||
---|---|---|---|
1 | /****************************************** |
1 | /****************************************** |
2 | * |
2 | * |
3 | * Voice output for MK |
3 | * Voice output for MK |
4 | * |
4 | * |
5 | * Author: Marcus -LiGi- Bueschleb |
5 | * Author: Marcus -LiGi- Bueschleb |
6 | * |
6 | * |
7 | *******************************************/ |
7 | *******************************************/ |
8 | 8 | ||
9 | import javax.microedition.media.*; |
9 | import javax.microedition.media.*; |
10 | import javax.microedition.media.control.*; |
10 | import javax.microedition.media.control.*; |
11 | import java.util.*; |
11 | import java.util.*; |
12 | import java.io.*; |
12 | import java.io.*; |
13 | 13 | ||
14 | 14 | ||
15 | public class MKStatusVoice |
15 | public class MKStatusVoice |
16 | implements Runnable,PlayerListener |
16 | implements Runnable,PlayerListener |
17 | { |
17 | { |
18 | 18 | ||
19 | org.ligi.ufo.MKCommunicator mk=null; |
19 | org.ligi.ufo.MKCommunicator mk=null; |
20 | DUBwiseCanvas canvas=null; |
20 | DUBwiseCanvas canvas=null; |
21 | Player player; |
21 | Player player; |
22 | 22 | ||
23 | public final int PLAYERSTATE_IDLE=0; |
23 | public final int PLAYERSTATE_IDLE=0; |
24 | public final int PLAYERSTATE_PLAYING=1; |
24 | public final int PLAYERSTATE_PLAYING=1; |
25 | public final int PLAYERSTATE_FIN=2; |
25 | public final int PLAYERSTATE_FIN=2; |
26 | 26 | ||
27 | 27 | ||
28 | public int volume=100; |
28 | public int volume=100; |
29 | public int delay=5; |
29 | public int delay=5; |
30 | 30 | ||
31 | int act_player_state=PLAYERSTATE_IDLE; |
31 | int act_player_state=PLAYERSTATE_IDLE; |
32 | VolumeControl vc; |
32 | VolumeControl vc; |
33 | 33 | ||
34 | public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas) |
34 | public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas) |
35 | { |
35 | { |
36 | canvas=_canvas; |
36 | canvas=_canvas; |
37 | mk=_mk; |
37 | mk=_mk; |
38 | new Thread( this ).start(); // fire up main Thread |
38 | new Thread( this ).start(); // fire up main Thread |
39 | } |
39 | } |
40 | 40 | ||
41 | public void playerUpdate(Player player, String event, Object data) |
41 | public void playerUpdate(Player player, String event, Object data) |
42 | { |
42 | { |
43 | if(event == PlayerListener.END_OF_MEDIA) { |
43 | if(event == PlayerListener.END_OF_MEDIA) { |
44 | try { |
44 | try { |
45 | defplayer(); |
45 | defplayer(); |
46 | } |
46 | } |
47 | catch(MediaException me) { } |
47 | catch(MediaException me) { } |
48 | act_player_state=PLAYERSTATE_FIN; |
48 | act_player_state=PLAYERSTATE_FIN; |
49 | player=null; |
49 | player=null; |
50 | 50 | ||
51 | } |
51 | } |
52 | } |
52 | } |
53 | 53 | ||
54 | void defplayer() throws MediaException { |
54 | void defplayer() throws MediaException { |
55 | if (player != null) { |
55 | if (player != null) { |
56 | if(player.getState() == Player.STARTED) { |
56 | if(player.getState() == Player.STARTED) { |
57 | player.stop(); |
57 | player.stop(); |
58 | } |
58 | } |
59 | if(player.getState() == Player.PREFETCHED) { |
59 | if(player.getState() == Player.PREFETCHED) { |
60 | player.deallocate(); |
60 | player.deallocate(); |
61 | } |
61 | } |
62 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
62 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
63 | player.close(); |
63 | player.close(); |
64 | } |
64 | } |
65 | } |
65 | } |
66 | player = null; |
66 | player = null; |
67 | } |
67 | } |
68 | 68 | ||
69 | 69 | ||
70 | public void start_playing(String name) |
70 | public void start_playing(String name) |
71 | { |
71 | { |
72 | try { |
72 | try { |
73 | 73 | ||
74 | try { |
74 | try { |
75 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
75 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
76 | } |
76 | } |
77 | catch (Exception e) { |
77 | catch (Exception e) { |
78 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
78 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
79 | } |
79 | } |
80 | player.addPlayerListener(this); |
80 | player.addPlayerListener(this); |
81 | player.realize(); |
81 | player.realize(); |
82 | act_player_state=PLAYERSTATE_PLAYING; |
82 | act_player_state=PLAYERSTATE_PLAYING; |
83 | 83 | ||
84 | vc = (VolumeControl) player.getControl("VolumeControl"); |
84 | vc = (VolumeControl) player.getControl("VolumeControl"); |
85 | if(vc != null) { |
85 | if(vc != null) { |
86 | vc.setLevel(volume); |
86 | vc.setLevel(volume); |
87 | } |
87 | } |
88 | 88 | ||
89 | player.prefetch(); |
89 | player.prefetch(); |
90 | player.setLoopCount(1); |
90 | player.setLoopCount(1); |
91 | player.start(); |
91 | player.start(); |
92 | } |
92 | } |
93 | catch (Exception e) { |
93 | catch (Exception e) { |
94 | 94 | ||
95 | } |
95 | } |
96 | } |
96 | } |
97 | 97 | ||
98 | public void wait_for_end() |
98 | public void wait_for_end() |
99 | { |
99 | { |
100 | while (act_player_state!=PLAYERSTATE_FIN) |
100 | while (act_player_state!=PLAYERSTATE_FIN) |
101 | { |
101 | { |
102 | try { Thread.sleep(5); } |
102 | try { Thread.sleep(5); } |
103 | catch (Exception e) { } |
103 | catch (Exception e) { } |
104 | } |
104 | } |
105 | 105 | ||
106 | 106 | ||
107 | } |
107 | } |
108 | 108 | ||
109 | int info_from_debug_set=-1; |
109 | int info_from_debug_set=-1; |
110 | int volt_timeout=0; |
110 | int volt_timeout=0; |
111 | 111 | ||
112 | public int last_alt=-1; |
112 | public int last_alt=-1; |
113 | 113 | ||
114 | public void run() |
114 | public void run() |
115 | { |
115 | { |
116 | while(true) |
116 | while(true) |
117 | { |
117 | { |
118 | if (mk.connected&&(canvas.settings.do_sound)&&(mk.UBatt()!=-1)&&(!mk.force_disconnect)) |
118 | if (mk.connected&&(canvas.settings.do_sound)&&(mk.UBatt()!=-1)&&(!mk.force_disconnect)) |
119 | { |
119 | { |
120 | 120 | ||
121 | if (info_from_debug_set!=mk.stats.debug_data_count) |
121 | if (info_from_debug_set!=mk.stats.debug_data_count) |
122 | { // only when newdata |
122 | { // only when newdata |
123 | 123 | ||
124 | if (canvas.settings.do_volts_sound&&(volt_timeout--<0)) |
124 | if (canvas.settings.do_volts_sound&&(volt_timeout--<0)) |
125 | { |
125 | { |
126 | volt_timeout=delay*10; |
126 | volt_timeout=delay*10; |
127 | int ubatt=mk.UBatt(); |
127 | int ubatt=mk.UBatt(); |
128 | info_from_debug_set=mk.stats.debug_data_count; |
128 | info_from_debug_set=mk.stats.debug_data_count; |
129 | start_playing(""+(ubatt/10)); |
129 | start_playing(""+(ubatt/10)); |
130 | wait_for_end(); |
130 | wait_for_end(); |
131 | 131 | ||
132 | if((ubatt%10)!=0) |
132 | if((ubatt%10)!=0) |
133 | { |
133 | { |
134 | start_playing("komma"); |
134 | start_playing("komma"); |
135 | wait_for_end(); |
135 | wait_for_end(); |
136 | start_playing(""+(ubatt%10)); |
136 | start_playing(""+(ubatt%10)); |
137 | wait_for_end(); |
137 | wait_for_end(); |
138 | } |
138 | } |
139 | start_playing("volt"); |
139 | start_playing("volt"); |
140 | wait_for_end(); |
140 | wait_for_end(); |
141 | } |
141 | } |
142 | 142 | ||
143 | 143 | ||
144 | 144 | ||
145 | if (canvas.settings.do_altimeter_sound) |
145 | if (canvas.settings.do_altimeter_sound) |
146 | { |
146 | { |
147 | if (last_alt==-1) last_alt=mk.Alt(); |
147 | if (last_alt==-1) last_alt=mk.Alt(); |
148 | int alt_diff=10; |
- | |
- | 148 | ||
149 | 149 | ||
150 | if (last_alt>mk.Alt()+alt_diff) |
150 | if (last_alt>mk.Alt()+canvas.settings.altsteps) |
151 | { |
151 | { |
152 | start_playing("down"); |
152 | start_playing("down"); |
153 | wait_for_end(); |
153 | wait_for_end(); |
154 | last_alt-=alt_diff; |
154 | last_alt-=canvas.settings.altsteps; |
155 | } |
155 | } |
156 | if (last_alt<mk.Alt()-alt_diff) |
156 | if (last_alt<mk.Alt()-canvas.settings.altsteps) |
157 | 157 | ||
158 | { |
158 | { |
159 | start_playing("up"); |
159 | start_playing("up"); |
160 | wait_for_end(); |
160 | wait_for_end(); |
161 | last_alt+=alt_diff; |
161 | last_alt+=canvas.settings.altsteps; |
162 | } |
162 | } |
163 | } |
163 | } |
164 | else |
164 | else |
165 | last_alt=-1; |
165 | last_alt=-1; |
166 | } |
166 | } |
167 | 167 | ||
168 | } |
168 | } |
169 | 169 | ||
170 | try { |
170 | try { |
171 | Thread.sleep(100); |
171 | Thread.sleep(100); |
172 | /* |
172 | /* |
173 | if (delay<1) |
173 | if (delay<1) |
174 | Thread.sleep(1000); |
174 | Thread.sleep(1000); |
175 | else |
175 | else |
176 | Thread.sleep(delay*1000); |
176 | Thread.sleep(delay*1000); |
177 | */ |
177 | */ |
178 | } |
178 | } |
179 | catch (Exception e) { } |
179 | catch (Exception e) { } |
180 | 180 | ||
181 | } |
181 | } |
182 | } |
182 | } |
183 | 183 | ||
184 | 184 | ||
185 | 185 | ||
186 | } |
186 | } |
187 | 187 |