comparison src/audlegacy/output.c @ 4817:6c131c192b92

removed unnecessary spaces
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 04 Feb 2009 07:31:14 +0900
parents 7bf7f83a217e
children 8ebd8358de04
comparison
equal deleted inserted replaced
4816:49bd21710d54 4817:6c131c192b92
113 113
114 if (playing == TRUE) 114 if (playing == TRUE)
115 { 115 {
116 guint time, pos; 116 guint time, pos;
117 PlaylistEntry *entry; 117 PlaylistEntry *entry;
118 118
119 plugin_set_current((Plugin *)op); 119 plugin_set_current((Plugin *)op);
120 120
121 /* don't stop yet, get the seek time and playlist position first */ 121 /* don't stop yet, get the seek time and playlist position first */
122 pos = playlist_get_position(playlist_get_active()); 122 pos = playlist_get_position(playlist_get_active());
123 time = op->output_time(); 123 time = op->output_time();
124 124
332 return TRUE; 332 return TRUE;
333 } else { 333 } else {
334 #ifdef USE_SAMPLERATE 334 #ifdef USE_SAMPLERATE
335 rate = src_flow_init(rate, nch); /* returns sample rate unchanged if resampling switched off */ 335 rate = src_flow_init(rate, nch); /* returns sample rate unchanged if resampling switched off */
336 #endif 336 #endif
337 337
338 bit_depth = cfg.output_bit_depth; 338 bit_depth = cfg.output_bit_depth;
339 339
340 AUDDBG("bit depth: %d\n", bit_depth); 340 AUDDBG("bit depth: %d\n", bit_depth);
341 output_fmt = (bit_depth == 24) ? FMT_S24_NE : FMT_S16_NE; 341 output_fmt = (bit_depth == 24) ? FMT_S24_NE : FMT_S16_NE;
342 342
343 freeSAD(); 343 freeSAD();
344 344
345 AUDDBG("initializing dithering engine for 2 stage conversion: fmt%d --> float -->fmt%d\n", fmt, output_fmt); 345 AUDDBG("initializing dithering engine for 2 stage conversion: fmt%d --> float -->fmt%d\n", fmt, output_fmt);
346 input_sad_fmt.sample_format = sadfmt_from_afmt(fmt); 346 input_sad_fmt.sample_format = sadfmt_from_afmt(fmt);
347 if (input_sad_fmt.sample_format < 0) return FALSE; 347 if (input_sad_fmt.sample_format < 0) return FALSE;
348 input_sad_fmt.fracbits = FMT_FRACBITS(fmt); 348 input_sad_fmt.fracbits = FMT_FRACBITS(fmt);
349 input_sad_fmt.channels = nch; 349 input_sad_fmt.channels = nch;
350 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; 350 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED;
351 input_sad_fmt.samplerate = 0; 351 input_sad_fmt.samplerate = 0;
352 352
353 output_sad_fmt.sample_format = SAD_SAMPLE_FLOAT; 353 output_sad_fmt.sample_format = SAD_SAMPLE_FLOAT;
354 output_sad_fmt.fracbits = 0; 354 output_sad_fmt.fracbits = 0;
355 output_sad_fmt.channels = nch; 355 output_sad_fmt.channels = nch;
356 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; 356 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED;
357 output_sad_fmt.samplerate = 0; 357 output_sad_fmt.samplerate = 0;
358 358
359 sad_state_to_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); 359 sad_state_to_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret);
360 if (sad_state_to_float == NULL) { 360 if (sad_state_to_float == NULL) {
361 AUDDBG("ditherer init failed (decoder's native --> float)\n"); 361 AUDDBG("ditherer init failed (decoder's native --> float)\n");
362 return FALSE; 362 return FALSE;
363 } 363 }
364 SAD_dither_set_dither (sad_state_to_float, FALSE); 364 SAD_dither_set_dither (sad_state_to_float, FALSE);
365 365
366 input_sad_fmt.sample_format = SAD_SAMPLE_FLOAT; 366 input_sad_fmt.sample_format = SAD_SAMPLE_FLOAT;
367 input_sad_fmt.fracbits = 0; 367 input_sad_fmt.fracbits = 0;
368 input_sad_fmt.channels = nch; 368 input_sad_fmt.channels = nch;
369 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; 369 input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED;
370 input_sad_fmt.samplerate = 0; 370 input_sad_fmt.samplerate = 0;
371 371
372 output_sad_fmt.sample_format = sadfmt_from_afmt(output_fmt); 372 output_sad_fmt.sample_format = sadfmt_from_afmt(output_fmt);
373 if (output_sad_fmt.sample_format < 0) return FALSE; 373 if (output_sad_fmt.sample_format < 0) return FALSE;
374 output_sad_fmt.fracbits = FMT_FRACBITS(output_fmt); 374 output_sad_fmt.fracbits = FMT_FRACBITS(output_fmt);
375 output_sad_fmt.channels = nch; 375 output_sad_fmt.channels = nch;
376 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; 376 output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED;
377 output_sad_fmt.samplerate = 0; 377 output_sad_fmt.samplerate = 0;
378 378
379 sad_state_from_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); 379 sad_state_from_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret);
380 if (sad_state_from_float == NULL) { 380 if (sad_state_from_float == NULL) {
381 SAD_dither_free(sad_state_to_float); 381 SAD_dither_free(sad_state_to_float);
382 AUDDBG("ditherer init failed (float --> output)\n"); 382 AUDDBG("ditherer init failed (float --> output)\n");
383 return FALSE; 383 return FALSE;
384 } 384 }
385 SAD_dither_set_dither (sad_state_from_float, TRUE); 385 SAD_dither_set_dither (sad_state_from_float, TRUE);
386 386
387 fmt = output_fmt; 387 fmt = output_fmt;
388 388
389 if(replay_gain_info.album_peak == 0.0 && replay_gain_info.track_peak == 0.0) { 389 if(replay_gain_info.album_peak == 0.0 && replay_gain_info.track_peak == 0.0) {
390 AUDDBG("RG info isn't set yet. Filling replay_gain_info with default values.\n"); 390 AUDDBG("RG info isn't set yet. Filling replay_gain_info with default values.\n");
391 replay_gain_info.track_gain = cfg.default_gain; 391 replay_gain_info.track_gain = cfg.default_gain;
392 replay_gain_info.track_peak = 0.01; 392 replay_gain_info.track_peak = 0.01;
393 replay_gain_info.album_gain = cfg.default_gain; 393 replay_gain_info.album_gain = cfg.default_gain;
394 replay_gain_info.album_peak = 0.01; 394 replay_gain_info.album_peak = 0.01;
395 } 395 }
396 apply_replaygain_info(&replay_gain_info); 396 apply_replaygain_info(&replay_gain_info);
397 397
398 return reopen_audio(fmt, rate, nch); 398 return reopen_audio(fmt, rate, nch);
399 } /* bypass_dsp */ 399 } /* bypass_dsp */
400 } 400 }
401 401
402 void 402 void
416 output_close_audio(void) 416 output_close_audio(void)
417 { 417 {
418 OutputPlugin *op = get_current_output_plugin(); 418 OutputPlugin *op = get_current_output_plugin();
419 419
420 freeSAD(); 420 freeSAD();
421 421
422 AUDDBG("clearing RG settings\n"); 422 AUDDBG("clearing RG settings\n");
423 replay_gain_info.track_gain = 0.0; 423 replay_gain_info.track_gain = 0.0;
424 replay_gain_info.track_peak = 0.0; 424 replay_gain_info.track_peak = 0.0;
425 replay_gain_info.album_gain = 0.0; 425 replay_gain_info.album_gain = 0.0;
426 replay_gain_info.album_peak = 0.0; 426 replay_gain_info.album_peak = 0.0;
513 static Flow *postproc_flow = NULL; 513 static Flow *postproc_flow = NULL;
514 static Flow *legacy_flow = NULL; 514 static Flow *legacy_flow = NULL;
515 OutputPlugin *op = playback->output; 515 OutputPlugin *op = playback->output;
516 gint writeoffs; 516 gint writeoffs;
517 gpointer float_ptr; 517 gpointer float_ptr;
518 518
519 if (visualization_flow == NULL) 519 if (visualization_flow == NULL)
520 { 520 {
521 visualization_flow = flow_new(); 521 visualization_flow = flow_new();
522 flow_link_element(visualization_flow, vis_flow); 522 flow_link_element(visualization_flow, vis_flow);
523 } 523 }
524 524
525 plugin_set_current((Plugin *)(playback->output)); 525 plugin_set_current((Plugin *)(playback->output));
526 gint time = playback->output->written_time(); 526 gint time = playback->output->written_time();
527 527
528 flow_execute(visualization_flow, time, &ptr, length, fmt, decoder_srate, nch); 528 flow_execute(visualization_flow, time, &ptr, length, fmt, decoder_srate, nch);
529 529
530 if (!bypass_dsp) { 530 if (!bypass_dsp) {
531 531
532 if(length <= 0 || sad_state_from_float == NULL || sad_state_to_float == NULL) return; 532 if(length <= 0 || sad_state_from_float == NULL || sad_state_to_float == NULL) return;
533 533
534 if (legacy_flow == NULL) 534 if (legacy_flow == NULL)
535 { 535 {
536 legacy_flow = flow_new(); 536 legacy_flow = flow_new();
537 flow_link_element(legacy_flow, effect_flow); 537 flow_link_element(legacy_flow, effect_flow);
538 } 538 }
539 539
540 if (postproc_flow == NULL) 540 if (postproc_flow == NULL)
541 { 541 {
542 postproc_flow = flow_new(); 542 postproc_flow = flow_new();
543 #ifdef USE_SAMPLERATE 543 #ifdef USE_SAMPLERATE
544 flow_link_element(postproc_flow, src_flow); 544 flow_link_element(postproc_flow, src_flow);
545 #endif 545 #endif
546 flow_link_element(postproc_flow, equalizer_flow); 546 flow_link_element(postproc_flow, equalizer_flow);
547 flow_link_element(postproc_flow, volumecontrol_flow); 547 flow_link_element(postproc_flow, volumecontrol_flow);
548 } 548 }
549 549
550 int frames = length / nch / FMT_SIZEOF(fmt); 550 int frames = length / nch / FMT_SIZEOF(fmt);
551 int len = frames * nch * sizeof(float); 551 int len = frames * nch * sizeof(float);
552 if(sad_float_buf == NULL || sad_float_buf_length < len) { 552 if(sad_float_buf == NULL || sad_float_buf_length < len) {
553 sad_float_buf_length = len; 553 sad_float_buf_length = len;
554 sad_float_buf = smart_realloc(sad_float_buf, &sad_float_buf_length); 554 sad_float_buf = smart_realloc(sad_float_buf, &sad_float_buf_length);
555 } 555 }
556 556
557 SAD_dither_process_buffer(sad_state_to_float, ptr, sad_float_buf, frames); 557 SAD_dither_process_buffer(sad_state_to_float, ptr, sad_float_buf, frames);
558 float_ptr = sad_float_buf; 558 float_ptr = sad_float_buf;
559 559
560 length = flow_execute(postproc_flow, 560 length = flow_execute(postproc_flow,
561 time, 561 time,
562 &float_ptr, 562 &float_ptr,
563 len, 563 len,
564 FMT_FLOAT, 564 FMT_FLOAT,
565 decoder_srate, 565 decoder_srate,
566 nch); 566 nch);
567 567
568 frames = length / nch / sizeof(float); 568 frames = length / nch / sizeof(float);
569 len = frames * nch * FMT_SIZEOF(op_state.fmt); 569 len = frames * nch * FMT_SIZEOF(op_state.fmt);
570 if(sad_out_buf == NULL || sad_out_buf_length < len) { 570 if(sad_out_buf == NULL || sad_out_buf_length < len) {
571 sad_out_buf_length = len; 571 sad_out_buf_length = len;
572 sad_out_buf = smart_realloc(sad_out_buf, &sad_out_buf_length); 572 sad_out_buf = smart_realloc(sad_out_buf, &sad_out_buf_length);
573 } 573 }
574 574
575 SAD_dither_process_buffer(sad_state_from_float, float_ptr, sad_out_buf, frames); 575 SAD_dither_process_buffer(sad_state_from_float, float_ptr, sad_out_buf, frames);
576 576
577 length = len; 577 length = len;
578 ptr = sad_out_buf; 578 ptr = sad_out_buf;
579 579
580 if (op_state.fmt == FMT_S16_NE || (op_state.fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) || 580 if (op_state.fmt == FMT_S16_NE || (op_state.fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) ||
581 (op_state.fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)) { 581 (op_state.fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)) {
582 length = flow_execute(legacy_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch); 582 length = flow_execute(legacy_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch);
583 } else { 583 } else {
584 AUDDBG("legacy_flow can deal only with S16_NE streams\n"); /*FIXME*/ 584 AUDDBG("legacy_flow can deal only with S16_NE streams\n"); /*FIXME*/
649 649
650 if(sad_state_from_float == NULL) { 650 if(sad_state_from_float == NULL) {
651 AUDDBG("SAD not initialized!\n"); 651 AUDDBG("SAD not initialized!\n");
652 return; 652 return;
653 } 653 }
654 654
655 rg_enabled = cfg.enable_replay_gain; 655 rg_enabled = cfg.enable_replay_gain;
656 album_mode = cfg.replay_gain_album; 656 album_mode = cfg.replay_gain_album;
657 mode.clipping_prevention = cfg.enable_clipping_prevention; 657 mode.clipping_prevention = cfg.enable_clipping_prevention;
658 mode.hard_limit = FALSE; 658 mode.hard_limit = FALSE;
659 mode.adaptive_scaler = cfg.enable_adaptive_scaler; 659 mode.adaptive_scaler = cfg.enable_adaptive_scaler;
660 660
661 if(!rg_enabled) return; 661 if(!rg_enabled) return;
662 662
663 mode.mode = album_mode ? SAD_RG_ALBUM : SAD_RG_TRACK; 663 mode.mode = album_mode ? SAD_RG_ALBUM : SAD_RG_TRACK;
664 mode.preamp = cfg.replay_gain_preamp; 664 mode.preamp = cfg.replay_gain_preamp;
665 665
677 AUDDBG("Replay Gain info for current track:\n"); 677 AUDDBG("Replay Gain info for current track:\n");
678 AUDDBG("* track gain: %+f dB\n", info.track_gain); 678 AUDDBG("* track gain: %+f dB\n", info.track_gain);
679 AUDDBG("* track peak: %f\n", info.track_peak); 679 AUDDBG("* track peak: %f\n", info.track_peak);
680 AUDDBG("* album gain: %+f dB\n", info.album_gain); 680 AUDDBG("* album gain: %+f dB\n", info.album_gain);
681 AUDDBG("* album peak: %f\n", info.album_peak); 681 AUDDBG("* album peak: %f\n", info.album_peak);
682 682
683 SAD_dither_apply_replaygain(sad_state_from_float, &info, &mode); 683 SAD_dither_apply_replaygain(sad_state_from_float, &info, &mode);
684 } 684 }
685 685
686 void output_plugin_cleanup(void) 686 void output_plugin_cleanup(void)
687 { 687 {