---------- generic table initialize ---------- */
| 610 | |
| 611 | /* ---------- generic table initialize ---------- */ |
| 612 | static int OPLOpenTable( void ) |
| 613 | { |
| 614 | int s,t; |
| 615 | double rate; |
| 616 | int i,j; |
| 617 | double pom; |
| 618 | |
| 619 | /* allocate dynamic tables */ |
| 620 | if( (TL_TABLE = (INT32 *)malloc(TL_MAX*2*sizeof(INT32))) == NULL) |
| 621 | return 0; |
| 622 | if( (SIN_TABLE = (INT32 **)malloc(SIN_ENT*4 *sizeof(INT32 *))) == NULL) |
| 623 | { |
| 624 | free(TL_TABLE); |
| 625 | return 0; |
| 626 | } |
| 627 | if( (AMS_TABLE = (INT32 *)malloc(AMS_ENT*2 *sizeof(INT32))) == NULL) |
| 628 | { |
| 629 | free(TL_TABLE); |
| 630 | free(SIN_TABLE); |
| 631 | return 0; |
| 632 | } |
| 633 | if( (VIB_TABLE = (INT32 *)malloc(VIB_ENT*2 *sizeof(INT32))) == NULL) |
| 634 | { |
| 635 | free(TL_TABLE); |
| 636 | free(SIN_TABLE); |
| 637 | free(AMS_TABLE); |
| 638 | return 0; |
| 639 | } |
| 640 | /* make total level table */ |
| 641 | for (t = 0;t < EG_ENT-1 ;t++){ |
| 642 | rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20); /* dB -> voltage */ |
| 643 | TL_TABLE[ t] = (int)rate; |
| 644 | TL_TABLE[TL_MAX+t] = -TL_TABLE[t]; |
| 645 | /* LOG(LOG_INF,("TotalLevel(%3d) = %x\n",t,TL_TABLE[t]));*/ |
| 646 | } |
| 647 | /* fill volume off area */ |
| 648 | for ( t = EG_ENT-1; t < TL_MAX ;t++){ |
| 649 | TL_TABLE[t] = TL_TABLE[TL_MAX+t] = 0; |
| 650 | } |
| 651 | |
| 652 | /* make sinwave table (total level offset) */ |
| 653 | /* degree 0 = degree 180 = off */ |
| 654 | SIN_TABLE[0] = SIN_TABLE[SIN_ENT/2] = &TL_TABLE[EG_ENT-1]; |
| 655 | for (s = 1;s <= SIN_ENT/4;s++){ |
| 656 | pom = sin(2*PI*s/SIN_ENT); /* sin */ |
| 657 | pom = 20*log10(1/pom); /* decibel */ |
| 658 | j = pom / EG_STEP; /* TL_TABLE steps */ |
| 659 | |
| 660 | /* degree 0 - 90 , degree 180 - 90 : plus section */ |
| 661 | SIN_TABLE[ s] = SIN_TABLE[SIN_ENT/2-s] = &TL_TABLE[j]; |
| 662 | /* degree 180 - 270 , degree 360 - 270 : minus section */ |
| 663 | SIN_TABLE[SIN_ENT/2+s] = SIN_TABLE[SIN_ENT -s] = &TL_TABLE[TL_MAX+j]; |
| 664 | /* LOG(LOG_INF,("sin(%3d) = %f:%f db\n",s,pom,(double)j * EG_STEP));*/ |
| 665 | } |
| 666 | for (s = 0;s < SIN_ENT;s++) |
| 667 | { |
| 668 | SIN_TABLE[SIN_ENT*1+s] = s<(SIN_ENT/2) ? SIN_TABLE[s] : &TL_TABLE[EG_ENT]; |
| 669 | SIN_TABLE[SIN_ENT*2+s] = SIN_TABLE[s % (SIN_ENT/2)]; |