Mod.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // Original MOD & XM playback code from JUDAS Soundsystem
  24. // Copyright (c) 1997 Lasse Öörni & Olli Niemitalo
  25. #ifndef AUDIO_MOD_H
  26. #define AUDIO_MOD_H
  27. #include "Song.h"
  28. #include <string>
  29. #include <vector>
  30. class Channel;
  31. class Sound;
  32. //! MOD identification string and corresponding channel count
  33. struct ModIdent
  34. {
  35. std::string mString;
  36. int mChannels;
  37. };
  38. //! MOD note
  39. struct ModNote
  40. {
  41. unsigned char mNote;
  42. unsigned char mInstrNum;
  43. unsigned char mCommand;
  44. unsigned char mData;
  45. };
  46. //! MOD instrument
  47. struct ModInstrument
  48. {
  49. SharedPtr<Sound> mSound;
  50. signed char mVolume;
  51. unsigned char mFineTune;
  52. };
  53. //! MOD track state
  54. struct ModTrack
  55. {
  56. ModInstrument* mInstr;
  57. unsigned char mNewNote;
  58. unsigned char mNote;
  59. unsigned char mInstrNum;
  60. unsigned char mNewInstrNum;
  61. unsigned char mEffect;
  62. unsigned char mEffectData;
  63. unsigned char mNybble1;
  64. unsigned char mNybble2;
  65. unsigned char mSmp;
  66. signed char mFineTune;
  67. signed char mVolume;
  68. unsigned short mBasePeriod;
  69. unsigned short mPeriod;
  70. unsigned short mTargetPeriod;
  71. bool mTonePortamento;
  72. bool mUseSoundOffset;
  73. unsigned char mTonePortaSpeed;
  74. unsigned char mSoundOffset;
  75. unsigned char mVolSpeedUp;
  76. unsigned char mVolSpeedDown;
  77. unsigned char mPortaSpeedUp;
  78. unsigned char mPortaSpeedDown;
  79. unsigned char mVibratoType;
  80. unsigned char mVibratoSpeed;
  81. unsigned char mVibratoDepth;
  82. unsigned char mVibratoPhase;
  83. unsigned char mGlissando;
  84. unsigned char mTremoloType;
  85. unsigned char mTremoloSpeed;
  86. unsigned char mTremoloDepth;
  87. unsigned char mTremoloPhase;
  88. unsigned char mPatternLoopLine;
  89. unsigned char mPatternLoopCount;
  90. unsigned char mRetrigCount;
  91. };
  92. //! MOD format song resource
  93. class Mod : public Song
  94. {
  95. DEFINE_TYPE(Mod);
  96. public:
  97. //! Construct with audio subsystem pointer and name
  98. Mod(Audio* audio, const std::string& name = std::string());
  99. //! Destruct. Stop playback and free song data
  100. virtual ~Mod();
  101. //! Load the resource
  102. virtual void load(Deserializer& source, ResourceCache* cache = 0);
  103. //! Play from a specified position
  104. virtual void play(unsigned position = 0);
  105. //! Return current position
  106. virtual unsigned getPosition() const { return mPos; }
  107. //! MOD identification strings
  108. static const ModIdent sIdent[];
  109. //! MOD frequency table
  110. static const unsigned short sPeriodTable[16][12];
  111. protected:
  112. //! Update player
  113. virtual void updatePlayer();
  114. private:
  115. //! Release song data
  116. void release();
  117. //! Start new note
  118. void startNewNote(ModTrack* tptr, Channel* chptr);
  119. //! Perform toneportamento effect
  120. void tonePortamento(ModTrack* tptr, Channel* chptr);
  121. //! Perform vibrato effect
  122. void vibrato(ModTrack* tptr, Channel* chptr);
  123. //! Perform volume slide effect
  124. void volumeSlide(ModTrack* tptr, Channel* chptr);
  125. //! Perform extended command
  126. void extendedCommand(ModTrack* tptr, Channel* chptr);
  127. //! Sequencer position
  128. unsigned char mPos;
  129. //! Position within pattern
  130. unsigned char mLine;
  131. //! Song length
  132. unsigned char mLength;
  133. //! Tick tempo
  134. unsigned char mTickTempo;
  135. //! Tick counter
  136. unsigned char mTickCount;
  137. //! Pattern delay counter
  138. unsigned char mPatternDelay;
  139. //! Pattern break flag
  140. bool mPatternBreak;
  141. //! Number of channels
  142. unsigned mNumChannels;
  143. //! Number of patterns
  144. unsigned mNumPatterns;
  145. //! Pattern size in bytes
  146. unsigned mPatternLength;
  147. //! MOD info block
  148. SharedArrayPtr<unsigned char> mInfo;
  149. //! MOD pattern data
  150. SharedArrayPtr<unsigned char> mPatterns;
  151. //! MOD instruments
  152. std::vector<ModInstrument> mInstruments;
  153. //! MOD track states
  154. std::vector<ModTrack> mTracks;
  155. };
  156. #endif // AUDIO_MOD_H