Changeset 904 for pjproject/trunk/pjmedia/src/pjmedia/tonegen.c
- Timestamp:
- Jan 24, 2007 2:02:09 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/tonegen.c
r747 r904 28 28 29 29 /* amplitude */ 30 #define AMP 1638330 #define AMP 8192 31 31 32 32 … … 234 234 pjmedia_port base; 235 235 236 /* options */ 237 unsigned options; 238 unsigned playback_options; 239 236 240 /* Digit map */ 237 241 pjmedia_tone_digit_map *digit_map; … … 281 285 * default digit map. 282 286 */ 287 PJ_DEF(pj_status_t) pjmedia_tonegen_create2(pj_pool_t *pool, 288 const pj_str_t *name, 289 unsigned clock_rate, 290 unsigned channel_count, 291 unsigned samples_per_frame, 292 unsigned bits_per_sample, 293 unsigned options, 294 pjmedia_port **p_port) 295 { 296 const pj_str_t STR_TONE_GEN = pj_str("tone-gen"); 297 struct tonegen *tonegen; 298 pj_status_t status; 299 300 PJ_ASSERT_RETURN(pool && clock_rate && channel_count && 301 samples_per_frame && bits_per_sample == 16 && 302 p_port != NULL, PJ_EINVAL); 303 304 /* Only support mono and stereo */ 305 PJ_ASSERT_RETURN(channel_count==1 || channel_count==2, PJ_EINVAL); 306 307 /* Create and initialize port */ 308 tonegen = pj_pool_zalloc(pool, sizeof(struct tonegen)); 309 if (name == NULL || name->slen == 0) name = &STR_TONE_GEN; 310 status = pjmedia_port_info_init(&tonegen->base.info, name, 311 SIGNATURE, clock_rate, channel_count, 312 bits_per_sample, samples_per_frame); 313 if (status != PJ_SUCCESS) 314 return status; 315 316 tonegen->options = options; 317 tonegen->base.get_frame = &tonegen_get_frame; 318 tonegen->digit_map = &digit_map; 319 320 /* Done */ 321 *p_port = &tonegen->base; 322 return PJ_SUCCESS; 323 } 324 325 283 326 PJ_DEF(pj_status_t) pjmedia_tonegen_create( pj_pool_t *pool, 284 327 unsigned clock_rate, … … 289 332 pjmedia_port **p_port) 290 333 { 291 const pj_str_t STR_TONE_GEN = pj_str("tone-gen"); 292 struct tonegen *tonegen; 293 pj_status_t status; 294 295 PJ_ASSERT_RETURN(pool && clock_rate && channel_count && 296 samples_per_frame && bits_per_sample == 16 && 297 options == 0 && p_port != NULL, PJ_EINVAL); 298 299 /* Only support mono and stereo */ 300 PJ_ASSERT_RETURN(channel_count==1 || channel_count==2, PJ_EINVAL); 301 302 /* Create and initialize port */ 303 tonegen = pj_pool_zalloc(pool, sizeof(struct tonegen)); 304 status = pjmedia_port_info_init(&tonegen->base.info, &STR_TONE_GEN, 305 SIGNATURE, clock_rate, channel_count, 306 bits_per_sample, samples_per_frame); 307 if (status != PJ_SUCCESS) 308 return status; 309 310 tonegen->base.get_frame = &tonegen_get_frame; 311 tonegen->digit_map = &digit_map; 312 313 /* Done */ 314 *p_port = &tonegen->base; 315 return PJ_SUCCESS; 334 return pjmedia_tonegen_create2(pool, NULL, clock_rate, channel_count, 335 samples_per_frame, bits_per_sample, 336 options, p_port); 316 337 } 317 338 … … 359 380 if (tonegen->cur_digit > tonegen->count) { 360 381 /* We have played all the digits */ 361 tonegen->count = 0; 362 frame->type = PJMEDIA_FRAME_TYPE_NONE; 363 return PJ_SUCCESS; 382 if ((tonegen->options|tonegen->playback_options)&PJMEDIA_TONEGEN_LOOP) 383 { 384 /* Reset back to the first tone */ 385 tonegen->cur_digit = 0; 386 tonegen->dig_samples = 0; 387 388 } else { 389 tonegen->count = 0; 390 frame->type = PJMEDIA_FRAME_TYPE_NONE; 391 return PJ_SUCCESS; 392 } 364 393 } 365 394 … … 377 406 * the digits 378 407 */ 379 tonegen->count = 0; 380 frame->type = PJMEDIA_FRAME_TYPE_NONE; 381 return PJ_SUCCESS; 408 if ((tonegen->options|tonegen->playback_options)&PJMEDIA_TONEGEN_LOOP) 409 { 410 /* Reset back to the first tone */ 411 tonegen->cur_digit = 0; 412 tonegen->dig_samples = 0; 413 414 } else { 415 tonegen->count = 0; 416 frame->type = PJMEDIA_FRAME_TYPE_NONE; 417 return PJ_SUCCESS; 418 } 382 419 } 383 420 … … 385 422 end = dst + port->info.samples_per_frame; 386 423 387 while (dst < end && tonegen->cur_digit < tonegen->count) {424 while (dst < end) { 388 425 const pjmedia_tone_desc *dig = &tonegen->digits[tonegen->cur_digit]; 389 426 unsigned required, cnt, on_samp, off_samp; … … 426 463 tonegen->cur_digit++; 427 464 tonegen->dig_samples = 0; 465 466 if (tonegen->cur_digit >= tonegen->count) { 467 /* All digits have been played */ 468 if ((tonegen->options & PJMEDIA_TONEGEN_LOOP) || 469 (tonegen->playback_options & PJMEDIA_TONEGEN_LOOP)) 470 { 471 tonegen->cur_digit = 0; 472 } else { 473 break; 474 } 475 } 428 476 } 429 477 } … … 435 483 frame->size = port->info.bytes_per_frame; 436 484 437 if (tonegen->cur_digit >= tonegen->count) 438 tonegen->count = 0; 485 if (tonegen->cur_digit >= tonegen->count) { 486 if ((tonegen->options|tonegen->playback_options)&PJMEDIA_TONEGEN_LOOP) 487 { 488 /* Reset back to the first tone */ 489 tonegen->cur_digit = 0; 490 tonegen->dig_samples = 0; 491 492 } else { 493 tonegen->count = 0; 494 } 495 } 439 496 440 497 return PJ_SUCCESS; … … 454 511 455 512 PJ_ASSERT_RETURN(port && port->info.signature == SIGNATURE && 456 count && tones && options==0, PJ_EINVAL);513 count && tones, PJ_EINVAL); 457 514 458 515 /* Don't put more than available buffer */ … … 460 517 PJ_ETOOMANY); 461 518 519 /* Set playback options */ 520 tonegen->playback_options = options; 521 462 522 /* Copy digits */ 463 523 pj_memcpy(tonegen->digits + tonegen->count, … … 493 553 494 554 PJ_ASSERT_RETURN(port && port->info.signature == SIGNATURE && 495 count && digits && options==0, PJ_EINVAL);555 count && digits, PJ_EINVAL); 496 556 PJ_ASSERT_RETURN(count < PJMEDIA_TONEGEN_MAX_DIGITS, PJ_ETOOMANY); 497 557
Note: See TracChangeset
for help on using the changeset viewer.