home *** CD-ROM | disk | FTP | other *** search
/ Amiga Dream 59 / CDDream59.ISO / BeOs / Sound / Intel / PPBeDevKit.ZIP / PLAYERPR.TAR / PlayerPRO / Source / Effects.c < prev    next >
C/C++ Source or Header  |  1999-01-02  |  12KB  |  575 lines

  1. /********************                        ***********************/
  2. //
  3. //    Player PRO 5.0 - DRIVER SOURCE CODE -
  4. //
  5. //    Library Version 5.0
  6. //
  7. //    To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
  8. //
  9. //    Antoine ROSSET
  10. //    16 Tranchees
  11. //    1206 GENEVA
  12. //    SWITZERLAND
  13. //
  14. //    COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
  15. //
  16. //    Thank you for your interest in PlayerPRO !
  17. //
  18. //    FAX:                (+41 22) 346 11 97
  19. //    PHONE:             (+41 79) 203 74 62
  20. //    Internet:     RossetAntoine@bluewin.ch
  21. //
  22. /********************                        ***********************/
  23.  
  24. #include "RDriver.h"
  25. #include "RDriverInt.h"
  26.  
  27. #define LOW(para) ((para) & 15)
  28. #define HI(para) ((para) >> 4)
  29.  
  30. void parse_slidevol(Channel *ch, Byte Arg)
  31. {
  32.     if ( LOW( Arg) ) ch->volumerate = -LOW( Arg);
  33.     else ch->volumerate = HI( Arg);
  34. }
  35.  
  36. void DoEffect( Channel *ch, short call, MADDriverRec *intDriver)
  37. {
  38. long offset;
  39.     
  40.     switch( ch->cmd)
  41.     {
  42.         default:
  43.             ch->cmd = 0;
  44.             ch->arg = 0;
  45.             return;
  46.         break;
  47.     
  48.         case arpeggioE:                        // OK
  49.             if( ch->arg != 0 && ch->arpUse == true)
  50.             {
  51.                 ch->arpindex++;
  52.                 if( ch->arpindex >= MAX_ARP) ch->arpindex = 0;
  53.                 
  54.                 ch->period = ch->arp[ ch->arpindex];
  55.                 
  56.                 if( call == intDriver->speed - 1) ch->period = ch->arp[ 0];
  57.             }
  58.         break;
  59.     
  60.         case skipE:                            // OK
  61.             if( call == intDriver->speed - 1)
  62.             {
  63.                 intDriver->endPattern = true;
  64.                 
  65.                 if( intDriver->JumpToNextPattern)
  66.                 {
  67.                     if( intDriver->PartitionReader != 0)
  68.                     {
  69.                         intDriver->PL++;
  70.                         intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  71.                     }
  72.                     
  73.                     intDriver->PartitionReader = HI( ch->arg) * 10 + LOW( ch->arg);
  74.                     
  75.                     if( intDriver->PL >= intDriver->curMusic->header->numPointers)
  76.                     {
  77.                         intDriver->PL = 0;
  78.                         intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  79.                         
  80.                         MADCleanDriver( intDriver);
  81.                         if( !intDriver->DriverSettings.repeatMusic) intDriver->Reading = false;
  82.                         
  83.                         intDriver->musicEnd = true;
  84.                     }
  85.                 }
  86.                 else
  87.                 {
  88.                     intDriver->PartitionReader = 0;
  89.                 }
  90.                 ch->cmd = 0;
  91.                 ch->arg = 0;
  92.             }
  93.         break;
  94.         
  95.         case fastskipE:                        // OK
  96.             if( call == intDriver->speed - 1)
  97.             {
  98.                 intDriver->endPattern = true;
  99.                 
  100.                 if( intDriver->JumpToNextPattern)
  101.                 {
  102.                     if( intDriver->PL > ch->arg)        // Evite les boucles
  103.                     {
  104.                         intDriver->musicEnd = true;
  105.                         
  106.                         if( !intDriver->DriverSettings.repeatMusic) intDriver->Reading = false;
  107.                     }
  108.                     
  109.                     intDriver->PL = ch->arg;
  110.                     intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  111.                 
  112.                     if( intDriver->PL >= intDriver->curMusic->header->numPointers)
  113.                     {
  114.                         intDriver->PL = 0;
  115.                         intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  116.                         
  117.                         MADCleanDriver( intDriver);
  118.                         if( !intDriver->DriverSettings.repeatMusic) intDriver->Reading = false;
  119.                         
  120.                         intDriver->musicEnd = true;
  121.                     }
  122.                 }
  123.                 intDriver->PartitionReader = 0;
  124.                 ch->cmd = 0;
  125.                 ch->arg = 0;
  126.             }
  127.         break;
  128.         
  129.         case downslideE:                        // OK
  130.             if( ch->period > intDriver->MIN_PITCH)
  131.                 ch->period -= ch->slide*4;
  132.         break;
  133.         
  134.         case upslideE:                            // OK
  135.             if( ch->period < intDriver->MAX_PITCH)
  136.                 ch->period += ch->slide*4;
  137.         break;
  138.         
  139.         case vibratoE:
  140.         {
  141.             Byte q = (ch->viboffset>>2)&0x1f;
  142.             
  143.             switch( ch->vibtype)
  144.             {
  145.             case 0:
  146.                 offset = intDriver->vibrato_table[ q];
  147.             break;
  148.             
  149.             case 1:
  150.                 q<<=3;
  151.                 if(ch->viboffset<0) q=255-q;
  152.                 offset = q;
  153.             break;
  154.  
  155.             case 2:
  156.                 offset = 255;
  157.             break;
  158.             }
  159.             
  160.             offset *= ch->vibdepth;
  161.             offset >>= 7;
  162.             offset <<= 2;
  163.             
  164.             if( ch->viboffset >= 0) ch->period = ch->periodOld + offset;
  165.             else ch->period = ch->periodOld - offset;
  166.             
  167.             ch->viboffset += ch->vibrate;
  168.             
  169.             if( call == intDriver->speed - 1) ch->period = ch->periodOld;
  170.         }
  171.         break;
  172.         
  173.         case slidevolE:                        // OK
  174.             ch->vol += ch->volumerate;
  175.             
  176.             if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  177.             else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  178.         break;
  179.         
  180.         case portamentoE:
  181.         //    if( ch->period == 0) MyDebugStr( __LINE__, __FILE__, "Goal");
  182.             if( ch->period != ch->pitchgoal)
  183.             {
  184.                 if (ch->period < ch->pitchgoal)
  185.                 {
  186.                     ch->period += ch->pitchrate*4;
  187.                     if( ch->period > ch->pitchgoal)
  188.                     {
  189.                         ch->cmd = 0;
  190.                         ch->arg = 0;
  191.                         ch->period = ch->pitchgoal;
  192.                     }
  193.                 }
  194.                 else if (ch->period > ch->pitchgoal)
  195.                 {
  196.                     ch->period -= ch->pitchrate*4;
  197.                     if( ch->period < ch->pitchgoal)
  198.                     {
  199.                         ch->cmd = 0;
  200.                         ch->arg = 0;
  201.                         ch->period = ch->pitchgoal;
  202.                     }
  203.                 }
  204.             }
  205.         break;
  206.         
  207.         case portaslideE:
  208.             ch->cmd = portamentoE;
  209.             DoEffect( ch, call, intDriver);
  210.             
  211.             ch->cmd = slidevolE;
  212.             DoEffect( ch, call, intDriver);
  213.             
  214.             ch->cmd = portaslideE;
  215.         break;
  216.         
  217.         case vibratoslideE:
  218.             ch->cmd = vibratoE;
  219.             DoEffect( ch, call, intDriver);
  220.             
  221.             ch->cmd = slidevolE;
  222.             DoEffect( ch, call, intDriver);
  223.             
  224.             ch->cmd = vibratoslideE;
  225.         break;
  226.  
  227.         case extendedE:
  228.             switch( HI( ch->arg))
  229.               {
  230.                 case 12:
  231.                     if( call >= LOW( ch->arg)) ch->vol = 0;
  232.                 break;
  233.             }
  234.         break;
  235.     }
  236.     
  237.     if( call == intDriver->speed - 1)
  238.     {
  239.         ch->arg = 0;
  240.         ch->cmd = 0;
  241.     }
  242. }
  243.  
  244. void SetUpEffect( Channel *ch, MADDriverRec *intDriver)
  245. {
  246. short     temp, note;
  247. long    aL;
  248.  
  249. if( ch->arg == 0)
  250. {
  251.     switch( ch->cmd)
  252.     {
  253.         case arpeggioE:
  254.         case nothingE:
  255.         case fastskipE:
  256.         case volumeE:
  257.         case panningE:
  258.         case skipE:
  259.         case extendedE:
  260.         case speedE:
  261.         break;
  262.         
  263.         default:
  264.             ch->arg = ch->oldArg[ ch->cmd];
  265.         break;
  266.     }
  267. }
  268. else ch->oldArg[ ch->cmd] = ch->arg;
  269.  
  270. switch( ch->cmd)
  271. {
  272.     case upslideE:                            // OK
  273.         if( ch->arg) ch->slide = ch->arg;
  274.     break;
  275.     
  276.     case downslideE:                        // OK
  277.         if( ch->arg) ch->slide = ch->arg;
  278.     break;
  279.  
  280.     case vibratoE:                            // OK
  281.         if( HI( ch->arg)) ch->vibrate = (ch->arg & 0xf0)>>2;    //HI( ch->arg);
  282.         if( LOW( ch->arg)) ch->vibdepth = LOW( ch->arg);
  283.         
  284.         //ch->viboffset = 0;
  285.         ch->periodOld = ch->period;
  286.     break;
  287.     
  288.     case arpeggioE:                        // OK
  289.         if( ch->arg == 0) ch->arpUse = false;
  290.         else
  291.         {
  292.             long    inNote = ch->note;
  293.             
  294.             if( inNote == 0xFF) inNote = ch->noteOld;
  295.             
  296.             if( inNote != 0xFF)
  297.             {
  298.                 note = inNote + HI( ch->arg);
  299.                 if (note < NUMBER_NOTES) ch->arp[ 1] = GetOldPeriod( note, NOFINETUNE, intDriver);
  300.                 
  301.                 note = inNote + LOW( ch->arg);
  302.                 if (note < NUMBER_NOTES) ch->arp[ 2] = GetOldPeriod( note, NOFINETUNE, intDriver);
  303.                    
  304.                 ch->arpindex = 0;
  305.                 ch->arp[ 0] = ch->period;
  306.                 
  307.                 ch->arpUse = true;
  308.             }
  309.             else ch->arpUse = false;
  310.         }
  311.     break;
  312.     
  313.     case slidevolE:                        // OK
  314.         parse_slidevol( ch, ch->arg);
  315.     break;
  316.     
  317.     case extendedE:
  318.         switch( HI( ch->arg))
  319.         {
  320.             case 0:        // Turn On/Off filter
  321.             break;
  322.             
  323.             case 1:        // Fineslide up
  324.                 temp = LOW( ch->arg);
  325.                 ch->period -= temp*4;
  326.             break;
  327.             
  328.             case 2:        // Fineslide down
  329.                 temp = LOW( ch->arg);
  330.                 ch->period += temp*4;
  331.             break;
  332.             
  333.             case 3:        // Set glissando on/off
  334.                 
  335.             break;
  336.             
  337.             case 4:        // Set vibrato waveform
  338.                 switch( LOW( ch->arg))
  339.                 {
  340.                     case 0:
  341.                     case 4:
  342.                         ch->vibtype = 0;
  343.                     break;
  344.                     
  345.                     case 1:
  346.                     case 5:
  347.                         ch->vibtype = 1;
  348.                     break;
  349.                     
  350.                     case 2:
  351.                     case 6:
  352.                         ch->vibtype = 2;
  353.                     break;
  354.                     
  355.                     case 3:
  356.                     case 7:
  357.                         ch->vibtype = 0;
  358.                     break;
  359.                 }
  360.             break;
  361.             
  362.             case 5:        // Set finetune value
  363.             //    ch->fineTune    = finetune[ LOW( ch->arg)];
  364.             //    ch->period    = GetOldPeriod( ch->Amiga, ch->fineTune);
  365.             break;
  366.             
  367.             case 6:        // Loop pattern
  368.             /*    if( LOW( ch->arg) == 0)        // Set Pattern loop
  369.                 {
  370.                     intDriver->PatternLoopE6 = intDriver->PartitionReader;
  371.                 }
  372.                 else
  373.                 {
  374.                     if( intDriver->PatternLoopE6Count-- > 0)
  375.                     {
  376.                         intDriver->PartitionReader = intDriver->PatternLoopE6;
  377.                     }
  378.                 }*/
  379.             break;
  380.             
  381.             case 7:        // Set tremolo waveform
  382.             break;
  383.             
  384.             case 8:        // Unused
  385.             break;
  386.             
  387.             case 9:
  388.             break;
  389.  
  390.             case 10:    // Fine volume slide up
  391.                 ch->vol += LOW( ch->arg);
  392.                 
  393.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  394.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  395.             break;
  396.             
  397.             case 11:    // Fine volume slide down
  398.                 ch->vol -= LOW( ch->arg);
  399.                 
  400.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  401.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  402.             break;
  403.             
  404.             case 12:    // Cut sample
  405.             break;
  406.             
  407.             case 13:    // Delay sample
  408.             break;
  409.             
  410.             case 14:    // Delay pattern
  411.             break;
  412.             
  413.             case 15:    // Invert loop
  414.             break;
  415.         }
  416.  
  417.     break;
  418.     
  419.     case portamentoE:                // OK
  420.     {
  421.         long    inNote = ch->note;
  422.         
  423.         ch->pitchrate = ch->arg;
  424.         
  425.         if( inNote == 0xFF) inNote = ch->noteOld;
  426.         
  427.         if( inNote != 0xFF)
  428.         {
  429.             ch->pitchgoal = GetOldPeriod( inNote, ch->fineTune, intDriver);
  430.         }
  431.         else if( ch->pitchgoal == 0) ch->pitchgoal = ch->period;
  432.     }
  433.     break;
  434.     
  435.     case portaslideE:                // OK
  436.     {
  437.         long    inNote = ch->note;
  438.         
  439.         if( inNote == 0xFF) inNote = ch->noteOld;
  440.         
  441.         if( inNote != 0xFF)
  442.         {
  443.             ch->pitchgoal = GetOldPeriod( ch->note, ch->fineTune, intDriver);
  444.         }
  445.         else if( ch->pitchgoal == 0) ch->pitchgoal = ch->period;
  446.         
  447.         parse_slidevol(ch, ch->arg);
  448.     }
  449.     break;
  450.     
  451.     case vibratoslideE:
  452.         ch->periodOld = ch->period;
  453.  
  454.            parse_slidevol(ch, ch->arg);
  455.     break;
  456.     
  457.     case speedE:
  458.         if( ch->arg < 32)        /** Setting de la speed + reset de la finespeed **/
  459.         {
  460.             if( ch->arg != 0) intDriver->speed = ch->arg;
  461.         }
  462.         else        /** Setting de finespeed **/
  463.         {
  464.             intDriver->finespeed = ch->arg;
  465.         }
  466.     break;
  467.             
  468.     case skipE:
  469.     break;
  470.     
  471.     case fastskipE:
  472.     break;
  473.     
  474.     case offsetE:
  475.         ch->curPtr = ch->begPtr;
  476.  
  477.         aL = ch->arg;
  478.         aL *= 256L;
  479.  
  480.         ch->curPtr += aL;
  481.     break;
  482.     
  483.     case panningE:
  484.         ch->pann = ch->arg;
  485.         
  486.         ch->pann = ( (long) ch->pann * (long)  MAX_PANNING) / (long) 0xFF;
  487.         
  488.         if( ch->pann < 0) ch->pann = 0;
  489.         else if( ch->pann > MAX_PANNING) ch->pann = MAX_PANNING;
  490.     break;
  491.     
  492.     case volumeE:
  493.         ch->vol = ch->arg;
  494.         
  495.         if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  496.         else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  497.     break;
  498.     }
  499. }
  500.  
  501. void DoVolCmd( Channel *ch, short call, MADDriverRec *intDriver)
  502. {
  503. short    vol = ch->volcmd;
  504. short    volLO = vol & 0xf;
  505.  
  506.     switch( vol >> 4)
  507.     {
  508.         case 0x6:                    // volslide down
  509.             ch->vol -= volLO;
  510.         
  511.             if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  512.             else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  513.         break;
  514.  
  515.         case 0x7:                    // volslide up
  516.             ch->vol += volLO;
  517.         
  518.             if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  519.             else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  520.         break;
  521.  
  522.         // volume-row fine volume slide is compatible with protracker
  523.         //   EBx and EAx effects i.e. a zero nibble means DO NOT SLIDE, as
  524.         //  opposed to 'take the last sliding value'.
  525.         //
  526.  
  527.         case 0x8:                        // finevol down
  528.             if( call == 1)
  529.             {
  530.                 ch->vol -= volLO;
  531.         
  532.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  533.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  534.             }
  535.         break;
  536.  
  537.         case 0x9:                       // finevol up
  538.             if( call == 1)
  539.             {
  540.                 ch->vol += volLO;
  541.         
  542.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  543.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  544.             }
  545.         break;
  546.  
  547.         case 0xa:                       // set vibrato speed
  548.         break;
  549.  
  550.         case 0xb:                       // vibrato
  551.         break;
  552.  
  553.         case 0xc:                       // set panning
  554.         break;
  555.  
  556.         case 0xd:                       // panning slide left
  557.             // only slide when data nibble not zero:
  558.  
  559.             if(vol&0xf)
  560.             {
  561.             }
  562.             break;
  563.  
  564.         case 0xe:                       // panning slide right
  565.             // only slide when data nibble not zero:
  566.  
  567.             if(vol&0xf)
  568.             {
  569.             }
  570.         break;
  571.  
  572.         case 0xf:                       // tone porta
  573.         break;
  574.     }
  575. }