AudioUtils.mm
changeset 16 ce9c83f7ec14
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/AudioUtils.mm	Sun Jul 13 10:45:42 2008 -0700
     1.3 @@ -0,0 +1,44 @@
     1.4 +//
     1.5 +//  AudioUtils.mm
     1.6 +//  Cloudy
     1.7 +//
     1.8 +//  Created by Jens Alfke on 6/17/08.
     1.9 +//  Copyright 2008 Jens Alfke. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import "AudioUtils.h"
    1.13 +
    1.14 +
    1.15 +NSString* MYCAErrorString( OSStatus coreAudioError )
    1.16 +{
    1.17 +    if( coreAudioError >= 0x20202020 )
    1.18 +        return NSFileTypeForHFSTypeCode(coreAudioError);
    1.19 +    else
    1.20 +        return [NSString stringWithFormat: @"%i",coreAudioError];
    1.21 +}
    1.22 +
    1.23 +NSError* MYCAError( OSStatus coreAudioError, NSString *message )
    1.24 +{
    1.25 +    NSString *errStr = $sprintf(@"CoreAudio error %@", MYCAErrorString(coreAudioError));
    1.26 +    if( message )
    1.27 +        message = [message stringByAppendingFormat: @" [%@]", errStr];
    1.28 +    else
    1.29 +        message = errStr;
    1.30 +    NSString *domain = (coreAudioError >= 0x20202020) ?MYCoreAudioErrorDomain :NSOSStatusErrorDomain;
    1.31 +    return [NSError errorWithDomain: domain code: coreAudioError
    1.32 +                           userInfo: $dict({NSLocalizedDescriptionKey, message})];
    1.33 +}
    1.34 +
    1.35 +
    1.36 +void _MYThrowCAError( OSStatus err, NSString *operation ) throw(NSError*)
    1.37 +{
    1.38 +    NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation));
    1.39 +    Warn(@"EXCEPTION: %@",error.localizedDescription);
    1.40 +    throw error;
    1.41 +}
    1.42 +
    1.43 +void _MYWarnCAError( OSStatus err, NSString *operation )
    1.44 +{
    1.45 +    NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation));
    1.46 +    Warn(@"%@",error.localizedDescription);
    1.47 +}