1
0

S3MTools.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * S3MTools.h
  3. * ----------
  4. * Purpose: Definition of S3M file structures and helper functions
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "../soundlib/ModSample.h"
  12. #include "../soundlib/SampleIO.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. // S3M File Header
  15. struct S3MFileHeader
  16. {
  17. // Magic Bytes
  18. enum S3MMagic
  19. {
  20. idEOF = 0x1A,
  21. idS3MType = 0x10,
  22. idPanning = 0xFC,
  23. };
  24. // Tracker Versions in the cwtv field
  25. enum S3MTrackerVersions
  26. {
  27. trackerMask = 0xF000,
  28. versionMask = 0x0FFF,
  29. trkScreamTracker = 0x1000,
  30. trkImagoOrpheus = 0x2000,
  31. trkImpulseTracker = 0x3000,
  32. trkSchismTracker = 0x4000,
  33. trkOpenMPT = 0x5000,
  34. trkBeRoTracker = 0x6000,
  35. trkCreamTracker = 0x7000,
  36. trkAkord = 0x0208,
  37. trkST3_00 = 0x1300,
  38. trkST3_20 = 0x1320,
  39. trkST3_01 = 0x1301,
  40. trkIT2_07 = 0x3207,
  41. trkIT2_14 = 0x3214,
  42. trkBeRoTrackerOld = 0x4100, // Used from 2004 to 2012
  43. trkCamoto = 0xCA00,
  44. };
  45. // Flags
  46. enum S3MHeaderFlags
  47. {
  48. st2Vibrato = 0x01, // Vibrato is twice as deep. Cannot be enabled from UI.
  49. zeroVolOptim = 0x08, // Volume 0 optimisations
  50. amigaLimits = 0x10, // Enforce Amiga limits
  51. fastVolumeSlides = 0x40, // Fast volume slides (like in ST3.00)
  52. };
  53. // S3M Format Versions
  54. enum S3MFormatVersion
  55. {
  56. oldVersion = 0x01, // Old Version, signed samples
  57. newVersion = 0x02, // New Version, unsigned samples
  58. };
  59. char name[28]; // Song Title
  60. uint8le dosEof; // Supposed to be 0x1A, but even ST3 seems to ignore this sometimes (see STRSHINE.S3M by Purple Motion)
  61. uint8le fileType; // File Type, 0x10 = ST3 module
  62. char reserved1[2]; // Reserved
  63. uint16le ordNum; // Number of order items
  64. uint16le smpNum; // Number of sample parapointers
  65. uint16le patNum; // Number of pattern parapointers
  66. uint16le flags; // Flags, see S3MHeaderFlags
  67. uint16le cwtv; // "Made With" Tracker ID, see S3MTrackerVersions
  68. uint16le formatVersion; // Format Version, see S3MFormatVersion
  69. char magic[4]; // "SCRM" magic bytes
  70. uint8le globalVol; // Default Global Volume (0...64)
  71. uint8le speed; // Default Speed (1...254)
  72. uint8le tempo; // Default Tempo (33...255)
  73. uint8le masterVolume; // Sample Volume (0...127, stereo if high bit is set)
  74. uint8le ultraClicks; // Number of channels used for ultra click removal
  75. uint8le usePanningTable; // 0xFC => read extended panning table
  76. uint16le reserved2; // Schism Tracker and OpenMPT use this for their extended version information
  77. uint32le reserved3; // Impulse Tracker hides its edit timer here
  78. uint16le reserved4;
  79. uint16le special; // Pointer to special custom data (unused)
  80. uint8le channels[32]; // Channel setup
  81. };
  82. MPT_BINARY_STRUCT(S3MFileHeader, 96)
  83. // S3M Sample Header
  84. struct S3MSampleHeader
  85. {
  86. enum SampleType
  87. {
  88. typeNone = 0,
  89. typePCM = 1,
  90. typeAdMel = 2,
  91. };
  92. enum SampleFlags
  93. {
  94. smpLoop = 0x01,
  95. smpStereo = 0x02,
  96. smp16Bit = 0x04,
  97. };
  98. enum SamplePacking
  99. {
  100. pUnpacked = 0x00, // PCM
  101. pDP30ADPCM = 0x01, // Unused packing type
  102. pADPCM = 0x04, // MODPlugin ADPCM :(
  103. };
  104. uint8le sampleType; // Sample type, see SampleType
  105. char filename[12]; // Sample filename
  106. uint8le dataPointer[3]; // Pointer to sample data (divided by 16)
  107. uint32le length; // Sample length, in samples
  108. uint32le loopStart; // Loop start, in samples
  109. uint32le loopEnd; // Loop end, in samples
  110. uint8le defaultVolume; // Default volume (0...64)
  111. char reserved1; // Reserved
  112. uint8le pack; // Packing algorithm, SamplePacking
  113. uint8le flags; // Sample flags
  114. uint32le c5speed; // Middle-C frequency
  115. char reserved2[4]; // Reserved
  116. uint16le gusAddress; // Sample address in GUS memory (used for fingerprinting)
  117. uint16le sb512; // SoundBlaster loop expansion stuff
  118. uint32le lastUsedPos; // More SoundBlaster stuff
  119. char name[28]; // Sample name
  120. char magic[4]; // "SCRS" magic bytes ("SCRI" for Adlib instruments)
  121. // Convert an S3M sample header to OpenMPT's internal sample header.
  122. void ConvertToMPT(ModSample &mptSmp, bool isST3 = false) const;
  123. // Convert OpenMPT's internal sample header to an S3M sample header.
  124. SmpLength ConvertToS3M(const ModSample &mptSmp);
  125. // Retrieve the internal sample format flags for this sample.
  126. SampleIO GetSampleFormat(bool signedSamples) const;
  127. // Calculate the sample position in file
  128. uint32 GetSampleOffset() const;
  129. };
  130. MPT_BINARY_STRUCT(S3MSampleHeader, 80)
  131. // Pattern decoding flags
  132. enum S3MPattern
  133. {
  134. s3mEndOfRow = 0x00,
  135. s3mChannelMask = 0x1F,
  136. s3mNotePresent = 0x20,
  137. s3mVolumePresent = 0x40,
  138. s3mEffectPresent = 0x80,
  139. s3mAnyPresent = 0xE0,
  140. s3mNoteOff = 0xFE,
  141. s3mNoteNone = 0xFF,
  142. };
  143. OPENMPT_NAMESPACE_END