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