ToneGenerator.java revision dda5391d5079537e275c9f4ed2637a1484d0e4e8
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: 134 * CEPT: 425Hz, continuous 135 * ANSI (IS-95): 350Hz+440Hz, continuous 136 * JAPAN: 400Hz, continuous 137 * 138 * @see #ToneGenerator(int, int) 139 */ 140 public static final int TONE_SUP_DIAL = 16; 141 /** 142 * Call supervisory tone, Busy: 143 * CEPT: 425Hz, 500ms ON, 500ms OFF... 144 * ANSI (IS-95): 480Hz+620Hz, 500ms ON, 500ms OFF... 145 * JAPAN: 400Hz, 500ms ON, 500ms OFF... 146 * 147 * @see #ToneGenerator(int, int) 148 */ 149 public static final int TONE_SUP_BUSY = 17; 150 /** 151 * Call supervisory tone, Congestion: 152 * CEPT, JAPAN: 425Hz, 200ms ON, 200ms OFF... 153 * ANSI (IS-95): 480Hz+620Hz, 250ms ON, 250ms OFF... 154 * 155 * @see #ToneGenerator(int, int) 156 */ 157 public static final int TONE_SUP_CONGESTION = 18; 158 /** 159 * Call supervisory tone, Radio path acknowlegment : 160 * CEPT, ANSI: 425Hz, 200ms ON 161 * JAPAN: 400Hz, 1s ON, 2s OFF... 162 * 163 * @see #ToneGenerator(int, int) 164 */ 165 public static final int TONE_SUP_RADIO_ACK = 19; 166 /** 167 * Call supervisory tone, Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts 168 * 169 * @see #ToneGenerator(int, int) 170 */ 171 public static final int TONE_SUP_RADIO_NOTAVAIL = 20; 172 /** 173 * Call supervisory tone, Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF... 174 * 175 * @see #ToneGenerator(int, int) 176 */ 177 public static final int TONE_SUP_ERROR = 21; 178 /** 179 * Call supervisory tone, Call Waiting: 180 * CEPT, JAPAN: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF... 181 * ANSI (IS-95): 440 Hz, 300 ms ON, 9.7 s OFF, 182 * (100 ms ON, 100 ms OFF, 100 ms ON, 9.7s OFF ...) 183 * 184 * @see #ToneGenerator(int, int) 185 */ 186 public static final int TONE_SUP_CALL_WAITING = 22; 187 /** 188 * Call supervisory tone, Ring Tone: 189 * CEPT, JAPAN: 425Hz, 1s ON, 4s OFF... 190 * ANSI (IS-95): 440Hz + 480Hz, 2s ON, 4s OFF... 191 * 192 * @see #ToneGenerator(int, int) 193 */ 194 public static final int TONE_SUP_RINGTONE = 23; 195 /** 196 * Proprietary tone, general beep: 400Hz+1200Hz, 35ms ON 197 * 198 * @see #ToneGenerator(int, int) 199 */ 200 public static final int TONE_PROP_BEEP = 24; 201 /** 202 * Proprietary tone, positive acknowlegement: 1200Hz, 100ms ON, 100ms OFF 2 bursts 203 * 204 * @see #ToneGenerator(int, int) 205 */ 206 public static final int TONE_PROP_ACK = 25; 207 /** 208 * Proprietary tone, negative acknowlegement: 300Hz+400Hz+500Hz, 400ms ON 209 * 210 * @see #ToneGenerator(int, int) 211 */ 212 public static final int TONE_PROP_NACK = 26; 213 /** 214 * Proprietary tone, prompt tone: 400Hz+1200Hz, 200ms ON 215 * 216 * @see #ToneGenerator(int, int) 217 */ 218 public static final int TONE_PROP_PROMPT = 27; 219 /** 220 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 221 * 222 * @see #ToneGenerator(int, int) 223 */ 224 public static final int TONE_PROP_BEEP2 = 28; 225 /** 226 * Call supervisory tone (IS-95), intercept tone: alternating 440 Hz and 620 Hz tones, 227 * each on for 250 ms 228 * 229 * @see #ToneGenerator(int, int) 230 */ 231 public static final int TONE_SUP_INTERCEPT = 29; 232 /** 233 * Call supervisory tone (IS-95), abbreviated intercept: intercept tone limited to 4 seconds 234 * 235 * @see #ToneGenerator(int, int) 236 */ 237 public static final int TONE_SUP_INTERCEPT_ABBREV = 30; 238 /** 239 * Call supervisory tone (IS-95), abbreviated congestion: congestion tone limited to 4 seconds 240 * 241 * @see #ToneGenerator(int, int) 242 */ 243 public static final int TONE_SUP_CONGESTION_ABBREV = 31; 244 /** 245 * Call supervisory tone (IS-95), confirm tone: a 350 Hz tone added to a 440 Hz tone 246 * repeated 3 times in a 100 ms on, 100 ms off cycle 247 * 248 * @see #ToneGenerator(int, int) 249 */ 250 public static final int TONE_SUP_CONFIRM = 32; 251 /** 252 * Call supervisory tone (IS-95), pip tone: four bursts of 480 Hz tone (0.1 s on, 0.1 s off). 253 * 254 * @see #ToneGenerator(int, int) 255 */ 256 public static final int TONE_SUP_PIP = 33; 257 258 259 /** 260 * CDMA SPECIFIC TONES START 261 */ 262 263 /** TODO(Moto): Change "Proprietary" below with an appropriate specification reference */ 264 265 /** 266 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 267 * 268 * @see #ToneGenerator(int, int) 269 * 270 * @hide 271 */ 272 public static final int TONE_CDMA_DIAL_TONE_LITE = 34; 273 274 /** 275 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 276 * 277 * @see #ToneGenerator(int, int) 278 * 279 * @hide 280 */ 281 public static final int TONE_CDMA_NETWORK_USA_RINGBACK = 35; 282 283 /** 284 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 285 * 286 * @see #ToneGenerator(int, int) 287 * 288 * @hide 289 */ 290 public static final int TONE_CDMA_REORDER = 36; 291 292 /** 293 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 294 * 295 * @see #ToneGenerator(int, int) 296 * 297 * @hide 298 */ 299 public static final int TONE_CDMA_ABBR_REORDER = 37; 300 301 /** 302 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 303 * 304 * @see #ToneGenerator(int, int) 305 * 306 * @hide 307 */ 308 public static final int TONE_CDMA_NETWORK_BUSY = 38; 309 310 311 /** 312 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 313 * 314 * @see #ToneGenerator(int, int) 315 * 316 * @hide 317 */ 318 public static final int TONE_CDMA_ANSWER = 39; 319 320 /** 321 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 322 * 323 * @see #ToneGenerator(int, int) 324 * 325 * @hide 326 */ 327 public static final int TONE_CDMA_NETWORK_CALLWAITING = 40; 328 329 /** 330 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 331 * 332 * @see #ToneGenerator(int, int) 333 * 334 * @hide 335 */ 336 public static final int TONE_CDMA_PIP = 41; 337 338 339 /** 340 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 341 * 342 * @see #ToneGenerator(int, int) 343 * 344 * @hide 345 */ 346 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL = 42; 347 348 /** 349 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 350 * 351 * @see #ToneGenerator(int, int) 352 * 353 * @hide 354 */ 355 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP = 43; 356 357 /** 358 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 359 * 360 * @see #ToneGenerator(int, int) 361 * 362 * @hide 363 */ 364 public static final int TONE_CDMA_CALL_SIGNAL_SP_PRI = 44; 365 366 /** 367 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 368 * 369 * @see #ToneGenerator(int, int) 370 * 371 * @hide 372 */ 373 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT3 = 45; 374 375 /** 376 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 377 * 378 * @see #ToneGenerator(int, int) 379 * 380 * @hide 381 */ 382 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_RING_RING = 46; 383 384 /** 385 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 386 * 387 * @see #ToneGenerator(int, int) 388 * 389 * @hide 390 */ 391 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT5 = 47; 392 393 /** 394 * general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 395 * 396 * @see #ToneGenerator(int, int) 397 * 398 * @hide 399 */ 400 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT6 = 48; 401 402 /** 403 * general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 404 * 405 * @see #ToneGenerator(int, int) 406 * 407 * @hide 408 */ 409 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT7 = 49; 410 411 // TODO(Moto): Need comments for each one and we need ToneGenerator.cpp/ToneGenerator.h 412 413 /** @hide */ 414 public static final int TONE_CDMA_HIGH_L = 50; 415 416 /** @hide */ 417 public static final int TONE_CDMA_LOW_L = 51; 418 /** @hide */ 419 public static final int TONE_CDMA_HIGH_SS = 52; 420 /** @hide */ 421 public static final int TONE_CDMA_MED_SS = 53; 422 /** @hide */ 423 public static final int TONE_CDMA_LOW_SS = 54; 424 /** @hide */ 425 public static final int TONE_CDMA_HIGH_SSL = 55; 426 427 428 /** @hide */ 429 public static final int TONE_CDMA_MED_SSL = 56; 430 /** @hide */ 431 public static final int TONE_CDMA_LOW_SSL = 57; 432 /** @hide */ 433 public static final int TONE_CDMA_HIGH_SS_2 = 58; 434 /** @hide */ 435 public static final int TONE_CDMA_MED_SS_2 = 59; 436 /** @hide */ 437 public static final int TONE_CDMA_LOW_SS_2 = 60; 438 /** @hide */ 439 public static final int TONE_CDMA_HIGH_SLS = 61; 440 /** @hide */ 441 public static final int TONE_CDMA_MED_SLS = 62; 442 /** @hide */ 443 public static final int TONE_CDMA_LOW_SLS = 63; 444 /** @hide */ 445 public static final int TONE_CDMA_HIGH_S_X4 = 64; 446 /** @hide */ 447 public static final int TONE_CDMA_MED_S_X4 = 65; 448 /** @hide */ 449 public static final int TONE_CDMA_LOW_S_X4 = 66; 450 /** @hide */ 451 public static final int TONE_CDMA_HIGH_PBX_L = 67; 452 /** @hide */ 453 public static final int TONE_CDMA_MED_PBX_L = 68; 454 /** @hide */ 455 public static final int TONE_CDMA_LOW_PBX_L = 69; 456 /** @hide */ 457 public static final int TONE_CDMA_HIGH_PBX_SS = 70; 458 /** @hide */ 459 public static final int TONE_CDMA_MED_PBX_SS = 71; 460 /** @hide */ 461 public static final int TONE_CDMA_LOW_PBX_SS = 72; 462 /** @hide */ 463 public static final int TONE_CDMA_HIGH_PBX_SSL = 73; 464 /** @hide */ 465 public static final int TONE_CDMA_MED_PBX_SSL = 74; 466 467 /** @hide */ 468 public static final int TONE_CDMA_LOW_PBX_SSL = 75; 469 /** @hide */ 470 public static final int TONE_CDMA_HIGH_PBX_SLS = 76; 471 /** @hide */ 472 public static final int TONE_CDMA_MED_PBX_SLS = 77; 473 /** @hide */ 474 public static final int TONE_CDMA_LOW_PBX_SLS = 78; 475 /** @hide */ 476 public static final int TONE_CDMA_HIGH_PBX_S_X4 = 79; 477 /** @hide */ 478 public static final int TONE_CDMA_MED_PBX_S_X4 = 80; 479 /** @hide */ 480 public static final int TONE_CDMA_LOW_PBX_S_X4 = 81; 481 /** @hide */ 482 public static final int TONE_CDMA_INTERCEPT_ONE_SHOT = TONE_SUP_INTERCEPT_ABBREV; 483 /** @hide */ 484 public static final int TONE_CDMA_REORDER_ONE_SHOT = TONE_CDMA_ABBR_REORDER; 485 /** @hide */ 486 public static final int TONE_CDMA_NETWORK_BUSY_ONE_SHOT = 82; 487 /** @hide */ 488 public static final int TONE_CDMA_ABBR_ALERT = 83; 489 /** @hide */ 490 public static final int TONE_CDMA_SIGNAL_OFF = 84; 491 /** @hide */ 492 public static final int TONE_CDMA_INVALID = 85; 493 494 /** Maximum volume, for use with {@link #ToneGenerator(int,int)} */ 495 public static final int MAX_VOLUME = AudioSystem.MAX_VOLUME; 496 /** Minimum volume setting, for use with {@link #ToneGenerator(int,int)} */ 497 public static final int MIN_VOLUME = AudioSystem.MIN_VOLUME; 498 499 500 /** 501 * ToneGenerator class contructor specifying output stream type and volume. 502 * 503 * @param streamType The streame type used for tone playback (e.g. STREAM_MUSIC). 504 * @param volume The volume of the tone, given in percentage of maximum volume (from 0-100). 505 * 506 */ 507 public ToneGenerator(int streamType, int volume) { 508 native_setup(streamType, volume); 509 } 510 511 /** 512 * This method starts the playback of a tone of the specified type. 513 * only one tone can play at a time: if a tone is playing while this method is called, 514 * this tone is stopped and replaced by the one requested. 515 * @param toneType The type of tone generate chosen from the following list: 516 * <ul> 517 * <li>{@link #TONE_DTMF_0} 518 * <li>{@link #TONE_DTMF_1} 519 * <li>{@link #TONE_DTMF_2} 520 * <li>{@link #TONE_DTMF_3} 521 * <li>{@link #TONE_DTMF_4} 522 * <li>{@link #TONE_DTMF_5} 523 * <li>{@link #TONE_DTMF_6} 524 * <li>{@link #TONE_DTMF_7} 525 * <li>{@link #TONE_DTMF_8} 526 * <li>{@link #TONE_DTMF_9} 527 * <li>{@link #TONE_DTMF_A} 528 * <li>{@link #TONE_DTMF_B} 529 * <li>{@link #TONE_DTMF_C} 530 * <li>{@link #TONE_DTMF_D} 531 * <li>{@link #TONE_SUP_DIAL} 532 * <li>{@link #TONE_SUP_BUSY} 533 * <li>{@link #TONE_SUP_CONGESTION} 534 * <li>{@link #TONE_SUP_RADIO_ACK} 535 * <li>{@link #TONE_SUP_RADIO_NOTAVAIL} 536 * <li>{@link #TONE_SUP_ERROR} 537 * <li>{@link #TONE_SUP_CALL_WAITING} 538 * <li>{@link #TONE_SUP_RINGTONE} 539 * <li>{@link #TONE_PROP_BEEP} 540 * <li>{@link #TONE_PROP_ACK} 541 * <li>{@link #TONE_PROP_NACK} 542 * <li>{@link #TONE_PROP_PROMPT} 543 * <li>{@link #TONE_PROP_BEEP2} 544 * <li>{@link #TONE_SUP_INTERCEPT} 545 * <li>{@link #TONE_SUP_INTERCEPT_ABBREV} 546 * <li>{@link #TONE_SUP_CONGESTION_ABBREV} 547 * <li>{@link #TONE_SUP_CONFIRM} 548 * <li>{@link #TONE_SUP_PIP} 549 * </ul> 550 * @see #ToneGenerator(int, int) 551 */ 552 public native boolean startTone(int toneType); 553 554 /** 555 * This method stops the tone currently playing playback. 556 * @see #ToneGenerator(int, int) 557 */ 558 public native void stopTone(); 559 560 /** 561 * Releases resources associated with this ToneGenerator object. It is good 562 * practice to call this method when you're done using the ToneGenerator. 563 */ 564 public native void release(); 565 566 private native final void native_setup(int streamType, int volume); 567 568 private native final void native_finalize(); 569 570 @Override 571 protected void finalize() { native_finalize(); } 572 573 @SuppressWarnings("unused") 574 private int mNativeContext; // accessed by native methods 575} 576