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