AkaoParser.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #ifndef AKAO_PARSER_H
  2. #define AKAO_PARSER_H
  3. #include <Ogre.h>
  4. #include <vector>
  5. #include "common/File.h"
  6. #include "common/TypeDefine.h"
  7. class AkaoParser
  8. {
  9. public:
  10. AkaoParser();
  11. virtual ~AkaoParser();
  12. void Update();
  13. // instrument
  14. void LoadInstruments( const Ogre::String& all_file, const Ogre::String& dat_file );
  15. void UnloadInstruments();
  16. // akao command 0x10
  17. void PlayMusic( const Ogre::String& file );
  18. // debug routines
  19. void DumpSequenceData( const Ogre::String& file );
  20. private:
  21. enum SpuParameter
  22. {
  23. SPU_LEFT_VOLUME = 1 << 0, // 0x00000001
  24. SPU_RIGHT_VOLUME = 1 << 1, // 0x00000002
  25. SPU_PITCH = 1 << 4, // 0x00000010
  26. SPU_START_OFFSET = 1 << 7, // 0x00000080
  27. SPU_ATTACK_RATE = 1 << 8, // 0x00000100
  28. SPU_SUSTAIN_RATE = 1 << 9, // 0x00000200
  29. SPU_RELEASE_RATE = 1 << 10, // 0x00000400
  30. SPU_ATTACK_MODE = 1 << 11, // 0x00000800
  31. SPU_DECAY_RATE = 1 << 12, // 0x00001000
  32. SPU_SUSTAIN_MODE = 1 << 13, // 0x00002000
  33. SPU_RELEASE_MODE = 1 << 14, // 0x00004000
  34. SPU_SUSTAIN_LEVEL = 1 << 15, // 0x00008000
  35. SPU_LOOP_OFFSET = 1 << 16, // 0x00010000
  36. };
  37. enum SpuConfigUpdate
  38. {
  39. SPU_REVERB = 1 << 7, // 0x00000080
  40. };
  41. // instrument
  42. struct InstrumentData
  43. {
  44. u32 start_offset; // 0x00
  45. u32 loop_offset; // 0x04
  46. u8 attack_rate; // 0x08
  47. u8 decay_rate; // 0x09
  48. u8 sustain_level; // 0x0a
  49. u8 sustain_rate; // 0x0b
  50. u8 release_rate; // 0x0c
  51. u8 attack_mode; // 0x0d
  52. u8 sustain_mode; // 0x0e
  53. u8 release_mode; // 0x0f
  54. u32 pitch[ 12 ];
  55. };
  56. std::vector< InstrumentData > m_InstrumentData;
  57. struct ChannelData
  58. {
  59. // 0x00 [][][][]
  60. u32 akao_sequence_pointer;
  61. // 0x04-0x10 [][][][]
  62. u32 loop_pointer[ 4 ];
  63. // 0x18 [][][][] in real here was addreses into wave table, but we store indexes here
  64. u32 wave1_table_index;
  65. // 0x1c [][][][]
  66. u32 wave2_table_index;
  67. // 0x20 [][][][]
  68. u32 wave3_table_index;
  69. // 0x24 [][]
  70. u16 mirror_channel_id;
  71. // 0x2c [][][][]
  72. s32 volume_multiplier;
  73. // 0x30 [][][][]
  74. u32 pitch_base;
  75. // 0x34 [][][][]
  76. s32 pitch_addition;
  77. // 0x38 [][][][]
  78. u32 mirror_update_flags;
  79. // 0x44 [][][][]
  80. s32 volume_level;
  81. // 0x48 [][][][]
  82. s32 volume_level_add;
  83. // 0x4c [][][][]
  84. s32 pitch_growth;
  85. // 0x54 [][]
  86. u16 unknown_54;
  87. // 0x56 [][]
  88. u16 pause;
  89. // 0x58 [][]
  90. int instrument_id;
  91. // 0x5c [][]
  92. u16 volume_level_change_ticks;
  93. // 0x5e [][]
  94. u16 unknown_c6_change_ticks;
  95. // 0x60 [][]
  96. u16 volume_index;
  97. // 0x62 [][]
  98. u16 unknown_62;
  99. // 0x64 [][]
  100. u16 unknown_64;
  101. // 0x66 [][]
  102. u16 pitch_correction;
  103. // 0x68 [][]
  104. u16 unknown_68;
  105. // 0x6a [][]
  106. u16 unknown_6a;
  107. // 0x6c [][]
  108. u16 unknown_6c;
  109. // 0x6e [][]
  110. u16 unknown_6e;
  111. // 0x72 [][]
  112. u16 wave1_delay;
  113. // 0x74 [][]
  114. u16 wave1_delay_current;
  115. // 0x76 [][]
  116. u16 wave1_refresh_interval;
  117. // 0x78 [][]
  118. u16 wave1_refresh_interval_counter;
  119. // 0x7a [][]
  120. u16 wave1_table_node_index;
  121. // 0x7c [][]
  122. u16 wave1_multiplier;
  123. // 0x7e [][]
  124. u16 wave1_modifier;
  125. // 0x86 [][]
  126. u16 wave2_delay;
  127. // 0x88 [][]
  128. u16 wave2_delay_current;
  129. // 0x8c [][]
  130. u16 wave2_refresh_interval_counter;
  131. // 0x8e [][]
  132. u16 wave2_table_node_index;
  133. // 0x9a [][]
  134. u16 wave3_refresh_interval_counter;
  135. // 0x9c [][]
  136. u16 wave3_table_node_index;
  137. // 0xb8 [][]
  138. u16 loop_index;
  139. // 0xba-0xc0 [][]
  140. u16 loop_count[ 4 ];
  141. // 0xc2 [][]
  142. u16 saved_pause;
  143. // 0xc4 [][]
  144. u16 pause_multiplier;
  145. // 0xc6 [][]
  146. u16 unknown_c6;
  147. // 0xc8 [][]
  148. u16 unknown_c8;
  149. // 0xcc [][]
  150. u16 pitch_selector;
  151. // 0xce [][]
  152. s16 pitch_modifier;
  153. // 0xd0 [][]
  154. u16 saved_pitch;
  155. // 0xd2 [][]
  156. u16 unknown_d2;
  157. // 0xd4 [][]
  158. u16 unknown_d4;
  159. // 0xd6 [][]
  160. s16 pitch_addition2;
  161. // 0xd8 [][]
  162. u16 unknown_d8;
  163. // 0xe0 [][][][]
  164. u32 spu_update_flags;
  165. // 0xe4 [][][][]
  166. u32 start_offset;
  167. // 0xe8 [][][][]
  168. u32 loop_offset;
  169. // 0xec [][][][]
  170. u32 attack_mode;
  171. // 0xf0 [][][][]
  172. u32 sustain_mode;
  173. // 0xf4 [][][][]
  174. u32 release_mode;
  175. // 0xf8 [][]
  176. u16 pitch;
  177. // 0xfa [][]
  178. u16 attack_rate;
  179. // 0xfc [][]
  180. u16 decay_rate;
  181. // 0xfe [][]
  182. u16 sustain_level;
  183. // 0x100 [][]
  184. u16 sustain_rate;
  185. // 0x102 [][]
  186. u16 release_rate;
  187. // 0x104 [][]
  188. u16 left_volume;
  189. // 0x106 [][]
  190. u16 right_volume;
  191. };
  192. ChannelData m_MusicChannelData[ 24 ];
  193. struct ChannelConfig
  194. {
  195. // 0x04 [][][][]
  196. u32 active_channel_mask;
  197. // 0x08 [][][][]
  198. u32 for_play_channel_mask;
  199. // 0x0c [][][][]
  200. u32 unknown_0c;
  201. // 0x10 [][][][]
  202. u32 unknown_10;
  203. // 0x18 [][][][]
  204. u32 tempo;
  205. // 0x1c [][][][]
  206. u32 tempo_increment;
  207. // 0x20 [][][][]
  208. u32 tempo_counter;
  209. // 0x2c [][][][]
  210. u32 unknown_2c;
  211. // 0x34 [][][][]
  212. u32 unknown_34;
  213. // 0x38 [][][][]
  214. u32 spu_update_flags;
  215. // 0x40 [][][][]
  216. u32 reverb_depth;
  217. // 0x48 [][]
  218. u16 tempo_increment_counter;
  219. // 0x4e [][]
  220. u16 conditional_value;
  221. // 0x50 [][]
  222. u16 reverb_depth_increment_counter;
  223. // 0x56 [][]
  224. u16 upper_timer_top;
  225. // 0x58 [][]
  226. u16 upper_timer;
  227. // 0x5a [][]
  228. u16 lower_timer_top;
  229. // 0x5c [][]
  230. u16 lower_timer;
  231. // 0x5e [][]
  232. u16 top_timer;
  233. };
  234. ChannelConfig m_MusicChannelConfig;
  235. File* m_Music;
  236. private:
  237. void UpdateDynamicSpuParameters();
  238. void UpdatePitchAndVolume( ChannelData* channel_data, int channel_id );
  239. void UpdateSpu( ChannelData* channel_data, int channel_id );
  240. void UpdatePlayChannel( bool on, u32 channel_mask );
  241. void UpdateSequence( ChannelData* channel_data, int channel_id, ChannelConfig& channel_config );
  242. const u8 NextSequenceHandle( ChannelData* channel_data, int channel_id, ChannelConfig& channel_config );
  243. void UpdateCounters( ChannelData* channel_data, int channel_id, ChannelConfig& channel_config );
  244. void InitChannelInstrument( ChannelData* channel_data, int channel_id, int instrument_id );
  245. };
  246. extern AkaoParser *AKAOPARSER;
  247. #endif // AKAO_PARSER_H