MIDI header in C

  • Follow


Hey!

Can anybody give me a full MIDI header in C. I already have sth. like this:

struct Header     {
   char           ID[4];
   unsigned long  Length;
   unsigned short Format;
   unsigned short NumTracks;
   unsigned short Division;
   unsigned char  Data[6];
};

but something is wrong, because when I try to read the Format value, it
gives me 256 (and it should be between 0 and 2 ;) ). What should I do? any
tips?

Kuba


0
Reply Kuba 3/4/2004 12:48:29 PM

Kuba Araszkiewicz wrote:
> Hey!
> 
> Can anybody give me a full MIDI header in C. I already have sth. like this:
> 
> struct Header     {
>    char           ID[4];
>    unsigned long  Length;
>    unsigned short Format;
>    unsigned short NumTracks;
>    unsigned short Division;
>    unsigned char  Data[6];
> };
> 
> but something is wrong, because when I try to read the Format value, it
> gives me 256 (and it should be between 0 and 2 ;) ). What should I do? any
> tips?

values in a MIDI file are not in intel byte order so you cannot use this 
as struct on intel machines

you must define them e.g.  as

unsigned char Format[2]

and read them reverse

e.g. by resorting them before reading
or better
    by shifting the bytes to
their correct position inside the larger value  (shift operator    <<)

see Jeff Glatt pages about MIDI format

0
Reply Guenter 3/4/2004 1:35:14 PM


1 Replies
194 Views

(page loaded in 0.042 seconds)

Similiar Articles:













7/16/2012 6:44:45 AM


Reply: