Added AudioUtils.
authorJens Alfke <jens@mooseyard.com>
Tue Jun 17 14:57:48 2008 -0700 (2008-06-17)
changeset 141af6415650bf
parent 13 c59dec088990
child 15 06e7d03fd23e
Added AudioUtils.
AudioUtils.h
AudioUtils.mm
ConcurrentOperation.m
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/AudioUtils.h	Tue Jun 17 14:57:48 2008 -0700
     1.3 @@ -0,0 +1,44 @@
     1.4 +//
     1.5 +//  AudioUtils.h
     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 <Cocoa/Cocoa.h>
    1.13 +
    1.14 +#ifdef __cplusplus
    1.15 +extern "C" {
    1.16 +#endif
    1.17 +    
    1.18 +    #define MYCoreAudioErrorDomain @"MYCoreAudioDomain"
    1.19 +
    1.20 +    NSString* MYCAErrorString( OSStatus coreAudioError );
    1.21 +    NSError* MYCAError( OSStatus coreAudioError, NSString *message );
    1.22 +
    1.23 +#ifdef __cplusplus
    1.24 +}
    1.25 +#endif
    1.26 +
    1.27 +       
    1.28 +
    1.29 +#define XWarnIfError(error, operation) \
    1.30 +    do {																	\
    1.31 +        OSStatus __err = error;												\
    1.32 +        if (__err) _MYWarnCAError(__err,@""operation);	\
    1.33 +    } while (0)
    1.34 +
    1.35 +void _MYWarnCAError( OSStatus error, NSString *operation );
    1.36 +
    1.37 +#ifdef __cplusplus
    1.38 +
    1.39 +    #define XThrowIfError(error, operation) \
    1.40 +        do {																	\
    1.41 +            OSStatus __err = error;												\
    1.42 +            if (__err) _MYThrowCAError(__err,@""operation);	\
    1.43 +        } while (0)
    1.44 +
    1.45 +    void _MYThrowCAError( OSStatus error, NSString *operation ) throw(NSError*) __attribute__((noreturn));
    1.46 +
    1.47 +#endif __cplusplus
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/AudioUtils.mm	Tue Jun 17 14:57:48 2008 -0700
     2.3 @@ -0,0 +1,44 @@
     2.4 +//
     2.5 +//  AudioUtils.mm
     2.6 +//  Cloudy
     2.7 +//
     2.8 +//  Created by Jens Alfke on 6/17/08.
     2.9 +//  Copyright 2008 Jens Alfke. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +#import "AudioUtils.h"
    2.13 +
    2.14 +
    2.15 +NSString* MYCAErrorString( OSStatus coreAudioError )
    2.16 +{
    2.17 +    if( coreAudioError >= 0x20202020 )
    2.18 +        return NSFileTypeForHFSTypeCode(coreAudioError);
    2.19 +    else
    2.20 +        return [NSString stringWithFormat: @"%i",coreAudioError];
    2.21 +}
    2.22 +
    2.23 +NSError* MYCAError( OSStatus coreAudioError, NSString *message )
    2.24 +{
    2.25 +    NSString *errStr = $sprintf(@"CoreAudio error %@", MYCAErrorString(coreAudioError));
    2.26 +    if( message )
    2.27 +        message = [message stringByAppendingFormat: @" [%@]", errStr];
    2.28 +    else
    2.29 +        message = errStr;
    2.30 +    NSString *domain = (coreAudioError >= 0x20202020) ?MYCoreAudioErrorDomain :NSOSStatusErrorDomain;
    2.31 +    return [NSError errorWithDomain: domain code: coreAudioError
    2.32 +                           userInfo: $dict({NSLocalizedDescriptionKey, message})];
    2.33 +}
    2.34 +
    2.35 +
    2.36 +void _MYThrowCAError( OSStatus err, NSString *operation ) throw(NSError*)
    2.37 +{
    2.38 +    NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation));
    2.39 +    Warn(@"EXCEPTION: %@",error.localizedDescription);
    2.40 +    throw error;
    2.41 +}
    2.42 +
    2.43 +void _MYWarnCAError( OSStatus err, NSString *operation )
    2.44 +{
    2.45 +    NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation));
    2.46 +    Warn(@"%@",error.localizedDescription);
    2.47 +}
     3.1 --- a/ConcurrentOperation.m	Sun Jun 01 14:01:44 2008 -0700
     3.2 +++ b/ConcurrentOperation.m	Tue Jun 17 14:57:48 2008 -0700
     3.3 @@ -8,7 +8,7 @@
     3.4  
     3.5  #import "ConcurrentOperation.h"
     3.6  
     3.7 -// See file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html#//apple_ref/doc/uid/TP40004591-RH2-DontLinkElementID_4
     3.8 +// See file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html
     3.9  
    3.10  
    3.11  @implementation ConcurrentOperation