[DUG] C code help
Brian Wrigley
bswrigley at xtra.co.nz
Thu Jul 13 23:10:29 NZST 2006
Hi Ross,
----- Original Message -----
From: Ross Levis
To: NZ Borland Developers Group - Delphi List
Sent: Thursday, July 13, 2006 9:07 PM
Subject: Re: [DUG] C code help
Just to clarify this a bit...
An audio file tag format uses 4 bytes to store a flag to indicate whether text or binary information is stored in the following tag. The C++ source code uses these definitions
#define TAG_FIELD_FLAG_DATA_TYPE_MASK (6)
#define TAG_FIELD_FLAG_DATA_TYPE_TEXT_UTF8 (0 << 1)
#define TAG_FIELD_FLAG_DATA_TYPE_BINARY (1 << 1)
#define TAG_FIELD_FLAG_DATA_TYPE_EXTERNAL_INFO (2 << 1)
#define TAG_FIELD_FLAG_DATA_TYPE_RESERVED (3 << 1)
Am I correct in assuming that a Binary flag will appear like this in the file (in Hex).
00 00 00 02
Effectively a big endian value of 02. Is this correct?
Essentially, yes.
It's a two-bit field by the look of it, using bits 1 and 2 of the word (numbering from bit 0 = least significant to 31 = most significant).
6 (bit pattern 110) is the mask, ie it's used with a bitwise AND to select just those two bits from the word.
the four values of the two-bit field are apparently:
0 = Text UTF8
1 = binary
2 = External Info
3 - reserved
So not just a simple 1-bit flag like I thought from what you posted in the first message.
With the various values of that field the whole word might look like:
0000 0000 = Text UTF8
0000 0002 = binary
0000 0004 = External Info
0000 0006 - reserved
Except, we don't know what might be in the rest of the word. Probably not zeroes, so the values you are interested in will be combined with other fields. Possibly even, that 3-bit field is repeated several times in the word, with additional masking and shifting being used to pick fields out. In your first message, you also showed:
#define APE_TAG_FLAG_CONTAINS_FOOTER (1 << 30)
which suggests bit 30 is also used as a one-bit flag. But whether this is in the same word or not can't necessarily be determined from the #defines. You'll probably need to find the code that masks, sets and tests these fields to be sure how they're used, for example look for something like:
value = (word & TAG_FIELD_FLAG_DATA_TYPE_MASK) >> 1;
to extract the value of the field from the word;
or, to set the value to, say "External Info":
word &= ~TAG_FIELD_FLAG_DATA_TYPE_MASK;
word |= TAG_FIELD_FLAG_DATA_TYPE_EXTERNAL_INFO;
To achieve the same operations in Delphi, use the bitwise logical operators not, and, or, xor, shl and shr. Snipped from the help screen:
--------------------------------------------------------------------------------
The following logical operators perform bitwise manipulation on integer operands. For example, if the value stored in X (in binary) is 001101 and the value stored in Y is 100001, the statement
Z := X or Y;
assigns the value 101101 to Z.
Operator Operation Operand types Result type Examples
not bitwise negation integer integer not X
and bitwise and integer integer X and Y
or bitwise or integer integer X or Y
xor bitwise xor integer integer X xor Y
shl bitwise shift left integer integer X shl 2
shr bitwise shift right integer integer Y shl I
The following rules apply to bitwise operators.
The result of a not operation is of the same type as the operand.
If the operands of an and, or, or xor operation are both integers, the result is of the predefined integer type with the smallest range that includes all possible values of both types.
The operations x shl y and x shr y shift the value of x to the left or right by y bits, which is equivalent to multiplying or dividing x by 2^y; the result is of the same type as x
. For example, if N stores the value 01101 (decimal 13), then N shl 1 returns 11010 (decimal 26).
--------------------------------------------------------------------------------
Hope some of this helps clarify things a bit and doesn't just muddy it further,
Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20060713/3f35a0c7/attachment.html
More information about the Delphi
mailing list