ToneGenerator.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.media;
18
19
20
21/**
22 * This class provides methods to play DTMF tones (ITU-T Recommendation Q.23),
23 * call supervisory tones (3GPP TS 22.001, CEPT) and proprietary tones (3GPP TS 31.111).
24 * Depending on call state and routing options, tones are mixed to the downlink audio
25 * or output to the speaker phone or headset.
26 * This API is not for generating tones over the uplink audio path.
27 */
28public class ToneGenerator
29{
30
31    /* Values for toneType parameter of ToneGenerator() constructor */
32    /*
33     * List of all available tones: These constants must be kept consistant with
34     * the enum in ToneGenerator C++ class.     */
35
36	/**
37     * DTMF tone for key 0: 1336Hz, 941Hz, continuous</p>
38     *
39     * @see #ToneGenerator(int, int)
40     */
41    public static final int TONE_DTMF_0 = 0;
42    /**
43     * DTMF tone for key 1: 1209Hz, 697Hz, continuous
44     *
45     * @see #ToneGenerator(int, int)
46     */
47    public static final int TONE_DTMF_1 = 1;
48    /**
49     * DTMF tone for key 2: 1336Hz, 697Hz, continuous
50     *
51     * @see #ToneGenerator(int, int)
52     */
53   public static final int TONE_DTMF_2 = 2;
54   /**
55    * DTMF tone for key 3: 1477Hz, 697Hz, continuous
56    *
57    * @see #ToneGenerator(int, int)
58    */
59    public static final int TONE_DTMF_3 = 3;
60    /**
61     * DTMF tone for key 4: 1209Hz, 770Hz, continuous
62     *
63     * @see #ToneGenerator(int, int)
64     */
65    public static final int TONE_DTMF_4 = 4;
66    /**
67     * DTMF tone for key 5: 1336Hz, 770Hz, continuous
68     *
69     * @see #ToneGenerator(int, int)
70     */
71    public static final int TONE_DTMF_5 = 5;
72    /**
73     * DTMF tone for key 6: 1477Hz, 770Hz, continuous
74     *
75     * @see #ToneGenerator(int, int)
76     */
77    public static final int TONE_DTMF_6 = 6;
78    /**
79     * DTMF tone for key 7: 1209Hz, 852Hz, continuous
80     *
81     * @see #ToneGenerator(int, int)
82     */
83    public static final int TONE_DTMF_7 = 7;
84    /**
85     * DTMF tone for key 8: 1336Hz, 852Hz, continuous
86     *
87     * @see #ToneGenerator(int, int)
88     */
89    public static final int TONE_DTMF_8 = 8;
90    /**
91     * DTMF tone for key 9: 1477Hz, 852Hz, continuous
92     *
93     * @see #ToneGenerator(int, int)
94     */
95    public static final int TONE_DTMF_9 = 9;
96    /**
97     * DTMF tone for key *: 1209Hz, 941Hz, continuous
98     *
99     * @see #ToneGenerator(int, int)
100     */
101    public static final int TONE_DTMF_S = 10;
102    /**
103     * DTMF tone for key #: 1477Hz, 941Hz, continuous
104     *
105     * @see #ToneGenerator(int, int)
106     */
107    public static final int TONE_DTMF_P = 11;
108    /**
109     * DTMF tone for key A: 1633Hz, 697Hz, continuous
110     *
111     * @see #ToneGenerator(int, int)
112     */
113    public static final int TONE_DTMF_A = 12;
114    /**
115     * DTMF tone for key B: 1633Hz, 770Hz, continuous
116     *
117     * @see #ToneGenerator(int, int)
118     */
119    public static final int TONE_DTMF_B = 13;
120    /**
121     * DTMF tone for key C: 1633Hz, 852Hz, continuous
122     *
123     * @see #ToneGenerator(int, int)
124     */
125    public static final int TONE_DTMF_C = 14;
126    /**
127     * DTMF tone for key D: 1633Hz, 941Hz, continuous
128     *
129     * @see #ToneGenerator(int, int)
130     */
131    public static final int TONE_DTMF_D = 15;
132    /**
133     * Call supervisory tone, Dial tone: 425Hz, continuous
134     *
135     * @see #ToneGenerator(int, int)
136     */
137    public static final int TONE_SUP_DIAL = 16;
138    /**
139     * Call supervisory tone, Busy: 425Hz, 500ms ON, 500ms OFF...
140     *
141     * @see #ToneGenerator(int, int)
142     */
143    public static final int TONE_SUP_BUSY = 17;
144    /**
145     * Call supervisory tone, Congestion: 425Hz, 200ms ON, 200ms OFF...
146     *
147     * @see #ToneGenerator(int, int)
148     */
149    public static final int TONE_SUP_CONGESTION = 18;
150    /**
151     * Call supervisory tone, Radio path acknowlegment : 425Hz, 200ms ON
152     *
153     * @see #ToneGenerator(int, int)
154     */
155    public static final int TONE_SUP_RADIO_ACK = 19;
156    /**
157     * Call supervisory tone, Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts
158     *
159     * @see #ToneGenerator(int, int)
160     */
161    public static final int TONE_SUP_RADIO_NOTAVAIL = 20;
162    /**
163     * Call supervisory tone, Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF...
164     *
165     * @see #ToneGenerator(int, int)
166     */
167    public static final int TONE_SUP_ERROR = 21;
168    /**
169     * Call supervisory tone, Call Waiting: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF...
170     *
171     * @see #ToneGenerator(int, int)
172     */
173    public static final int TONE_SUP_CALL_WAITING = 22;
174    /**
175     * Call supervisory tone, Ring Tone: 425Hz, 1s ON, 4s OFF...
176     *
177     * @see #ToneGenerator(int, int)
178     */
179    public static final int TONE_SUP_RINGTONE = 23;
180    /**
181     * Proprietary tone, general beep: 400Hz+1200Hz, 35ms ON
182     *
183     * @see #ToneGenerator(int, int)
184     */
185    public static final int TONE_PROP_BEEP = 24;
186    /**
187     * Proprietary tone, positive acknowlegement: 1200Hz, 100ms ON, 100ms OFF 2 bursts
188     *
189     * @see #ToneGenerator(int, int)
190     */
191    public static final int TONE_PROP_ACK = 25;
192    /**
193     * Proprietary tone, negative acknowlegement: 300Hz+400Hz+500Hz, 400ms ON
194     *
195     * @see #ToneGenerator(int, int)
196     */
197    public static final int TONE_PROP_NACK = 26;
198    /**
199     * Proprietary tone, prompt tone: 400Hz+1200Hz, 200ms ON
200     *
201     * @see #ToneGenerator(int, int)
202     */
203    public static final int  TONE_PROP_PROMPT = 27;
204    /**
205     * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON
206     *
207     * @see #ToneGenerator(int, int)
208     */
209    public static final int TONE_PROP_BEEP2 = 28;
210
211    /** Maximum volume, for use with {@link #ToneGenerator(int,int)} */
212    public static final int MAX_VOLUME = AudioSystem.MAX_VOLUME;
213    /** Minimum volume setting, for use with {@link #ToneGenerator(int,int)} */
214    public static final int MIN_VOLUME = AudioSystem.MIN_VOLUME;
215
216
217    /**
218     * ToneGenerator class contructor specifying output stream type and volume.
219     *
220     * @param streamType The streame type used for tone playback (e.g. STREAM_MUSIC).
221     * @param volume     The volume of the tone, given in percentage of maximum volume (from 0-100).
222     *
223     */
224    public ToneGenerator(int streamType, int volume) {
225        native_setup(streamType, volume);
226    }
227
228    /**
229     * This method starts the playback of a tone of the specified type.
230     * only one tone can play at a time: if a tone is playing while this method is called,
231     * this tone is stopped and replaced by the one requested.
232     * @param toneType   The type of tone generate chosen from the following list:
233     * <ul>
234     * <li>{@link #TONE_DTMF_0}
235     * <li>{@link #TONE_DTMF_1}
236     * <li>{@link #TONE_DTMF_2}
237     * <li>{@link #TONE_DTMF_3}
238     * <li>{@link #TONE_DTMF_4}
239     * <li>{@link #TONE_DTMF_5}
240     * <li>{@link #TONE_DTMF_6}
241     * <li>{@link #TONE_DTMF_7}
242     * <li>{@link #TONE_DTMF_8}
243     * <li>{@link #TONE_DTMF_9}
244     * <li>{@link #TONE_DTMF_A}
245     * <li>{@link #TONE_DTMF_B}
246     * <li>{@link #TONE_DTMF_C}
247     * <li>{@link #TONE_DTMF_D}
248     * <li>{@link #TONE_SUP_DIAL}
249     * <li>{@link #TONE_SUP_BUSY}
250     * <li>{@link #TONE_SUP_CONGESTION}
251     * <li>{@link #TONE_SUP_RADIO_ACK}
252     * <li>{@link #TONE_SUP_RADIO_NOTAVAIL}
253     * <li>{@link #TONE_SUP_ERROR}
254     * <li>{@link #TONE_SUP_CALL_WAITING}
255     * <li>{@link #TONE_SUP_RINGTONE}
256     * <li>{@link #TONE_PROP_BEEP}
257     * <li>{@link #TONE_PROP_ACK}
258     * <li>{@link #TONE_PROP_NACK}
259     * <li>{@link #TONE_PROP_PROMPT}
260     * <li>{@link #TONE_PROP_BEEP2}
261     * </ul>
262     * @see #ToneGenerator(int, int)
263    */
264    public native boolean startTone(int toneType);
265
266    /**
267     * This method stops the tone currently playing playback.
268     * @see #ToneGenerator(int, int)
269     */
270    public native void stopTone();
271
272    /**
273     * Releases resources associated with this ToneGenerator object. It is good
274     * practice to call this method when you're done using the ToneGenerator.
275     */
276    public native void release();
277
278    private native final void native_setup(int streamType, int volume);
279
280    private native final void native_finalize();
281    protected void finalize() { native_finalize(); }
282
283    private int mNativeContext; // accessed by native methods
284
285
286}
287