1 /*************************************************************************** 2 * S3m/Mod player by Daniel Marks (dmarks@ais.net) 3 * GUS support by David Jeske (jeske@uiuc.edu) 4 * 5 * (C) 1994,1995 By Daniel Marks and David Jeske 6 * 7 * While we retain the copyright to this code, this source code is FREE. 8 * You may use it in any way you wish, in any product you wish. You may 9 * NOT steal the copyright for this code from us. 10 * 11 * We respectfully ask that you email one of us, if possible, if you 12 * produce something significant with this code, or if you have any bug 13 * fixes to contribute. We also request that you give credit where 14 * credit is due if you include part of this code in a program of your own. 15 * 16 * Email: s3mod@uiuc.edu 17 * jeske@uiuc.edu 18 * 19 * See the associated README file for Thanks 20 *************************************************************************** 21 * 22 * mod.h - mod/s3m portable module 23 * 24 */ 25 26 #ifndef _MOD_H 27 #define _MOD_H 1 28 29 #include "config.h" 30 31 #ifdef NEAR_FAR_PTR 32 typedef uint8 near *sample8_near; 33 typedef uint16 near *sample16_near; 34 typedef uint8 far *sample8_far; 35 typedef uint16 far *sample16_far; 36 typedef uint8 far *pattern_ptr; 37 #else 38 typedef uint8 *sample8_near; 39 typedef uint16 *sample16_near; 40 typedef uint8 *sample8_far; 41 typedef uint16 *sample16_far; 42 typedef uint8 *pattern_ptr; 43 #endif 44 45 #define EFF_VOL_SLIDE 0x01 46 #define EFF_PORT_DOWN 0x02 47 #define EFF_PORT_UP 0x04 48 #define EFF_VIBRATO 0x08 49 #define EFF_ARPEGGIO 0x10 50 #define EFF_PORT_TO 0x20 51 #define EFF_TREMOLO 0x40 52 #define EFF_RETRIG 0x80 53 54 #define MIX_BUF_SIZE 2048 55 #define DEF_TEMPO_NTSC 6 56 #define DEF_TEMPO_PAL 6 57 #define DEF_BPM_NTSC 125 58 #define DEF_BPM_PAL 145 59 #define MIDCRATE 8448 60 61 #define MAX_SAMPLES 100 62 #define MAX_TRACKS 32 63 64 #define S3M_MAGIC1 0x101A 65 #define S3M_MAGIC2 "SCRM" 66 #define S3M_INSTR2 "SCRS" 67 68 typedef struct _s3m_header 69 { 70 int8 name[28]; 71 uint16 s3m_magic_1; 72 uint16 npi1; 73 uint16 seq_len; 74 uint16 n_instr; 75 uint16 n_patts; 76 uint16 word_4; 77 uint32 long_1; 78 int8 s3m_magic_2[4]; 79 uint8 volume; 80 uint8 tempo; 81 uint8 bpm; 82 uint8 fill_1[13]; 83 uint8 channel_maps[32]; 84 } s3m_header; 85 86 typedef struct _s3m_instr 87 { 88 uint8 flag; 89 int8 name[13]; 90 uint16 position; 91 uint32 size; 92 uint32 rep_start; 93 uint32 rep_end; 94 uint16 volume; 95 uint8 byte_1; 96 uint8 looped; 97 uint16 period_fine; 98 uint8 fill_3[10]; 99 uint16 word_3; 100 uint16 word_4; 101 int8 comment[28]; 102 int8 id[4]; 103 } s3m_instr; 104 105 typedef struct _mod_voice 106 { 107 int8 sample_name[22]; 108 uint16 sample_length; 109 uint8 finetune_value; 110 uint8 volume; 111 uint16 repeat_point; 112 uint16 repeat_length; 113 } mod_voice; 114 115 typedef struct _song_data 116 { 117 int8 name[20]; 118 uint8 tracks; 119 uint8 track_shift; 120 pattern_ptr patterns[256]; 121 sample8_far samples[MAX_SAMPLES]; 122 uint16 sample_length[MAX_SAMPLES]; 123 uint32 finetune_rate[MAX_SAMPLES]; 124 uint16 period_low_limit[MAX_SAMPLES]; 125 uint16 period_high_limit[MAX_SAMPLES]; 126 uint16 finetune_value[MAX_SAMPLES]; 127 uint16 volume[MAX_SAMPLES]; 128 uint16 repeat_point[MAX_SAMPLES]; 129 uint16 repeat_length[MAX_SAMPLES]; 130 uint8 positions[256]; 131 uint8 song_length_patterns; 132 uint8 song_repeat_patterns; 133 uint16 bpm; 134 uint16 tempo; 135 uint8 s3m; 136 } song_data; 137 138 typedef struct _song_15 139 { 140 uint8 song_length_patterns; 141 uint8 song_repeat_patterns; 142 uint8 positions[128]; 143 } song_15; 144 145 typedef struct track_info 146 { 147 sample8_far samples; 148 uint16 position; 149 uint16 length; 150 uint16 repeat; 151 uint16 replen; 152 int8 volume; 153 int8 error; 154 uint16 pitch; 155 uint16 old_position; 156 157 158 int8 samp; 159 int8 note_hit; /* for the GUS */ 160 int8 note; /* for the GUS */ 161 int16 panning; /* for the GUS -127 to 127 */ 162 int16 playing_period; /* for GUS */ 163 int8 playing_volume; /* for GUS */ 164 int16 start_period; /* the period at the start of the 165 track 166 */ 167 int16 period; 168 uint16 step; 169 uint8 effect; 170 uint16 portto; 171 uint8 vibpos; 172 uint8 trempos; 173 uint16 oldsampofs; 174 int16 arp[3]; 175 uint16 arpindex; 176 177 int16 oldperiod; 178 int16 vol_slide; 179 uint16 port_inc; 180 uint16 port_up; 181 uint16 port_down; 182 uint16 vib_rate; 183 uint16 vib_depth; 184 uint16 trem_rate; 185 uint16 trem_depth; 186 uint8 retrig; 187 188 uint32 finetune_rate; 189 uint16 period_low_limit; 190 uint16 period_high_limit; 191 } track_info; 192 193 #ifdef NEAR_FAR_PTR 194 typedef track_info near *track_info_ptr; 195 #else 196 typedef track_info *track_info_ptr; 197 #endif 198 199 int load_mod(char *filename, song_data *data, int8 noprint); 200 int16 load_s3m(char *filename, song_data *data, int8 noprint); 201 void startplaying(int loud); 202 void updatetracks(void); 203 void mixtrack_8_stereo(track_info *track, uint8 *buffer, uint16 buflen, uint32 channel); 204 void mixtrack_8_mono(track_info *track, uint8 *buffer, uint16 buflen); 205 void mixtrack_16_stereo(track_info *track, uint16 *buffer, uint16 buflen, uint32 channel); 206 void mixtrack_16_mono(track_info *track, uint16 *buffer, uint16 buflen); 207 208 extern uint8 sintable[]; 209 extern song_data mod; 210 extern uint8 order_pos; 211 extern uint8 tempo; 212 extern uint8 tempo_wait; 213 extern uint8 bpm; 214 extern uint8 row; 215 extern uint8 break_row; 216 extern uint16 bpm_samples; 217 extern uint8 *buf_ptr; 218 extern uint16 buf_len; 219 extern uint16 buf_rep; 220 extern pattern_ptr note; 221 extern track_info tracks[]; 222 extern track_info old_tracks[]; 223 extern int16 mod_done; 224 extern uint8 loop_mod; 225 extern uint16 period_set[]; 226 227 228 union vol_union 229 { 230 int8 vol_table[16640]; 231 int16 vol_table16[16640]; 232 }; 233 234 extern union vol_union vol; 235 236 #endif /* _MOD_H */ 237