diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-09-10 18:40:12 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-09-10 18:40:12 +0000 |
commit | d4249affc41a0483ff9800b0b197e0fbeb5757fc (patch) | |
tree | 972cb897b6f09eda9caacefbbd4870c7ea69a8a0 /apps/codecs/libgme | |
parent | 585eb12348a23bfe9e181fa01ba55afa6109c735 (diff) | |
download | rockbox-d4249affc41a0483ff9800b0b197e0fbeb5757fc.tar.gz rockbox-d4249affc41a0483ff9800b0b197e0fbeb5757fc.zip |
Remove residual floating point code from libgme's ym2612_emu. Saves several KB of codesize.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30496 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libgme')
-rw-r--r-- | apps/codecs/libgme/blargg_common.h | 1 | ||||
-rw-r--r-- | apps/codecs/libgme/ym2612_emu.c | 126 |
2 files changed, 63 insertions, 64 deletions
diff --git a/apps/codecs/libgme/blargg_common.h b/apps/codecs/libgme/blargg_common.h index a023d6b842..74cc227eed 100644 --- a/apps/codecs/libgme/blargg_common.h +++ b/apps/codecs/libgme/blargg_common.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | // common defines | 23 | // common defines |
24 | #define FP_ONE_CLOCK (1LL << 12) | ||
24 | #define FP_ONE_TEMPO (1LL << 24) | 25 | #define FP_ONE_TEMPO (1LL << 24) |
25 | #define FP_ONE_GAIN (1LL << 24) | 26 | #define FP_ONE_GAIN (1LL << 24) |
26 | #define FP_ONE_VOLUME FP_ONE_GAIN | 27 | #define FP_ONE_VOLUME FP_ONE_GAIN |
diff --git a/apps/codecs/libgme/ym2612_emu.c b/apps/codecs/libgme/ym2612_emu.c index a9b7be21f1..60df30a33c 100644 --- a/apps/codecs/libgme/ym2612_emu.c +++ b/apps/codecs/libgme/ym2612_emu.c | |||
@@ -461,44 +461,23 @@ static int YM_SET( struct Ym2612_Impl* impl, int Adr, int data ) | |||
461 | return 0; | 461 | return 0; |
462 | } | 462 | } |
463 | 463 | ||
464 | #if defined(ROCKBOX) | ||
465 | double fabs(double x) | ||
466 | { | ||
467 | if (x < 0.0) return -x; | ||
468 | return x; | ||
469 | } | ||
470 | |||
471 | double ipow(double a,int b) | ||
472 | { | ||
473 | if (b < 0) { | ||
474 | a = 1.0 / a; | ||
475 | b = -b; | ||
476 | } | ||
477 | double result = 1.0; | ||
478 | while(b) { | ||
479 | if (b & 1) result*=a; | ||
480 | a *= a; | ||
481 | b >>= 1; | ||
482 | } | ||
483 | return result; | ||
484 | } | ||
485 | #endif | ||
486 | |||
487 | void impl_reset( struct Ym2612_Impl* impl ); | 464 | void impl_reset( struct Ym2612_Impl* impl ); |
488 | static void impl_set_rate( struct Ym2612_Impl* impl, double sample_rate, double clock_rate ) | 465 | static void impl_set_rate( struct Ym2612_Impl* impl, int sample_rate, int clock_rate ) |
489 | { | 466 | { |
490 | assert( sample_rate ); | 467 | assert( sample_rate ); |
491 | assert( !clock_rate || clock_rate > sample_rate ); | 468 | assert( !clock_rate || clock_rate > sample_rate ); |
492 | 469 | ||
493 | int i; | 470 | int i; |
494 | 471 | ||
495 | // 144 = 12 * (prescale * 2) = 12 * 6 * 2 | 472 | // 144 = 12 * (prescale * 2) = 12 * 6 * 2 |
496 | // prescale set to 6 by default | 473 | // prescale set to 6 by default |
497 | 474 | ||
498 | double Frequence = (clock_rate ? clock_rate / sample_rate / 144.0 : 1.0); | 475 | int Frequency = (clock_rate ? (int)((FP_ONE_CLOCK * clock_rate) / sample_rate / 144) : (int)FP_ONE_CLOCK); |
499 | if ( fabs( Frequence - 1.0 ) < 0.0000001 ) | 476 | if ( abs( Frequency - FP_ONE_CLOCK ) < 1 ) |
500 | Frequence = 1.0; | 477 | Frequency = FP_ONE_CLOCK; |
501 | impl->YM2612.TimerBase = (int) (Frequence * 4096.0); | 478 | impl->YM2612.TimerBase = Frequency; |
479 | |||
480 | /* double Frequence = (double)Frequency / FP_ONE_CLOCK; */ | ||
502 | 481 | ||
503 | // Tableau TL : | 482 | // Tableau TL : |
504 | // [0 - 4095] = +output [4095 - ...] = +output overflow (fill with 0) | 483 | // [0 - 4095] = +output [4095 - ...] = +output overflow (fill with 0) |
@@ -571,11 +550,18 @@ static void impl_set_rate( struct Ym2612_Impl* impl, double sample_rate, double | |||
571 | { | 550 | { |
572 | // Attack curve (x^8 - music level 2 Vectorman 2) | 551 | // Attack curve (x^8 - music level 2 Vectorman 2) |
573 | #if defined(ROCKBOX) | 552 | #if defined(ROCKBOX) |
574 | double x = ipow( ((ENV_LENGHT - 1) - i) / (double) ENV_LENGHT, 8.0 ); | 553 | int k; |
554 | int prescale = (31 - 2*ENV_HBITS); /* used to gain higher precision */ | ||
555 | int x = ENV_LENGHT * (1 << prescale); | ||
556 | for ( k = 0; k < 8; ++k) | ||
557 | { | ||
558 | x = ( x * ((ENV_LENGHT - 1) - i) ) / ENV_LENGHT; | ||
559 | } | ||
560 | x >>= prescale; | ||
575 | #else | 561 | #else |
576 | double x = pow( ((ENV_LENGHT - 1) - i) / (double) ENV_LENGHT, 8.0 ); | 562 | double x = pow( ((ENV_LENGHT - 1) - i) / (double) ENV_LENGHT, 8.0 ); |
563 | x *= ENV_LENGHT; | ||
577 | #endif | 564 | #endif |
578 | x *= ENV_LENGHT; | ||
579 | 565 | ||
580 | impl->g.ENV_TAB [i] = (int) x; | 566 | impl->g.ENV_TAB [i] = (int) x; |
581 | 567 | ||
@@ -586,7 +572,7 @@ static void impl_set_rate( struct Ym2612_Impl* impl, double sample_rate, double | |||
586 | impl->g.ENV_TAB [i + ENV_LENGHT * 2] = 0; | 572 | impl->g.ENV_TAB [i + ENV_LENGHT * 2] = 0; |
587 | 573 | ||
588 | impl->g.ENV_TAB [ENV_END >> ENV_LBITS] = ENV_LENGHT - 1; // for the stopped state | 574 | impl->g.ENV_TAB [ENV_END >> ENV_LBITS] = ENV_LENGHT - 1; // for the stopped state |
589 | 575 | ||
590 | // Tableau pour la conversion Attack -> Decay and Decay -> Attack | 576 | // Tableau pour la conversion Attack -> Decay and Decay -> Attack |
591 | 577 | ||
592 | int j = ENV_LENGHT - 1; | 578 | int j = ENV_LENGHT - 1; |
@@ -599,28 +585,33 @@ static void impl_set_rate( struct Ym2612_Impl* impl, double sample_rate, double | |||
599 | } | 585 | } |
600 | 586 | ||
601 | // Tableau pour le Substain Level | 587 | // Tableau pour le Substain Level |
602 | 588 | ||
603 | for ( i = 0; i < 15; i++ ) | 589 | for ( i = 0; i < 15; i++ ) |
604 | { | 590 | { |
605 | double x = i * 3 / ENV_STEP; // 3 and not 6 (Mickey Mania first music for test) | 591 | int x = i * 3 * (int)( (1 << ENV_LBITS) / ENV_STEP); // 3 and not 6 (Mickey Mania first music for test) |
606 | 592 | ||
607 | impl->g.SL_TAB [i] = ((int) x << ENV_LBITS) + ENV_DECAY; | 593 | impl->g.SL_TAB [i] = x + ENV_DECAY; |
608 | } | 594 | } |
609 | 595 | ||
610 | impl->g.SL_TAB [15] = ((ENV_LENGHT - 1) << ENV_LBITS) + ENV_DECAY; // special case : volume off | 596 | impl->g.SL_TAB [15] = ((ENV_LENGHT - 1) << ENV_LBITS) + ENV_DECAY; // special case : volume off |
611 | 597 | ||
612 | // Tableau Frequency Step | 598 | // Tableau Frequency Step |
599 | |||
613 | { | 600 | { |
614 | // 0.5 because MUL = value * 2 | 601 | // * 1 / 2 because MUL = value * 2 |
615 | #if SIN_LBITS + SIN_HBITS - (21 - 7) < 0 | 602 | #if SIN_LBITS + SIN_HBITS - (21 - 7) < 0 |
616 | double const factor = 0.5 / (1 << ((21 - 7) - SIN_LBITS - SIN_HBITS)) * Frequence; | 603 | /* double const factor = Frequence / 2.0 / (1 << ((21 - 7) - SIN_LBITS - SIN_HBITS)); */ |
604 | int const factor = (int)(Frequency / 2 / (1 << ((21 - 7) - SIN_LBITS - SIN_HBITS)) / FP_ONE_CLOCK); | ||
617 | #else | 605 | #else |
618 | double const factor = 0.5 * (1 << (SIN_LBITS + SIN_HBITS - (21 - 7))) * Frequence; | 606 | /* double const factor = Frequence / 2.0 * (1 << (SIN_LBITS + SIN_HBITS - (21 - 7))); */ |
607 | int const factor = (int)(Frequency / 2 * (1 << (SIN_LBITS + SIN_HBITS - (21 - 7))) / FP_ONE_CLOCK); | ||
619 | #endif | 608 | #endif |
620 | for ( i = 0; i < 2048; i++ ) | 609 | for ( i = 0; i < 2048; i++ ) |
621 | impl->g.FINC_TAB [i] = (unsigned) (i * factor); | 610 | { |
611 | impl->g.FINC_TAB [i] = i * factor; | ||
612 | } | ||
622 | } | 613 | } |
623 | 614 | ||
624 | // Tableaux Attack & Decay Rate | 615 | // Tableaux Attack & Decay Rate |
625 | 616 | ||
626 | for ( i = 0; i < 4; i++ ) | 617 | for ( i = 0; i < 4; i++ ) |
@@ -628,19 +619,23 @@ static void impl_set_rate( struct Ym2612_Impl* impl, double sample_rate, double | |||
628 | impl->g.AR_TAB [i] = 0; | 619 | impl->g.AR_TAB [i] = 0; |
629 | impl->g.DR_TAB [i] = 0; | 620 | impl->g.DR_TAB [i] = 0; |
630 | } | 621 | } |
631 | 622 | ||
632 | for ( i = 0; i < 60; i++ ) | 623 | for ( i = 0; i < 60; i++ ) |
633 | { | 624 | { |
634 | double x = | 625 | long long x = |
635 | (1.0 + ((i & 3) * 0.25)) * // bits 0-1 : x1.00, x1.25, x1.50, x1.75 | 626 | (4LL + ((i & 3))) * // bits 0-1 : 4*(x1.00, x1.25, x1.50, x1.75) |
636 | (ENV_LENGHT << ENV_LBITS) * // on ajuste pour le tableau impl->g.ENV_TAB | 627 | (ENV_LENGHT << ENV_LBITS) * // on ajuste pour le tableau impl->g.ENV_TAB |
637 | Frequence * | 628 | Frequency * |
638 | (1 << (i >> 2)); // bits 2-5 : shift bits (x2^0 - x2^15) | 629 | (1 << (i >> 2)) / // bits 2-5 : shift bits (x2^0 - x2^15) |
630 | FP_ONE_CLOCK / 4; | ||
631 | |||
632 | long long x_AR = x / AR_RATE; | ||
633 | long long x_DR = x / DR_RATE; | ||
639 | 634 | ||
640 | impl->g.AR_TAB [i + 4] = (unsigned int) (x / AR_RATE); | 635 | impl->g.AR_TAB [i + 4] = (unsigned int) ( x_AR > ((1LL<<32) - 1) ? ((1LL<<32) - 1) : x_AR ); |
641 | impl->g.DR_TAB [i + 4] = (unsigned int) (x / DR_RATE); | 636 | impl->g.DR_TAB [i + 4] = (unsigned int) ( x_DR > ((1LL<<32) - 1) ? ((1LL<<32) - 1) : x_DR ); |
642 | } | 637 | } |
643 | 638 | ||
644 | for ( i = 64; i < 96; i++ ) | 639 | for ( i = 64; i < 96; i++ ) |
645 | { | 640 | { |
646 | impl->g.AR_TAB [i] = impl->g.AR_TAB [63]; | 641 | impl->g.AR_TAB [i] = impl->g.AR_TAB [63]; |
@@ -651,36 +646,39 @@ static void impl_set_rate( struct Ym2612_Impl* impl, double sample_rate, double | |||
651 | 646 | ||
652 | for ( i = 96; i < 128; i++ ) | 647 | for ( i = 96; i < 128; i++ ) |
653 | impl->g.AR_TAB [i] = 0; | 648 | impl->g.AR_TAB [i] = 0; |
654 | 649 | ||
655 | // Tableau Detune | 650 | // Tableau Detune |
656 | { | 651 | { |
657 | #if SIN_LBITS + SIN_HBITS - 21 < 0 | 652 | #if SIN_LBITS + SIN_HBITS - 21 < 0 |
658 | double const factor = 1.0 / (1 << (21 - SIN_LBITS - SIN_HBITS)) * Frequence; | 653 | /* double const factor = 1.0 / (1 << (21 - SIN_LBITS - SIN_HBITS)) * Frequence; */ |
654 | int const factor = Frequency / (1 << (21 - SIN_LBITS - SIN_HBITS)) / FP_ONE_CLOCK; | ||
659 | #else | 655 | #else |
660 | double const factor = (1 << (SIN_LBITS + SIN_HBITS - 21)) * Frequence; | 656 | /* double const factor = (1 << (SIN_LBITS + SIN_HBITS - 21)) * Frequence; */ |
657 | int const factor = Frequency * (1 << (SIN_LBITS + SIN_HBITS - 21)) / FP_ONE_CLOCK; | ||
661 | #endif | 658 | #endif |
662 | for ( i = 0; i < 4; i++ ) | 659 | for ( i = 0; i < 4; i++ ) |
663 | { | 660 | { |
664 | int j; | 661 | int j; |
665 | for ( j = 0; j < 32; j++ ) | 662 | for ( j = 0; j < 32; j++ ) |
666 | { | 663 | { |
667 | double y = DT_DEF_TAB [(i << 5) + j] * factor; | 664 | /* double y = DT_DEF_TAB [(i << 5) + j] * factor; */ |
665 | int y = DT_DEF_TAB [(i << 5) + j] * factor; | ||
668 | 666 | ||
669 | impl->g.DT_TAB [i + 0] [j] = (int) y; | 667 | impl->g.DT_TAB [i + 0] [j] = (int) y; |
670 | impl->g.DT_TAB [i + 4] [j] = (int) -y; | 668 | impl->g.DT_TAB [i + 4] [j] = (int) -y; |
671 | } | 669 | } |
672 | } | 670 | } |
673 | } | 671 | } |
674 | 672 | ||
675 | // Tableau LFO | 673 | // Tableau LFO |
676 | impl->g.LFO_INC_TAB [0] = (unsigned) (3.98 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 674 | impl->g.LFO_INC_TAB [0] = (int) (3.98 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
677 | impl->g.LFO_INC_TAB [1] = (unsigned) (5.56 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 675 | impl->g.LFO_INC_TAB [1] = (int) (5.56 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
678 | impl->g.LFO_INC_TAB [2] = (unsigned) (6.02 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 676 | impl->g.LFO_INC_TAB [2] = (int) (6.02 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
679 | impl->g.LFO_INC_TAB [3] = (unsigned) (6.37 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 677 | impl->g.LFO_INC_TAB [3] = (int) (6.37 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
680 | impl->g.LFO_INC_TAB [4] = (unsigned) (6.88 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 678 | impl->g.LFO_INC_TAB [4] = (int) (6.88 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
681 | impl->g.LFO_INC_TAB [5] = (unsigned) (9.63 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 679 | impl->g.LFO_INC_TAB [5] = (int) (9.63 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
682 | impl->g.LFO_INC_TAB [6] = (unsigned) (48.1 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 680 | impl->g.LFO_INC_TAB [6] = (int) (48.1 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
683 | impl->g.LFO_INC_TAB [7] = (unsigned) (72.2 * (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); | 681 | impl->g.LFO_INC_TAB [7] = (int) (72.2 * (1 << (LFO_HBITS + LFO_LBITS))) / sample_rate; |
684 | 682 | ||
685 | impl_reset( impl ); | 683 | impl_reset( impl ); |
686 | } | 684 | } |
@@ -693,7 +691,7 @@ const char* Ym2612_set_rate( struct Ym2612_Emu* this, int sample_rate, int clock | |||
693 | if (last_sample_rate == sample_rate && last_clock_rate == clock_rate) return 0; | 691 | if (last_sample_rate == sample_rate && last_clock_rate == clock_rate) return 0; |
694 | #endif | 692 | #endif |
695 | memset( &this->impl.YM2612, 0, sizeof this->impl.YM2612 ); | 693 | memset( &this->impl.YM2612, 0, sizeof this->impl.YM2612 ); |
696 | impl_set_rate( &this->impl, (double)sample_rate, (double)clock_rate ); | 694 | impl_set_rate( &this->impl, sample_rate, clock_rate ); |
697 | 695 | ||
698 | return 0; | 696 | return 0; |
699 | } | 697 | } |