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