xref: /btstack/3rd-party/hxcmod-player/hxcmod.h (revision c8249f334b7fdc69ce713f0cc754723f04d6ca30)
1 ///////////////////////////////////////////////////////////////////////////////////
2 //-------------------------------------------------------------------------------//
3 //-------------------------------------------------------------------------------//
4 //-----------H----H--X----X-----CCCCC----22222----0000-----0000------11----------//
5 //----------H----H----X-X-----C--------------2---0----0---0----0--1--1-----------//
6 //---------HHHHHH-----X------C----------22222---0----0---0----0-----1------------//
7 //--------H----H----X--X----C----------2-------0----0---0----0-----1-------------//
8 //-------H----H---X-----X---CCCCC-----222222----0000-----0000----1111------------//
9 //-------------------------------------------------------------------------------//
10 //----------------------------------------------------- http://hxc2001.free.fr --//
11 ///////////////////////////////////////////////////////////////////////////////////
12 // File : hxcmod.h
13 // Contains: a tiny mod player
14 //
15 // Written by: Jean Francois DEL NERO
16 //
17 // Change History (most recent first):
18 ///////////////////////////////////////////////////////////////////////////////////
19 
20 #ifndef __HXCMOD_H
21 #define __HXCMOD_H
22 
23 #if defined __cplusplus
24 extern "C" {
25 #endif
26 
27 
28 #ifndef MODPLAY_DEF
29 #define MODPLAY_DEF
30 
31 // Basic type
32 typedef unsigned char	muchar;
33 typedef signed   char   mchar;
34 typedef unsigned short	muint;
35 typedef          short	mint;
36 typedef unsigned long	mulong;
37 
38 #define NUMMAXCHANNELS 32
39 #define MAXNOTES 12*12
40 #define SAMPLE_RATE 44100
41 //
42 // MOD file structures
43 //
44 
45 #pragma pack(1)
46 
47 typedef struct {
48 	muchar  name[22];
49 	muint   length;
50 	muchar  finetune;
51 	muchar  volume;
52 	muint   reppnt;
53 	muint   replen;
54 } sample;
55 
56 typedef struct {
57 	muchar  sampperiod;
58 	muchar  period;
59 	muchar  sampeffect;
60 	muchar  effect;
61 } note;
62 
63 typedef struct {
64 	muchar  title[20];
65 	sample  samples[31];
66 	muchar  length;
67 	muchar  protracker;
68 	muchar  patterntable[128];
69 	muchar  signature[4];
70 	muchar  speed;
71 } module;
72 
73 #pragma pack()
74 
75 //
76 // HxCMod Internal structures
77 //
78 typedef struct {
79 	mchar * sampdata;
80 	muint   sampnum;
81 	muint   length;
82 	muint   reppnt;
83 	muint   replen;
84 	mulong  samppos;
85 	muint   period;
86 	muchar  volume;
87 	mulong  ticks;
88 	muchar  effect;
89 	muchar  parameffect;
90 	muint   effect_code;
91 
92 
93 	mint    decalperiod;
94 	mint    portaspeed;
95 	mint    portaperiod;
96 	mint    vibraperiod;
97 	mint    Arpperiods[3];
98 	muchar  ArpIndex;
99 
100 	mint    oldk;
101 	muchar  volumeslide;
102 
103 	muchar  vibraparam;
104 	muchar  vibrapointeur;
105 
106 	muchar  finetune;
107 
108 	muchar  cut_param;
109 
110 	muint   patternloopcnt;
111 	muint   patternloopstartpoint;
112 } hxcmod_channel;
113 
114 typedef struct {
115 	module  song;
116 	mchar * sampledata[31];
117 	note *  patterndata[128];
118 
119 	mulong  playrate;
120 	muint   tablepos;
121 	muint   patternpos;
122 	muint   patterndelay;
123 	muint   jump_loop_effect;
124 	muchar  bpm;
125 	mulong  patternticks;
126 	mulong  patterntickse;
127 	mulong  patternticksaim;
128 	mulong  sampleticksconst;
129 
130 	mulong  samplenb;
131 
132 	hxcmod_channel channels[NUMMAXCHANNELS];
133 
134 	muint   number_of_channels;
135 
136 	muint   fullperiod[MAXNOTES * 8];
137 
138 	muint   mod_loaded;
139 
140 	mint    last_r_sample;
141 	mint    last_l_sample;
142 
143 	mint    stereo;
144 	mint    stereo_separation;
145 	mint    bits;
146 	mint    filter;
147 
148 } modcontext;
149 
150 //
151 // Player states structures
152 //
153 typedef struct track_state_
154 {
155 	unsigned char instrument_number;
156 	unsigned short cur_period;
157 	unsigned char  cur_volume;
158 	unsigned short cur_effect;
159 	unsigned short cur_parameffect;
160 }track_state;
161 
162 typedef struct tracker_state_
163 {
164 	int number_of_tracks;
165 	int bpm;
166 	int speed;
167 	int cur_pattern;
168 	int cur_pattern_pos;
169 	int cur_pattern_table_pos;
170 	unsigned int buf_index;
171 	track_state tracks[32];
172 }tracker_state;
173 
174 typedef struct tracker_state_instrument_
175 {
176 	char name[22];
177 	int active;
178 }tracker_state_instrument;
179 
180 typedef struct tracker_buffer_state_
181 {
182 	int nb_max_of_state;
183 	int nb_of_state;
184 	int cur_rd_index;
185 	int sample_step;
186 	char name[64];
187 	tracker_state_instrument instruments[31];
188 	tracker_state * track_state_buf;
189 }tracker_buffer_state;
190 
191 ///////////////////////////////////////////////////////////////////////////////////
192 // HxCMOD Core API:
193 // -------------------------------------------
194 // int  hxcmod_init(modcontext * modctx)
195 //
196 // - Initialize the modcontext buffer. Must be called before doing anything else.
197 //   Return 1 if success. 0 in case of error.
198 // -------------------------------------------
199 // int  hxcmod_load( modcontext * modctx, void * mod_data, int mod_data_size )
200 //
201 // - "Load" a MOD from memory (from "mod_data" with size "mod_data_size").
202 //   Return 1 if success. 0 in case of error.
203 // -------------------------------------------
204 // void hxcmod_fillbuffer( modcontext * modctx, unsigned short * outbuffer, unsigned long nbsample, tracker_buffer_state * trkbuf )
205 //
206 // - Generate and return the next samples chunk to outbuffer.
207 //   nbsample specify the number of stereo 16bits samples you want.
208 //   The output format is signed 44100Hz 16-bit Stereo PCM samples.
209 //   The output buffer size in byte must be equal to ( nbsample * 2 * 2 ).
210 //   The optional trkbuf parameter can be used to get detailed status of the player. Put NULL/0 is unused.
211 // -------------------------------------------
212 // void hxcmod_unload( modcontext * modctx )
213 // - "Unload" / clear the player status.
214 // -------------------------------------------
215 ///////////////////////////////////////////////////////////////////////////////////
216 
217 int  hxcmod_init( modcontext * modctx );
218 int  hxcmod_setcfg( modcontext * modctx, int samplerate, int bits, int stereo, int stereo_separation, int filter);
219 int  hxcmod_load( modcontext * modctx, void * mod_data, int mod_data_size );
220 void hxcmod_fillbuffer( modcontext * modctx, unsigned short * outbuffer, unsigned long nbsample, tracker_buffer_state * trkbuf );
221 void hxcmod_unload( modcontext * modctx );
222 
223 #endif
224 
225 
226 #if defined __cplusplus
227 }
228 #endif
229 
230 #endif // __HXCMOD_H
231