7 typedef unsigned char octet
;
8 typedef int (*reader
)(octet
* buf
, int count
);
11 int bytes2short(octet arr
[2]){
12 return (arr
[1]<<8) | arr
[0];
15 int bytes2int(octet arr
[4]){
16 return (arr
[3]<<24) | (arr
[2]<<16) | (arr
[1]<<8) | arr
[0];
20 /* read a bunch of bytes and discard */
21 void skip_ahead(reader pull
, int count
){
34 octet
read_one(reader pull
){
40 int get_delta(reader pull
){
41 octet a
= read_one(pull
);
44 octet b
= read_one(pull
);
45 if(b
<0x80){return ((a
&0x7f)<<7) | b
;}
47 octet c
= read_one(pull
);
48 if(c
<0x80){return ((a
&0x7f)<<14) | ((b
&0x7f)<<7) | c
;}
50 octet d
= read_one(pull
);
51 return ((a
&0x7f)<<21) | ((b
&0x7f)<<14) | ((c
&0x7f)<<7) | d
;
55 int orgux_load_song(orgux_state
* S
, int (*pull
) (unsigned char* buf
, int bytes
)){
58 char string
[STRING_MAX
];
63 if(pull(buf
,4)<0) return -1;
66 if(pull(buf
,4)<0) return -1;
68 /*format type: 0x0000 0x0001 or 0x0002*/
69 if(pull(buf
,2)<0) return -1;
72 if(pull(buf
,2)<0) return -1;
73 int track_count
= bytes2short(buf
);
76 if(pull(buf
,2)<0) return -1;
77 //code to figure out time division
79 for(int i
=0; i
<track_count
; i
++){
82 if(pull(buf
,4)<0) return -1;
85 if(pull(buf
,4)<0) return -1;
86 int chunk_size
= bytes2int(buf
);
90 int delta
= get_delta(pull
);
96 /* get ticks per beat */
97 /* get time signature */
98 /* get us per quarter note */
102 /* for each track, each event, append event */
104 /* check for LoopStart and LoopEnd */