• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Convenience method, function for converting 4CCs to strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Convenience method, function for converting 4CCs to strings


  • Subject: Convenience method, function for converting 4CCs to strings
  • From: Chris Adamson <email@hidden>
  • Date: Thu, 28 May 2009 15:41:31 -0400

Because "fmt?" has shown up a few times recently, and because I'm writing about four char codes and their occasional use in OSStatuses, I thought I'd post two convenience routines I've written for converting 4CCs to NSStrings or CFStringRefs.  Take your pick:

CFStringRef createCFStringFor4CC (CFStringRef fourCCString) {
UInt32 errorCode = CFStringGetIntValue(fourCCString);
errorCode = CFSwapInt32HostToBig (errorCode);
return CFStringCreateWithFormat (
kCFAllocatorDefault, NULL,
(CFStringRef) @"%4.4s", (char*)&errorCode);
}

- (NSString*) stringFor4CC: (NSString*) fourCCString {
UInt32 errorCode = [fourCCString intValue];
errorCode = CFSwapInt32HostToBig (errorCode); 
return [NSString stringWithFormat: @"%4.4s", (char*)&errorCode];
}

The Obj-C version returns an autoreleased string, but the C version you'll have to CFRelease() when you're done with it.

The need to do an endian flip kind of surprised me.  I guess I would have expected that a definition like:
        kAudioFileUnsupportedDataFormatError = 'fmt?',
would have maintained the same byte order from the header to the iPhone Simulator or device.  Or maybe it does and I'm just not thinking through where each char ends up when it's stored as a UInt32?

--Chris

 _______________________________________________
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

  • Follow-Ups:
    • Re: Convenience method, function for converting 4CCs to strings
      • From: Doug Wyatt <email@hidden>
    • Re: Convenience method, function for converting 4CCs to strings
      • From: Chris Adamson <email@hidden>
  • Prev by Date: Re: Multi channel mixer - kAudioUnitSubType_MultiChannelMixer
  • Next by Date: Re: Convenience method, function for converting 4CCs to strings
  • Previous by thread: Re: shipping an aggregate device
  • Next by thread: Re: Convenience method, function for converting 4CCs to strings
  • Index(es):
    • Date
    • Thread