Advertisement
KSSBrawl_

Untitled

Dec 22nd, 2020
1,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. /**
  2.  * @brief Handles voice key-off triggered by gate
  3.  * @param part Target part
  4.  */
  5. static inline void
  6. koffCheck( SndDrvPart *part )
  7. {
  8.     // If gate already triggered, skip
  9.     if ( part->ngo == 0 ) return;
  10.  
  11.     if ( --part->ngo == 0 || part->ngc == 2 )
  12.     {
  13.         u8 *adx = part->add;    // Local copy of part->add
  14.         u8  ptx = part->ptc;    // Local copy of part->ptc
  15.  
  16.         while ( 1 )
  17.         {
  18.             u8 cmd = *adx;
  19.  
  20.             // Check for pattern end
  21.             if ( cmd == 0x00 )
  22.             {
  23.                 // If end of pattern, trigger key-off
  24.                 if ( ptx == 0 ) break;
  25.                 ptx--;
  26.  
  27.                 if ( ptx == 0 ) adx = part->adt;
  28.                 else adx = part->adp;
  29.  
  30.                 continue;
  31.             }
  32.  
  33.             // If not end of pattern, try to find a note or command
  34.             else if ( cmd < NOTE_BASE )
  35.             {
  36.                 int i;
  37.  
  38.                 for ( i = 0; i < 128; i++ )
  39.                 {
  40.                     cmd = *( adx + i );
  41.  
  42.                     // If not note params, break
  43.                     if ( cmd >= note_c00 ) break;
  44.                 }
  45.  
  46.                 // If nothing was found, just trigger key-off
  47.                 if ( i == 128 ) break;
  48.             }
  49.  
  50.             // If tie note, skip key-off
  51.             if ( cmd == note_tie ) return;
  52.  
  53.             // If command is to play pattern, set adx to start of pattern
  54.             else if ( cmd == PATX + CMD_BASE )
  55.                 adx = gft + read16( *++adx );
  56.  
  57.             // If any other command, skip past it
  58.             else if ( cmd >= CMD_BASE )
  59.                 adx += spfp[ cmd - CMD_BASE ];
  60.  
  61.             // If anything else, trigger key-off
  62.             else break;
  63.         }
  64.  
  65.         // Trigger key-off for voice
  66.         dsp->kof |= keyd;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement