1 | /*
|
---|
2 | * Copyright (c) 2014 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup trackmod
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file Extended Module (.xm) types.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef TYPES_XM_H
|
---|
37 | #define TYPES_XM_H
|
---|
38 |
|
---|
39 | #include <stdint.h>
|
---|
40 |
|
---|
41 | enum {
|
---|
42 | /** ID text (signature) */
|
---|
43 | xm_id_text_size = 17,
|
---|
44 | /** Module name size */
|
---|
45 | xm_mod_name_size = 20,
|
---|
46 | /** Tracker name size */
|
---|
47 | xm_tracker_name_size = 20,
|
---|
48 | /** Pattern order table size */
|
---|
49 | xm_pat_ord_table_size = 256,
|
---|
50 | /** Instrument name size */
|
---|
51 | xm_instr_name_size = 22,
|
---|
52 | /** Sample number for all notes table size */
|
---|
53 | xm_smp_note_size = 96,
|
---|
54 | /** Max number of volume envelope points */
|
---|
55 | xm_vol_env_points = 48,
|
---|
56 | /** Max number of panning envelope points */
|
---|
57 | xm_pan_env_points = 48,
|
---|
58 | /** Sample name size */
|
---|
59 | xm_smp_name_size = 22,
|
---|
60 | /** Keyoff note number */
|
---|
61 | xm_keyoff_note = 97
|
---|
62 | };
|
---|
63 |
|
---|
64 | /** XM file header */
|
---|
65 | typedef struct {
|
---|
66 | uint8_t id_text[xm_id_text_size];
|
---|
67 | /** Module name */
|
---|
68 | uint8_t name[xm_mod_name_size];
|
---|
69 | /** Text EOF mark */
|
---|
70 | uint8_t text_break;
|
---|
71 | /** Tracker name */
|
---|
72 | uint8_t tracker_name[xm_tracker_name_size];
|
---|
73 | /** File format version */
|
---|
74 | uint16_t version;
|
---|
75 | /** Header size */
|
---|
76 | uint32_t hdr_size;
|
---|
77 | /** Song length (in pattern order table) */
|
---|
78 | uint16_t song_len;
|
---|
79 | /** Restart position */
|
---|
80 | uint16_t restart_pos;
|
---|
81 | /** Number of channels */
|
---|
82 | uint16_t channels;
|
---|
83 | /** Number of patterns */
|
---|
84 | uint16_t patterns;
|
---|
85 | /** Number of intstruments */
|
---|
86 | uint16_t instruments;
|
---|
87 | /** Flags */
|
---|
88 | uint16_t flags;
|
---|
89 | /** Default tempo */
|
---|
90 | uint16_t def_tempo;
|
---|
91 | /** Default BPM */
|
---|
92 | uint16_t def_bpm;
|
---|
93 | uint8_t pat_ord_table[xm_pat_ord_table_size];
|
---|
94 | } __attribute__((packed)) xm_hdr_t;
|
---|
95 |
|
---|
96 | typedef enum {
|
---|
97 | /** 1 = Linear frequency table, 0 = Amiga freq. table */
|
---|
98 | xmf_lftable = 0
|
---|
99 | } xm_flags_bits_t;
|
---|
100 |
|
---|
101 | /** XM pattern header */
|
---|
102 | typedef struct {
|
---|
103 | /** Pattern header size */
|
---|
104 | uint32_t hdr_size;
|
---|
105 | /** Packing type */
|
---|
106 | uint8_t pack_type;
|
---|
107 | /** Number of rows */
|
---|
108 | uint16_t rows;
|
---|
109 | /** Packed pattern data size */
|
---|
110 | uint16_t data_size;
|
---|
111 | } __attribute__((packed)) xm_pattern_t;
|
---|
112 |
|
---|
113 | /** XM instrument header. */
|
---|
114 | typedef struct {
|
---|
115 | /** Instrument size */
|
---|
116 | uint32_t size;
|
---|
117 | /** Instrument name */
|
---|
118 | uint8_t name[xm_instr_name_size];
|
---|
119 | /** Instrument type */
|
---|
120 | uint8_t instr_type;
|
---|
121 | /** Number of samples in instrument */
|
---|
122 | uint16_t samples;
|
---|
123 | } __attribute__((packed)) xm_instr_t;
|
---|
124 |
|
---|
125 | /** XM additional instrument header if number of samples > 0 */
|
---|
126 | typedef struct {
|
---|
127 | /** Sample header size */
|
---|
128 | uint32_t smp_hdr_size;
|
---|
129 | /** Sample number for all notes */
|
---|
130 | uint8_t smp_note[xm_smp_note_size];
|
---|
131 | /** Points for volume envelope */
|
---|
132 | uint8_t vol_point[xm_vol_env_points];
|
---|
133 | /** Points for panning envelope */
|
---|
134 | uint8_t pan_point[xm_pan_env_points];
|
---|
135 | /** Number of volume points */
|
---|
136 | uint8_t vol_points;
|
---|
137 | /** Number of panning points */
|
---|
138 | uint8_t pan_points;
|
---|
139 | /** Volume sustating point */
|
---|
140 | uint8_t vol_sustain;
|
---|
141 | /** Volume loop start point */
|
---|
142 | uint8_t vol_loop_start;
|
---|
143 | /** Volume loop end point */
|
---|
144 | uint8_t vol_loop_end;
|
---|
145 | /** Panning sustating point */
|
---|
146 | uint8_t pan_sustain;
|
---|
147 | /** Panning loop start point */
|
---|
148 | uint8_t pan_loop_start;
|
---|
149 | /** Panning loop end point */
|
---|
150 | uint8_t pan_loop_end;
|
---|
151 | /** Volume type */
|
---|
152 | uint8_t vol_type;
|
---|
153 | /** Panning type */
|
---|
154 | uint8_t pan_type;
|
---|
155 | /** Vibrato type */
|
---|
156 | uint8_t vibrato_type;
|
---|
157 | /** Vibrato sweep */
|
---|
158 | uint8_t vibrato_sweep;
|
---|
159 | /** Vibrato depth */
|
---|
160 | uint8_t vibrato_depth;
|
---|
161 | /** Vibrato rate */
|
---|
162 | uint8_t vibrato_rate;
|
---|
163 | /** Volume fadeout */
|
---|
164 | uint16_t vol_fadeout;
|
---|
165 | /** Reserved */
|
---|
166 | uint16_t res241;
|
---|
167 | } __attribute__((packed)) xm_instr_ext_t;
|
---|
168 |
|
---|
169 | /** XM sample header */
|
---|
170 | typedef struct {
|
---|
171 | /** Sample length */
|
---|
172 | uint32_t length;
|
---|
173 | /** Loop start */
|
---|
174 | uint32_t loop_start;
|
---|
175 | /** Loop length */
|
---|
176 | uint32_t loop_len;
|
---|
177 | /** Volume */
|
---|
178 | uint8_t volume;
|
---|
179 | /** Finetune */
|
---|
180 | int8_t finetune;
|
---|
181 | /** Sample type */
|
---|
182 | uint8_t smp_type;
|
---|
183 | /** Panning */
|
---|
184 | uint8_t panning;
|
---|
185 | /** Relative note number */
|
---|
186 | int8_t rel_note;
|
---|
187 | /** Reserved */
|
---|
188 | uint8_t res17;
|
---|
189 | /** Sample name */
|
---|
190 | uint8_t name[xm_smp_name_size];
|
---|
191 | } __attribute__((packed)) xm_smp_t;
|
---|
192 |
|
---|
193 | /** XM sample type bits */
|
---|
194 | typedef enum {
|
---|
195 | /** 16-bit sample data */
|
---|
196 | xmst_16_bit = 4,
|
---|
197 | /** Loop type (H) */
|
---|
198 | xmst_loop_type_h = 1,
|
---|
199 | /** Loop type (L) */
|
---|
200 | xmst_loop_type_l = 0
|
---|
201 | } xm_smp_type_bits_t;
|
---|
202 |
|
---|
203 | /** Sample loop type */
|
---|
204 | typedef enum {
|
---|
205 | /** No loop */
|
---|
206 | xmsl_no_loop = 0,
|
---|
207 | /** Forward loop */
|
---|
208 | xmsl_forward_loop = 1,
|
---|
209 | /** Ping-pong loop */
|
---|
210 | xmsl_pingpong_loop = 2
|
---|
211 | } xm_smp_loop_type;
|
---|
212 |
|
---|
213 | #endif
|
---|
214 |
|
---|
215 | /** @}
|
---|
216 | */
|
---|