ScummVM API documentation
module_mod_xm_s3m.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on IBXM mod player
24  *
25  * Copyright (c) 2015, Martin Cameron
26  * All rights reserved.
27  *
28  * Redistribution and use in source and binary forms, with or
29  * without modification, are permitted provided that the
30  * following conditions are met:
31  *
32  * * Redistributions of source code must retain the above
33  * copyright notice, this list of conditions and the
34  * following disclaimer.
35  *
36  * * Redistributions in binary form must reproduce the
37  * above copyright notice, this list of conditions and the
38  * following disclaimer in the documentation and/or other
39  * materials provided with the distribution.
40  *
41  * * Neither the name of the organization nor the names of
42  * its contributors may be used to endorse or promote
43  * products derived from this software without specific
44  * prior written permission.
45 
46  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
47  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
49  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
51  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
52  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
54  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
55  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
58  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59  * POSSIBILITY OF SUCH DAMAGE.
60  *
61  */
62 
63 #ifndef AUDIO_MODS_MODULE_MOD_XM_S3M_H
64 #define AUDIO_MODS_MODULE_MOD_XM_S3M_H
65 
66 #include "common/scummsys.h"
67 
68 namespace Common {
69 class SeekableReadStream;
70 }
71 
72 namespace Modules {
73 
74 struct Note {
75  byte key;
76  byte instrument;
77  byte volume;
78  byte effect; // effect type
79  byte param; // parameter of effect
80 };
81 
82 struct Pattern {
83  int numChannels, numRows;
84  Note *notes;
85 
86  Note getNote(int row, int chan) const {
87  Note res;
88  if (row >= 0 && chan >= 0 && row < numRows && chan < numChannels)
89  res = notes[row * numChannels + chan];
90  else
91  memset(&res, 0, sizeof(struct Note));
92  return res;
93  }
94 };
95 
96 struct Sample {
97  char name[32]; // sample name
98  int16 finetune; // fine tune
99  int16 volume; // volume
100  int length; // loop start
101  int loopStart; // loop start
102  int loopLength; // loop length
103  int16 panning;
104  int16 relNote;
105  int16 *data;
106 };
107 
108 struct Envelope {
109  byte enabled, sustain, looped, numPoints;
110  uint16 sustainTick, loopStartTick, loopEndTick;
111  uint16 pointsTick[16], pointsAmpl[16];
112 };
113 
114 struct Instrument {
115  int numSamples, volFadeout;
116  char name[32], keyToSample[97];
117  int8 vibType, vibSweep, vibDepth, vibRate;
118  Envelope volEnv, panEnv;
119  Sample *samples;
120 };
121 
123 
124 private:
125  static const int FP_SHIFT;
126  static const int FP_ONE;
127  static const int FP_MASK;
128  static const int exp2table[];
129 
130 public:
131  // sound properties
132  byte name[32];
133  int sequenceLen;
134  int restartPos;
135  byte *sequence;
136 
137  // patterns
138  int numChannels;
139  int numPatterns;
140  Pattern *patterns;
141 
142  // instruments
143  int numInstruments;
144  Instrument *instruments;
145 
146  // others
147  int defaultGvol, defaultSpeed, defaultTempo, c2Rate, gain;
148  bool linearPeriods, fastVolSlides;
149  byte *defaultPanning;
150 
151  ModuleModXmS3m();
152  ~ModuleModXmS3m();
153 
154  bool load(Common::SeekableReadStream &stream);
155 
156  // math functions
157  static int moduleLog2(int x);
158  static int moduleExp2(int x);
159 
160 private:
161  bool loadMod(Common::SeekableReadStream &stream);
162  bool loadXm(Common::SeekableReadStream &stream);
163  bool loadS3m(Common::SeekableReadStream &stream);
164  bool loadAmf(Common::SeekableReadStream &st);
165 
166  void readSampleSint8(Common::SeekableReadStream &stream, int length, int16 *dest);
167  void readSampleSint16LE(Common::SeekableReadStream &stream, int length, int16 *dest);
168 
169  void SamplePingPong(Sample &sample);
170 };
171 
172 } // End of namespace Modules
173 
174 #endif
Definition: module_mod_xm_s3m.h:114
Definition: module.h:31
Definition: module_mod_xm_s3m.h:122
Definition: stream.h:745
Definition: module_mod_xm_s3m.h:108
Definition: module_mod_xm_s3m.h:74
Definition: algorithm.h:29
Definition: module_mod_xm_s3m.h:96
Definition: module_mod_xm_s3m.h:82