AudioUtils.mm
author Jens Alfke <jens@mooseyard.com>
Wed Apr 22 16:46:38 2009 -0700 (2009-04-22)
changeset 26 252c13061ee5
permissions -rw-r--r--
Fixed a few compiler warnings.
     1 //
     2 //  AudioUtils.mm
     3 //  Cloudy
     4 //
     5 //  Created by Jens Alfke on 6/17/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "AudioUtils.h"
    10 
    11 
    12 NSString* MYCAErrorString( OSStatus coreAudioError )
    13 {
    14     if( coreAudioError >= 0x20202020 )
    15         return NSFileTypeForHFSTypeCode(coreAudioError);
    16     else
    17         return [NSString stringWithFormat: @"%i",coreAudioError];
    18 }
    19 
    20 NSError* MYCAError( OSStatus coreAudioError, NSString *message )
    21 {
    22     NSString *errStr = $sprintf(@"CoreAudio error %@", MYCAErrorString(coreAudioError));
    23     if( message )
    24         message = [message stringByAppendingFormat: @" [%@]", errStr];
    25     else
    26         message = errStr;
    27     NSString *domain = (coreAudioError >= 0x20202020) ?MYCoreAudioErrorDomain :NSOSStatusErrorDomain;
    28     return [NSError errorWithDomain: domain code: coreAudioError
    29                            userInfo: $dict({NSLocalizedDescriptionKey, message})];
    30 }
    31 
    32 
    33 void _MYThrowCAError( OSStatus err, NSString *operation ) throw(NSError*)
    34 {
    35     NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation));
    36     Warn(@"EXCEPTION: %@",error.localizedDescription);
    37     throw error;
    38 }
    39 
    40 void _MYWarnCAError( OSStatus err, NSString *operation )
    41 {
    42     NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation));
    43     Warn(@"%@",error.localizedDescription);
    44 }