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