Re: CAF file, testing chunk types?
Re: CAF file, testing chunk types?
- Subject: Re: CAF file, testing chunk types?
- From: Brian Willoughby <email@hidden>
- Date: Wed, 30 Sep 2009 22:27:39 -0700
In the first example, you are casting the data type to a multi-byte
type, a 32-bit unsigned, and then dereferencing it. This technique
is byte-order-dependent, and produces the wrong result when reading a
big-endian file like CAF on a little-endian processor like Intel.
In the second example, you are casting the data type to a single-byte
type, a character (array), and thus you're not actually changing the
order of anything.
Note: The CAF chunk types appear in the file as a byte sequence which
reads correctly left-to-right. If you read this byte (character)
sequence on any computer, little or big, you'll get the right
result. Just avoid casting or dereferencing 32-bit variables (or 16-
bit, etc.) and you'll be fine. You won't be able to avoid this for
the chunk length, though, so be prepared to use different techniques
for those pieces of CAF.
Brian Willoughby
Sound Consulting
On Sep 30, 2009, at 22:12, Darren Minifie wrote:
-(NSString*)fileType{
if(!fileType){
// debug code:
UInt32 letters = *(UInt32*)[fileData bytes];
// The proper output should be 'caff', but as i expected,
this prints out
// 'ffac' instead
printf("****** the value of letters in hex is %x*****\n",
letters);
// This is the original code. it produces the correct
output on a little endian system
// i.e. fileType consains the string "caff"
char type [5];
type[4] = '\0';
memcpy(type, (char*)[fileData bytes], 4);
fileType = [[NSString stringWithCString:type
encoding:NSASCIIStringEncoding] retain];
}
return fileType;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden