LMMS
Loading...
Searching...
No Matches
sop.h
Go to the documentation of this file.
1/*
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2005 Simon Peter <dn.tlp@gmx.net>, et al.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * sop.h - sopepos' Note Player by Stas'M <binarymaster@mail.ru>
20 *
21 * REFERENCES:
22 * http://www.shikadi.net/moddingwiki/SOP_Format
23 */
24
25#ifndef H_ADPLUG_SOPPLAYER
26#define H_ADPLUG_SOPPLAYER
27
28#include <stdint.h>
29#include "player.h"
30
31/*
32 * Source code parts from free Ad262Sop Library (c) 1996-2005, Park Jeenhong
33 */
34
35/* percussive voice numbers: */
36#define BD 6
37#define SD 7
38#define TOM 8
39#define CYMB 9
40#define HIHAT 10
41
42#define MAX_VOLUME 0x7f
43#define LOG2_VOLUME 7 /* log2( MAX_VOLUME) */
44
45#define MID_C 60 /* MIDI standard mid C */
46
47#define SOP_TOM_PITCH 36 /* best frequency, in range of 0 to 95 */
48#define TOM_TO_SD 7 /* 7 half-tones between voice 7 & 8 */
49#define SOP_SD_PITCH (SOP_TOM_PITCH + TOM_TO_SD)
50
51#define NB_NOTES 96 /* 8 octave of 12 notes */
52#define OCTAVE 12 /* half-tone by octave */
53#define NB_STEP_PITCH 32 /* 32 steps between two half-tones */
54#define LOG_NB_STEP_PITCH 5 /* LOG2( NB_STEP_PITCH ) */
55#define NB_TABLE_DEMI_TON OCTAVE
56#define TABLE_SIZE (NB_STEP_PITCH * NB_TABLE_DEMI_TON)
57
58#define maxVoices 20
59#define YMB_SIZE 80
60
62{
63public:
65 : opl(newopl)
66 {};
68 {};
69
70 void SoundWarmInit();
71 void SetYM_262_SOP(int VX);
72 void SetMode_SOP(int mode);
73 void SetStereoPan_SOP(int chan, int value);
74 void SetVoiceVolume_SOP(unsigned chan, unsigned vol);
75 void SetVoiceTimbre_SOP(unsigned chan, unsigned char *array);
76 void SetVoicePitch_SOP(unsigned chan, int pitch);
77 void NoteOn_SOP(unsigned chan, unsigned pitch);
78 void NoteOff_SOP(unsigned chan);
79 int Set_4OP_Mode(unsigned chan, unsigned value);
80
81private:
83
84 void UpdateFNums(int chan);
85 void SndOutput1(int addr, int value);
86 void SndOutput3(int addr, int value);
87 void SEND_INS(int base_addr, unsigned char *value, int mode);
88 void SetFreq_SOP(int voice, unsigned note, int pitch, int keyOn);
89
90 char percussion; /* percussion mode parameter */
91 unsigned char VolumeTable[ 64 * 128 ]; /* Pre-calculated Volume Table */
92 char voiceNote[20]; /* pitch of last note-on of each voice */
93 char voiceKeyOn[20]; /* state of keyOn bit of each voice */
94 unsigned char vPitchBend[20]; /* current pitch bend of each voice */
95 unsigned char Ksl[20]; /* KSL value for Slot 1 */
96 unsigned char Ksl2[20]; /* KSL value for Slot 2 */
97 unsigned char Ksl2V[20]; /* Parallel connection? */
98 unsigned char VoiceVolume[20], OP_MASK;
99 unsigned char ymbuf[ 2 * YMB_SIZE ];
100 unsigned char OP4[20];
101 unsigned char Stereo[22];
102
103protected:
104 static const int fNumTbl[TABLE_SIZE];
105 static const unsigned char SlotX[maxVoices * 2];
106 static const unsigned char VolReg[11 * 2];
107 static const unsigned MOD12[OCTAVE * 11];
108 static const unsigned DIV12[OCTAVE * 8];
109};
110
111/******************************************************************/
112
113#define SOP_HEAD_SIZE 76
114#define SOP_SIGN_SIZE 7 /* "sopepos" signature */
115#define SOP_FILENAME 13 /* size of file name tag */
116#define SOP_TITLE 31 /* size of title tag */
117#define SOP_DEF_TEMPO 120 /* default tempo BPM */
118#define SOP_COMMENT 13 /* size of comment tag */
119#define SOP_INSTNAME 8 /* size of instrument file name tag */
120#define SOP_LONGNAME 19 /* size of instrument long name tag */
121#define SOP_INST2OP 11 /* size of 2OP instrument data */
122#define SOP_INST4OP 22 /* size of 4OP instrument data */
123#define SOP_MAX_INST 128 /* maximum number of instruments */
124#define SOP_MAX_TRACK 20 /* maximum number of tracks */
125#define SOP_MAX_VOL 127 /* maximum volume */
126
127#define SOP_CHAN_NONE 0 /* unused channel */
128#define SOP_CHAN_4OP 1 /* channel in 4OP mode */
129#define SOP_CHAN_2OP 2 /* channel in 2OP mode */
130
131#define SOP_INST_4OP 0 /* 4OP instrument */
132#define SOP_INST_2OP 1 /* 2OP instrument */
133#define SOP_INST_BD 6 /* Bass Drum */
134#define SOP_INST_SD 7 /* Snare Drum */
135#define SOP_INST_TT 8 /* Tom Tom */
136#define SOP_INST_CY 9 /* Cymbal */
137#define SOP_INST_HH 10 /* Hi-Hat */
138#define SOP_INST_NONE 12 /* Unused instrument */
139
140#define SOP_EVNT_SPEC 1 /* Special event */
141#define SOP_EVNT_NOTE 2 /* Note event */
142#define SOP_EVNT_TEMPO 3 /* Tempo event */
143#define SOP_EVNT_VOL 4 /* Volume event */
144#define SOP_EVNT_PITCH 5 /* Pitch event */
145#define SOP_EVNT_INST 6 /* Instrument event */
146#define SOP_EVNT_PAN 7 /* Panning event */
147#define SOP_EVNT_MVOL 8 /* Master volume event */
148
149class CsopPlayer: public CPlayer
150{
151public:
152 static CPlayer *factory(Copl *newopl);
153
155 : CPlayer(newopl), chanMode(0), inst(0), track(0)
156 { }
158 {
159 if (chanMode) delete[] chanMode;
160 if (inst) delete[] inst;
161 if (track)
162 {
163 for (int i = 0; i < nTracks + 1; i++)
164 {
165 if (track[i].data) delete[] track[i].data;
166 }
167 delete[] track;
168 }
169 if (drv) drv->~Cad262Driver();
170 };
171
172 bool load(const std::string &filename, const CFileProvider &fp);
173 bool update();
174 void rewind(int subsong);
175
177 {
178 return timer;
179 };
180
181 unsigned int getspeed()
182 {
183 return cur_tempo;
184 };
185
186 std::string gettitle()
187 {
188 return title[0] ? std::string(title) : std::string(fname);
189 }
190
191 std::string gettype()
192 {
193 return std::string("Note Sequencer by sopepos");
194 }
195
196 std::string getdesc()
197 {
198 return std::string(comment);
199 }
200
201 unsigned int getinstruments()
202 {
203 return inst ? nInsts : 0;
204 };
205
206 std::string getinstrument(unsigned int n)
207 {
208 return inst && n < nInsts ? std::string(inst[n].longname) : std::string();
209 };
210
211private:
212 void SetTempo(uint8_t tempo);
215
216protected:
218 float timer;
219 uint8_t cur_tempo; /* current tempo in BPM */
220 uint8_t volume[SOP_MAX_TRACK]; /* actual volume of all voices */
221 uint8_t lastvol[SOP_MAX_TRACK]; /* last set volume of all voices */
222 uint8_t master_vol; /* master volume */
223
229
236 struct sop_trk {
237 // stored variables
238 uint16_t nEvents; /* event count */
239 uint32_t size; /* data size */
240 uint8_t * data; /* event data */
241
242 // variables for playback
243 uint32_t pos; /* data position */
244 uint32_t counter; /* tick counter */
245 uint16_t ticks; /* ticks to wait for next event */
246 uint16_t dur; /* note play duration */
247 };
248 uint8_t * chanMode; /* channel modes [nTracks] */
249 sop_inst * inst; /* instruments [nInsts] */
250 sop_trk * track; /* event tracks [nTracks + control track] */
251};
252
253#endif
Definition fprovide.h:29
CPlayer(Copl *newopl)
Definition player.cpp:34
Definition sop.h:62
void SetVoiceVolume_SOP(unsigned chan, unsigned vol)
Definition sop.cpp:545
unsigned char OP4[20]
Definition sop.h:100
int Set_4OP_Mode(unsigned chan, unsigned value)
Definition sop.cpp:799
void SetMode_SOP(int mode)
Definition sop.cpp:400
unsigned char VoiceVolume[20]
Definition sop.h:98
void SetVoicePitch_SOP(unsigned chan, int pitch)
Definition sop.cpp:740
void SetYM_262_SOP(int VX)
Definition sop.cpp:505
unsigned char Stereo[22]
Definition sop.h:101
unsigned char OP_MASK
Definition sop.h:98
static const int fNumTbl[TABLE_SIZE]
Definition sop.h:330
char percussion
Definition sop.h:90
unsigned char VolumeTable[64 *128]
Definition sop.h:91
void SetFreq_SOP(int voice, unsigned note, int pitch, int keyOn)
Definition sop.cpp:708
void SndOutput3(int addr, int value)
Definition sop.cpp:480
void SEND_INS(int base_addr, unsigned char *value, int mode)
Definition sop.cpp:490
void UpdateFNums(int chan)
Definition sop.cpp:462
void NoteOn_SOP(unsigned chan, unsigned pitch)
Definition sop.cpp:755
char voiceKeyOn[20]
Definition sop.h:93
~Cad262Driver()
Definition sop.h:67
void SndOutput1(int addr, int value)
Definition sop.cpp:470
void SetStereoPan_SOP(int chan, int value)
Definition sop.cpp:511
unsigned char Ksl[20]
Definition sop.h:95
unsigned char Ksl2V[20]
Definition sop.h:97
void SoundWarmInit()
Definition sop.cpp:418
unsigned char ymbuf[2 *YMB_SIZE]
Definition sop.h:99
unsigned char vPitchBend[20]
Definition sop.h:94
unsigned char Ksl2[20]
Definition sop.h:96
static const unsigned char SlotX[maxVoices *2]
Definition sop.h:365
void NoteOff_SOP(unsigned chan)
Definition sop.cpp:782
void SetVoiceTimbre_SOP(unsigned chan, unsigned char *array)
Definition sop.cpp:625
static const unsigned DIV12[OCTAVE *8]
Definition sop.h:389
static const unsigned MOD12[OCTAVE *11]
Definition sop.h:375
Cad262Driver(Copl *newopl)
Definition sop.h:64
char voiceNote[20]
Definition sop.h:92
Copl * opl
Definition sop.h:82
static const unsigned char VolReg[11 *2]
Definition sop.h:370
Definition opl.h:26
void executeCommand(uint8_t t)
Definition sop.cpp:214
std::string getinstrument(unsigned int n)
Definition sop.h:206
sop_trk * track
Definition sop.h:250
CsopPlayer(Copl *newopl)
Definition sop.h:154
static CPlayer * factory(Copl *newopl)
Definition sop.cpp:29
bool update()
Definition sop.cpp:286
uint8_t cur_tempo
Definition sop.h:219
char title[SOP_TITLE]
Definition sop.h:225
void SetTempo(uint8_t tempo)
Definition sop.cpp:204
uint8_t * chanMode
Definition sop.h:248
Cad262Driver * drv
Definition sop.h:214
uint8_t basicTempo
Definition sop.h:226
uint8_t tickBeat
Definition sop.h:226
uint8_t master_vol
Definition sop.h:222
uint8_t lastvol[SOP_MAX_TRACK]
Definition sop.h:221
std::string gettitle()
Definition sop.h:186
float timer
Definition sop.h:218
void rewind(int subsong)
Definition sop.cpp:168
std::string gettype()
Definition sop.h:191
uint8_t percussive
Definition sop.h:226
unsigned int getinstruments()
Definition sop.h:201
char comment[SOP_COMMENT]
Definition sop.h:227
std::string getdesc()
Definition sop.h:196
uint8_t nTracks
Definition sop.h:228
char fname[SOP_FILENAME]
Definition sop.h:224
unsigned int getspeed()
Definition sop.h:181
~CsopPlayer()
Definition sop.h:157
bool songend
Definition sop.h:217
sop_inst * inst
Definition sop.h:249
uint8_t nInsts
Definition sop.h:228
float getrefresh()
Definition sop.h:176
uint8_t volume[SOP_MAX_TRACK]
Definition sop.h:220
bool load(const std::string &filename, const CFileProvider &fp)
Definition sop.cpp:34
struct huft * t
Definition inflate.c:943
register unsigned i
Definition inflate.c:1575
static char filename[]
Definition features.c:5
static PuglViewHint int value
Definition pugl.h:1708
JSAMPIMAGE data
Definition jpeglib.h:945
unsigned short uint16_t
Definition mid.cpp:99
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
png_structrp int mode
Definition png.h:1139
#define TABLE_SIZE
Definition sop.h:56
#define SOP_MAX_TRACK
Definition sop.h:124
#define SOP_INSTNAME
Definition sop.h:119
#define OCTAVE
Definition sop.h:52
#define SOP_FILENAME
Definition sop.h:115
#define SOP_LONGNAME
Definition sop.h:120
#define YMB_SIZE
Definition sop.h:59
#define SOP_COMMENT
Definition sop.h:118
#define SOP_INST4OP
Definition sop.h:122
#define SOP_TITLE
Definition sop.h:116
#define maxVoices
Definition sop.h:58
Definition sop.h:230
char filename[SOP_INSTNAME+1]
Definition sop.h:232
uint8_t data[SOP_INST4OP]
Definition sop.h:234
uint8_t type
Definition sop.h:231
char longname[SOP_LONGNAME+1]
Definition sop.h:233
Definition sop.h:236
uint32_t pos
Definition sop.h:243
uint16_t dur
Definition sop.h:246
uint16_t nEvents
Definition sop.h:238
uint32_t counter
Definition sop.h:244
uint16_t ticks
Definition sop.h:245
uint32_t size
Definition sop.h:239
uint8_t * data
Definition sop.h:240
int n
Definition crypt.c:458