text: //// LSDjSynth.h
  //// HertzDevil 2015
  //// MIT License.
  
  //// .dmw export By Pegmode Dec 2016
  
  #pragma once
  #pragma warning( disable : 4309 ) // truncation of constant value
  
  // constant values
  
  #define WAVE_COUNT  0x10
  #define WAVE_LENGTH 0x20
  #define MAX_SEQ_LENGTH 252
  
  // wave tables
  
  static const char PARTIAL[][WAVE_LENGTH] = {
  	{0x00, 0x0C, 0x18, 0x23, 0x2C, 0x34, 0x3A, 0x3D, 0x3F, 0x3D, 0x3A, 0x34, 0x2C, 0x23, 0x18, 0x0C,
  	 0x00, 0xF4, 0xE8, 0xDD, 0xD4, 0xCC, 0xC6, 0xC3, 0xC1, 0xC3, 0xC6, 0xCC, 0xD4, 0xDD, 0xE8, 0xF4},
  	{0x00, 0x0C, 0x16, 0x1D, 0x1F, 0x1D, 0x16, 0x0C, 0x00, 0xF4, 0xEA, 0xE3, 0xE1, 0xE3, 0xEA, 0xF4,
  	 0x00, 0x0C, 0x16, 0x1D, 0x1F, 0x1D, 0x16, 0x0C, 0x00, 0xF4, 0xEA, 0xE3, 0xE1, 0xE3, 0xEA, 0xF4},
  	{0x00, 0x0B, 0x13, 0x14, 0x0E, 0x04, 0xF8, 0xEF, 0xEB, 0xEF, 0xF8, 0x04, 0x0E, 0x14, 0x13, 0x0B,
  	 0x00, 0xF5, 0xED, 0xEC, 0xF2, 0xFC, 0x08, 0x11, 0x14, 0x11, 0x08, 0xFC, 0xF2, 0xEC, 0xED, 0xF5},
  	{0x00, 0x0B, 0x0F, 0x0B, 0x00, 0xF5, 0xF1, 0xF5, 0x00, 0x0B, 0x0F, 0x0B, 0x00, 0xF5, 0xF1, 0xF5,
  	 0x00, 0x0B, 0x0F, 0x0B, 0x00, 0xF5, 0xF1, 0xF5, 0x00, 0x0B, 0x0F, 0x0B, 0x00, 0xF5, 0xF1, 0xF5},
  	{0x00, 0x0A, 0x0B, 0x02, 0xF8, 0xF4, 0xFC, 0x07, 0x0C, 0x07, 0xFC, 0xF4, 0xF8, 0x02, 0x0B, 0x0A,
  	 0x00, 0xF6, 0xF5, 0xFE, 0x08, 0x0C, 0x04, 0xF9, 0xF4, 0xF9, 0x04, 0x0C, 0x08, 0xFE, 0xF5, 0xF6},
  	{0x00, 0x09, 0x07, 0xFC, 0xF6, 0xFC, 0x07, 0x09, 0x00, 0xF7, 0xF9, 0x04, 0x0A, 0x04, 0xF9, 0xF7,
  	 0x00, 0x09, 0x07, 0xFC, 0xF6, 0xFC, 0x07, 0x09, 0x00, 0xF7, 0xF9, 0x04, 0x0A, 0x04, 0xF9, 0xF7},
  	{0x00, 0x08, 0x03, 0xF9, 0xFA, 0x05, 0x08, 0xFF, 0xF8, 0xFF, 0x08, 0x05, 0xFA, 0xF9, 0x03, 0x08,
  	 0x00, 0xF8, 0xFD, 0x07, 0x06, 0xFB, 0xF8, 0x01, 0x08, 0x01, 0xF8, 0xFB, 0x06, 0x07, 0xFD, 0xF8},
  	{0x00, 0x07, 0x00, 0xF9, 0x00, 0x07, 0x00, 0xF9, 0x00, 0x07, 0x00, 0xF9, 0x00, 0x07, 0x00, 0xF9,
  	 0x00, 0x07, 0x00, 0xF9, 0x00, 0x07, 0x00, 0xF9, 0x00, 0x07, 0x00, 0xF9, 0x00, 0x07, 0x00, 0xF9},
  	{0x00, 0x06, 0xFE, 0xFB, 0x04, 0x03, 0xFA, 0xFF, 0x06, 0xFF, 0xFA, 0x03, 0x04, 0xFB, 0xFE, 0x06,
  	 0x00, 0xFA, 0x02, 0x05, 0xFC, 0xFD, 0x06, 0x01, 0xFA, 0x01, 0x06, 0xFD, 0xFC, 0x05, 0x02, 0xFA},
  	{0x00, 0x05, 0xFC, 0xFE, 0x06, 0xFE, 0xFC, 0x05, 0x00, 0xFB, 0x04, 0x02, 0xFA, 0x02, 0x04, 0xFB,
  	 0x00, 0x05, 0xFC, 0xFE, 0x06, 0xFE, 0xFC, 0x05, 0x00, 0xFB, 0x04, 0x02, 0xFA, 0x02, 0x04, 0xFB},
  	{0x00, 0x04, 0xFB, 0x01, 0x04, 0xFB, 0x02, 0x03, 0xFB, 0x03, 0x02, 0xFB, 0x04, 0x01, 0xFB, 0x04,
  	 0x00, 0xFC, 0x05, 0xFF, 0xFC, 0x05, 0xFE, 0xFD, 0x05, 0xFD, 0xFE, 0x05, 0xFC, 0xFF, 0x05, 0xFC},
  	{0x00, 0x03, 0xFB, 0x03, 0x00, 0xFD, 0x05, 0xFD, 0x00, 0x03, 0xFB, 0x03, 0x00, 0xFD, 0x05, 0xFD,
  	 0x00, 0x03, 0xFB, 0x03, 0x00, 0xFD, 0x05, 0xFD, 0x00, 0x03, 0xFB, 0x03, 0x00, 0xFD, 0x05, 0xFD},
  	{0x00, 0x02, 0xFC, 0x04, 0xFD, 0x00, 0x01, 0xFC, 0x04, 0xFC, 0x01, 0x00, 0xFD, 0x04, 0xFC, 0x02,
  	 0x00, 0xFE, 0x04, 0xFC, 0x03, 0x00, 0xFF, 0x04, 0xFC, 0x04, 0xFF, 0x00, 0x03, 0xFC, 0x04, 0xFE},
  	{0x00, 0x01, 0xFD, 0x04, 0xFC, 0x04, 0xFD, 0x01, 0x00, 0xFF, 0x03, 0xFC, 0x04, 0xFC, 0x03, 0xFF,
  	 0x00, 0x01, 0xFD, 0x04, 0xFC, 0x04, 0xFD, 0x01, 0x00, 0xFF, 0x03, 0xFC, 0x04, 0xFC, 0x03, 0xFF},
  	{0x00, 0x00, 0xFF, 0x02, 0xFE, 0x03, 0xFD, 0x04, 0xFC, 0x04, 0xFD, 0x03, 0xFE, 0x02, 0xFF, 0x00,
  	 0x00, 0x00, 0x01, 0xFE, 0x02, 0xFD, 0x03, 0xFC, 0x04, 0xFC, 0x03, 0xFD, 0x02, 0xFE, 0x01, 0x00},
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  };
  
  static const char PARTIAL_TRI[][WAVE_LENGTH] = {
  	{0x00, 0x0C, 0x18, 0x23, 0x2C, 0x34, 0x3A, 0x3D, 0x3F, 0x3D, 0x3A, 0x34, 0x2C, 0x23, 0x18, 0x0C,
  	 0x00, 0xF4, 0xE8, 0xDD, 0xD4, 0xCC, 0xC6, 0xC3, 0xC1, 0xC3, 0xC6, 0xCC, 0xD4, 0xDD, 0xE8, 0xF4},
  	{0x00, 0xFD, 0xFA, 0xFA, 0xFC, 0xFF, 0x02, 0x05, 0x07, 0x05, 0x02, 0xFF, 0xFC, 0xFA, 0xFA, 0xFD,
  	 0x00, 0x03, 0x06, 0x06, 0x04, 0x01, 0xFE, 0xFB, 0xFA, 0xFB, 0xFE, 0x01, 0x04, 0x06, 0x06, 0x03},
  	{0x00, 0x02, 0x02, 0x00, 0xFF, 0xFE, 0x00, 0x01, 0x02, 0x01, 0x00, 0xFE, 0xFF, 0x00, 0x02, 0x02,
  	 0x00, 0xFE, 0xFE, 0x00, 0x01, 0x02, 0x00, 0xFF, 0xFE, 0xFF, 0x00, 0x02, 0x01, 0x00, 0xFE, 0xFE},
  	{0x00, 0xFF, 0x00, 0x01, 0x00, 0x00, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x00, 0x00, 0x01, 0x00, 0xFF,
  	 0x00, 0x01, 0x00, 0xFF, 0x00, 0x00, 0x01, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x00, 0xFF, 0x00, 0x01},
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  };
  
  static const char SAWTOOTH_LP[][WAVE_LENGTH] = {
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x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x2B, 0x28, 0x1C, 0x1A, 0x14, 0x0A, 0x08,
  	 0x00, 0xF8, 0xF6, 0xEC, 0xE6, 0xE4, 0xD8, 0xD5, 0xD1, 0xC4, 0xC5, 0xBD, 0xB0, 0xB8, 0xA4, 0x9B},
  	{0x00, 0x69, 0x56, 0x4C, 0x50, 0x3F, 0x40, 0x38, 0x2F, 0x2F, 0x23, 0x20, 0x1A, 0x10, 0x0F, 0x05,
  	 0x00, 0xFB, 0xF1, 0xF0, 0xE6, 0xE0, 0xDD, 0xD1, 0xD1, 0xC8, 0xC0, 0xC1, 0xB0, 0xB4, 0xAA, 0x97},
  	{0x00, 0x6C, 0x52, 0x50, 0x4D, 0x40, 0x42, 0x34, 0x34, 0x2B, 0x24, 0x21, 0x16, 0x15, 0x0A, 0x07,
  	 0x00, 0xF9, 0xF6, 0xEB, 0xEA, 0xDF, 0xDC, 0xD5, 0xCC, 0xCC, 0xBE, 0xC0, 0xB3, 0xB0, 0xAE, 0x94},
  	{0x00, 0x6E, 0x4F, 0x54, 0x48, 0x44, 0x3F, 0x36, 0x34, 0x29, 0x28, 0x1C, 0x1B, 0x11, 0x0E, 0x06,
  	 0x00, 0xFA, 0xF2, 0xEF, 0xE5, 0xE4, 0xD8, 0xD7, 0xCC, 0xCA, 0xC1, 0xBC, 0xB8, 0xAC, 0xB1, 0x92},
  	{0x00, 0x6E, 0x4D, 0x57, 0x46, 0x48, 0x3B, 0x3A, 0x30, 0x2D, 0x24, 0x20, 0x18, 0x13, 0x0C, 0x06,
  	 0x00, 0xFA, 0xF4, 0xED, 0xE8, 0xE0, 0xDC, 0xD3, 0xD0, 0xC6, 0xC5, 0xB8, 0xBA, 0xA9, 0xB3, 0x92}
  };
  
  static const char SAWTOOTH_HP[][WAVE_LENGTH] = {
  	{0x00, 0x6E, 0x4F, 0x55, 0x48, 0x45, 0x3E, 0x36, 0x33, 0x29, 0x27, 0x1D, 0x1B, 0x11, 0x0D, 0x06,
  	 0x00, 0xFA, 0xF3, 0x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0x0B, 0x03, 0xF8, 0xFD, 0x01, 0x08, 0xFF, 0xFD, 0xFB, 0x04, 0x04,
  	 0x00, 0xFC, 0xFC, 0x05, 0x03, 0x01, 0xF8, 0xFF, 0x03, 0x08, 0xFD, 0xF5, 0xFF, 0x0A, 0x16, 0xD6},
  	{0x00, 0x22, 0xE6, 0xFE, 0x07, 0x06, 0xFB, 0xFA, 0x06, 0x02, 0x00, 0xFA, 0x03, 0x03, 0x00, 0xFB,
  	 0x00, 0x05, 0x00, 0xFD, 0xFD, 0x06, 0x00, 0xFE, 0xFA, 0x06, 0x05, 0xFA, 0xF9, 0x02, 0x1A, 0xDE},
  	{0x00, 0x1A, 0xE6, 0x06, 0x07, 0xFE, 0xFB, 0x02, 0x06, 0xFA, 0x00, 0x02, 0x03, 0xFB, 0x00, 0x03,
  	 0x00, 0xFD, 0x00, 0x05, 0xFD, 0xFE, 0x00, 0x06, 0xFA, 0xFE, 0x05, 0x02, 0xF9, 0xFA, 0x1A, 0xE6},
  	{0x00, 0x13, 0xE9, 0x0C, 0x02, 0xFA, 0x01, 0x03, 0xFF, 0xFC, 0x06, 0xFE, 0xFE, 0x01, 0x03, 0xFC,
  	 0x00, 0x04, 0xFD, 0xFF, 0x02, 0x02, 0xFA, 0x04, 0x01, 0xFD, 0xFF, 0x06, 0xFE, 0xF4, 0x17, 0xED},
  	{0x00, 0x0D, 0xEE, 0x0E, 0xFC, 0xFC, 0x06, 0xFE, 0xFF, 0x02, 0x02, 0xFB, 0x05, 0xFE, 0xFE, 0x02,
  	 0x00, 0xFE, 0x02, 0x02, 0xFB, 0x05, 0xFE, 0xFE, 0x01, 0x02, 0xFA, 0x04, 0x04, 0xF2, 0x12, 0xF3},
  	{0x00, 0x08, 0xF3, 0x0D, 0xF8, 0x02, 0x03, 0xFA, 0x04, 0xFE, 0xFF, 0x01, 0x01, 0xFD, 0x04, 0xFD,
  	 0x00, 0x03, 0xFC, 0x03, 0xFF, 0xFF, 0x01, 0x02, 0xFC, 0x06, 0xFD, 0xFE, 0x08, 0xF3, 0x0D, 0xF8},
  	{0x00, 0x05, 0xF8, 0x09, 0xF8, 0x06, 0xFE, 0xFE, 0x04, 0xFB, 0x05, 0xFD, 0x01, 0x01, 0xFF, 0x01,
  	 0x00, 0xFF, 0x01, 0xFF, 0xFF, 0x03, 0xFB, 0x05, 0xFC, 0x02, 0x02, 0xFA, 0x08, 0xF7, 0x08, 0xFB},
  	{0x00, 0x02, 0xFD, 0x04, 0xFB, 0x05, 0xFC, 0x02, 0x00, 0xFF, 0x03, 0xFC, 0x04, 0xFC, 0x03, 0xFE,
  	 0x00, 0x02, 0xFD, 0x04, 0xFC, 0x04, 0xFD, 0x01, 0x00, 0xFE, 0x04, 0xFB, 0x05, 0xFC, 0x03, 0xFE},
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  	{0x00, 0xFF, 0x01, 0xFE, 0x03, 0xFD, 0x03, 0xFC, 0x04, 0xFC, 0x03, 0xFD, 0x03, 0xFE, 0x01, 0xFF,
  	 0x00, 0x01, 0xFF, 0x02, 0xFD, 0x03, 0xFD, 0x04, 0xFC, 0x04, 0xFD, 0x03, 0xFD, 0x02, 0xFF, 0x01}
  };
  
  static const char SQUARE_LP[][WAVE_LENGTH] = {
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  	{0x00, 0x0C, 0x18, 0x23, 0x2D, 0x34, 0x3A, 0x3E, 0x3F, 0x3E, 0x3A, 0x34, 0x2D, 0x23,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, 0xD2, 0xCD, 0xC9},
  	{0x00, 0x3A, 0x2E, 0x33, 0x32, 0x30, 0x33, 0x2F, 0x34, 0x2F, 0x33, 0x30, 0x32, 0x33, 0x2E, 0x3A,
  	 0x00, 0xC6, 0xD2, 0xCD, 0xCE, 0xD0, 0xCD, 0xD1, 0xCC, 0xD1, 0xCD, 0xD0, 0xCE, 0xCD, 0xD2, 0xC6}
  };
  
  static const char SQUARE_HP[][WAVE_LENGTH] = {
  	{0x00, 0x3A, 0x2E, 0x33, 0x31, 0x31, 0x33, 0x30, 0x33, 0x30, 0x33, 0x31, 0x31, 0x33, 0x2E, 0x3A,
  	 0x00, 0xC6, 0xD2, 0xCD, 0xCF, 0xCF, 0xCD, 0xD0, 0xCD, 0xD0, 0xCD, 0xCF, 0xCF, 0xCD, 0xD2, 0xC6},
  	{0x00, 0x2D, 0x16, 0x10, 0x05, 0xFC, 0xF9, 0xF2, 0xF4, 0xF2, 0xF9, 0xFC, 0x05, 0x10, 0x16, 0x2D,
  	 0x00, 0xD3, 0xEA, 0xF0, 0xFB, 0x04, 0x07, 0x0E, 0x0C, 0x0E, 0x07, 0x04, 0xFB, 0xF0, 0xEA, 0xD3},
  	{0x00, 0x22, 0x02, 0xFB, 0xF6, 0xF8, 0x01, 0x04, 0x09, 0x04, 0x01, 0xF8, 0xF6, 0xFB, 0x02, 0x22,
  	 0x00, 0xDE, 0xFE, 0x05, 0x0A, 0x08, 0xFF, 0xFC, 0xF7, 0xFC, 0xFF, 0x08, 0x0A, 0x05, 0xFE, 0xDE},
  	{0x00, 0x17, 0xF7, 0xF9, 0xFF, 0x05, 0x05, 0xFD, 0xFD, 0xFD, 0x05, 0x05, 0xFF, 0xF9, 0xF7, 0x17,
  	 0x00, 0xE9, 0x09, 0x07, 0x01, 0xFB, 0xFB, 0x03, 0x03, 0x03, 0xFB, 0xFB, 0x01, 0x07, 0x09, 0xE9},
  	{0x00, 0x0E, 0xF3, 0x00, 0x05, 0x00, 0xFD, 0xFE, 0x06, 0xFE, 0xFD, 0x00, 0x05, 0x00, 0xF3, 0x0E,
  	 0x00, 0xF2, 0x0D, 0x00, 0xFB, 0x00, 0x03, 0x02, 0xFA, 0x02, 0x03, 0x00, 0xFB, 0x00, 0x0D, 0xF2},
  	{0x00, 0x08, 0xF6, 0x06, 0x00, 0xFC, 0x04, 0x00, 0xFF, 0x00, 0x04, 0xFC, 0x00, 0x06, 0xF6, 0x08,
  	 0x00, 0xF8, 0x0A, 0xFA, 0x00, 0x04, 0xFC, 0x00, 0x01, 0x00, 0xFC, 0x04, 0x00, 0xFA, 0x0A, 0xF8},
  	{0x00, 0x03, 0xFB, 0x05, 0xFC, 0x01, 0x01, 0xFC, 0x04, 0xFC, 0x01, 0x01, 0xFC, 0x05, 0xFB, 0x03,
  	 0x00, 0xFD, 0x05, 0xFB, 0x04, 0xFF, 0xFF, 0x04, 0xFC, 0x04, 0xFF, 0xFF, 0x04, 0xFB, 0x05, 0xFD},
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  };
  
  static const char TRIANGLE_LP[][WAVE_LENGTH] = {
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  	{0x00, 0x0C, 0x18, 0x23, 0x2D, 0x34, 0x3A, 0x3E, 0x3F, 0x3E, 0x3A, 0x34, 0x2D, 0x23, 0x18, 0x0C,
  	 0x00, 0xF4, 0xE8, 0xDD, 0xD3, 0xCC, 0xC6, 0xC2, 0xC1, 0xC2, 0xC6, 0xCC,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x27, 0x1D, 0x13, 0x0A,
  	 0x00, 0xF6, 0xED, 0xE3, 0xD9, 0xCF, 0xC6, 0xBB, 0xB5, 0xBB, 0xC6, 0xCF, 0xD9, 0xE3, 0xED, 0xF6}
  };
  
  static const char TRIANGLE_HP[][WAVE_LENGTH] = {
  	{0x00, 0x0A, 0x14, 0x1D, 0x27, 0x30, 0x3A, 0x44, 0x4C, 0x44, 0x3A, 0x30, 0x27, 0x1D, 0x14, 0x0A,
  	 0x00, 0xF6, 0xEC, 0xE3, 0xD9, 0xD0, 0xC6, 0xBC, 0xB4, 0xBC, 0xC6, 0xD0, 0xD9, 0xE3, 0xEC, 0xF6},
  	{0x00, 0xFD, 0xFB, 0xFA, 0xFA, 0xFC, 0x00, 0x06, 0x0D, 0x06, 0x00, 0xFC, 0xFA, 0xFA, 0xFB, 0xFD,
  	 0x00, 0x03, 0x05, 0x06, 0x06, 0x04, 0x00, 0xFA, 0xF3, 0xFA, 0x00, 0x04, 0x06, 0x06, 0x05, 0x03},
  	{0x00, 0x01, 0x02, 0x01, 0xFF, 0xFD, 0xFE, 0x00, 0x06, 0x00, 0xFE, 0xFD, 0xFF, 0x01, 0x02, 0x01,
  	 0x00, 0xFF, 0xFE, 0xFF, 0x01, 0x03, 0x02, 0x00, 0xFA, 0x00, 0x02, 0x03, 0x01, 0xFF, 0xFE, 0xFF},
  	{0x00, 0xFF, 0x00, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x03, 0xFF, 0xFE, 0x00, 0x01, 0x00, 0x00, 0xFF,
  	 0x00, 0x01, 0x00, 0x00, 0xFF, 0x00, 0x02, 0x01, 0xFD, 0x01, 0x02, 0x00, 0xFF, 0x00, 0x00, 0x01},
  	{0x00, 0x00, 0x00, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x02, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x01, 0x00, 0xFF, 0x00, 0x01, 0xFE, 0x01, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x00},
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00},
  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  };
  
  // enumerated constants
  
  enum wave_t   : unsigned char { SAWTOOTH, SQUARE, TRIANGLE };
  enum filter_t : unsigned char { LOWP, HIGHP, BANDP, ALLP };
  enum dist_t   : unsigned char { CLIP, WRAP };
  enum phase_t  : unsigned char { NORMAL, RESYNC, RESYN2 };
  enum play_t   : unsigned char { ONCE, LOOP, PINGPONG, MANUAL };
  
  enum exportMode_t
  {
  	EXPORT_NONE  = 0,
  	EXPORT_BIN   = 0x01,
  	EXPORT_FTI   = 0x02,
  	EXPORT_XPMCK = 0x04,
  	EXPORT_DMW   = 0x08,
  };
  
  // data types
  
  struct waveParam
  {
  	unsigned char volume;
  	unsigned char cutoff;
  	unsigned char phase;
  	unsigned char vshift;
  };
  
  struct synthParam
  {
  	wave_t        wave;
  	filter_t      filter;
  	dist_t        dist;
  	unsigned char q;
  	phase_t       phase;
  	waveParam     start;
  	waveParam     end;
  };
  
  struct instParam
  {
  	play_t        play;
  	unsigned char length;
  	unsigned char repeat;
  	unsigned char speed;
  };
  
  struct sequence_t
  {
  	unsigned int length;
  	unsigned int loop;
  	char         data[MAX_SEQ_LENGTH];
  };
  
  typedef unsigned char (waveTable[])[WAVE_LENGTH];
  
  // other constants
  
  static const synthParam DEFAULT_SYNTH = {
  	SAWTOOTH, LOWP, CLIP, 0, NORMAL,
  	{0x10, 0xFF, 0x00, 0x00},
  	{0x10, 0xFF, 0x00, 0x00}
  };
  
  static const instParam DEFAULT_INST = {
  	ONCE, 0x0F, 0x00, 0x04
  };
  
  static const char* HELP = \
  "LSDjSynth, recreation of the LittleSoundDj wave synthesizer\n\n"
  "Usage: \n"
  "  %s volume cutoff phase vshift [options]\n"
  "Note: Initial volume, cutoff, phase and vshift parameters are REQUIRED\n\n"
  "Options:\n"
  "  --sawtooth, --square, --triangle       change waveform\n"
  "  --lowp, --highp, --bandp, --allp       change filter\n"
  "  --q x                                  set filter resonance to x\n"
  "  --clip, --wrap                         change distortion method\n"
  "  --normal, --resync, --resyn2           change horizontal compression method\n"
  "  --once, --loop, --pingpong, --manual   set wave play mode for instrument\n"
  "  --length x                             set wave envelope length to x\n"
  "  --repeat x                             set instrument loop point to x\n"
  "  --speed x                              set instrument wave speed to x\n"
  "  --end volume cutoff phase vshift       interpolate wave parameters\n"
  "  --bin                                  export to raw binary waveform\n"
  "  --fti                                  export to FamiTracker N163 instrument\n"
  "  --xpmck                                export to XPMCK Game Boy wave macro\n"
  "  --dmw                                  export to multiple Deflemask wave files\n"
  "  --fname str                            set output file name to str\n"
  "  --help                                 display this help text\n"
  "  --version                              display version and license info\n\n"
  "See notes.txt for short options and other details.\n"
  "Original version can be obtained at: https://github.com/HertzDevil/LSDjSynth\n";
  
  static const char* VERSION = \
  "LSDjSynth 1.0\n"
  "Copyright (C) 2015 HertzDevil\n"
  "MIT License.\n"
  "LittleSoundDj is (C) Johan Kotlinski\n"
  ".dmw export by Pegmode\n";
  
  static const char* ERR_MSG[] = {
  	"Unknown option",
  	"Invalid synth parameter",
  	"Invalid instrument parameter",
  	"Invalid filter resonance parameter",
  	"Error while creating file",
  	"Error while exporting file",
  	"Unknown waveform",
  	"Unknown filter setting",
  	"Unknown distortion method",
  	"Unknown horizontal compression method",
  	"Unknown wave play setting",
  	"FamiTracker instrument wave sequence is too long",
  };
  
  enum err_msg_index
  {
  	E_UNKNOWN_OPTION = 0,
  	E_SYNTH_PARAM,
  	E_INST_PARAM,
  	E_Q_PARAM,
  	E_FILE,
  	E_EXPORT,
  	E_UNKNOWN_WAVE,
  	E_UNKNOWN_FILTER,
  	E_UNKNOWN_DIST,
  	E_UNKNOWN_PHASE,
  	E_PLAY,
  	E_FTI_SEQ_TOO_LONG,
  };
  