/************************************************************************ Auxiliary function for midi-file IO Copyright (C) 1994, 1995 by R.Harmsen Original date: 26 December 1994. Slight corrections, for portability to Linux, under standard C (C89, C90 or C99): 7 March 2025. ***********************************************************************/ /******************************************************************** Puts the binary number in in the two-byte buffer out, in a little-endian fashion: most-significant left (low address), less significant more to the right (higher adresses). On little-endian processors (Motorola for example) this is just a binary copy, but on big-endians like Intel-80x86, it is physically a wordwise byte swap. Returns out. *******************************************************************/ unsigned char *int2twochars (unsigned char *out, int in); /******************************************************************** Same for longs of 4 bytes. Returns out. *******************************************************************/ unsigned char *long2fourchars (unsigned char *out, long in); /******************************************************************** *******************************************************************/ int twochars2int (unsigned char *in); /******************************************************************** *******************************************************************/ long fourchars2long (unsigned char *in); /******************************************************************** Input is a 32 bit number. Output, in buf, is the same number split into 7-bits portions, where all but the rightmost character have their bit 7 set. The filled length of the buffer (min 1, max 5) is returned. (This variable length count format is used frequently in MIDI-files, for delta-time, and the length of the data portion of meta-messages, starting with 0xff.) *******************************************************************/ int var_length (long in, unsigned char *buf); /******************************************************************** Conversion the other way round. *******************************************************************/ long varlen2long (unsigned char *buf, int *p_bytes_used);