2.7 The Lookup Table

The lookup table, which is part of the header of the song or sound effect, is the list of sample waveform data types used by those sounds. You can determine the address of the lookup table with MusHandleWaveAddress and the size of the lookup table (the number of listed samples) with MusHandleWaveCount.


Return the address of the lookup table
Function name: MusHandleWaveAddress
Syntax: u16 *MusHandleWaveAddress(musHandle handle)
Arguments: handle Sound handle
Return value: Address of lookup table


Return the size of the lookup table
Function name: MusHandleWaveCount
Syntax: s32 MusHandleWaveCount(musHandle handle)
Arguments: handle Sound handle
Return value: Size of lookup table (number of entries)


The following example demonstrates how these functions can be used.

 
void swap_sample(musHandle handle, s32 swap1, s32 swap2)
  {
    s32 count;
    u16 *lookup, swap;

    count = MusHandleWaveCount(handle);     // Get size of lookup table
    lookup = MusHandleWaveAddress(handle);  // Get lookup table pointer                                            

     // If swap1 and swap2 are valid indexes of table
    if(count>=swap1 && count>=swap2)
    {
      // Store pointer corresponding to swap1
        swap = lookup[swap1];
      // Overwrite swap1 pointer with pointer corresponding to swap2
      lookup[swap1] = lookup[swap2];
      // Overwrite swap2 pointer with pointer corresponding to swap1
      lookup[swap2] = swap;
    }
  }

In this program, the samples numbered swap1 and swap2 in the specified sound handle are switched.
This can be used in a two-instrument duet to swap parts based on specific timing.

(*) Be careful because the order can change when the data is edited.