jens@14: // jens@14: // AudioUtils.mm jens@14: // Cloudy jens@14: // jens@14: // Created by Jens Alfke on 6/17/08. jens@14: // Copyright 2008 Jens Alfke. All rights reserved. jens@14: // jens@14: jens@14: #import "AudioUtils.h" jens@14: jens@14: jens@14: NSString* MYCAErrorString( OSStatus coreAudioError ) jens@14: { jens@14: if( coreAudioError >= 0x20202020 ) jens@14: return NSFileTypeForHFSTypeCode(coreAudioError); jens@14: else jens@14: return [NSString stringWithFormat: @"%i",coreAudioError]; jens@14: } jens@14: jens@14: NSError* MYCAError( OSStatus coreAudioError, NSString *message ) jens@14: { jens@14: NSString *errStr = $sprintf(@"CoreAudio error %@", MYCAErrorString(coreAudioError)); jens@14: if( message ) jens@14: message = [message stringByAppendingFormat: @" [%@]", errStr]; jens@14: else jens@14: message = errStr; jens@14: NSString *domain = (coreAudioError >= 0x20202020) ?MYCoreAudioErrorDomain :NSOSStatusErrorDomain; jens@14: return [NSError errorWithDomain: domain code: coreAudioError jens@14: userInfo: $dict({NSLocalizedDescriptionKey, message})]; jens@14: } jens@14: jens@14: jens@14: void _MYThrowCAError( OSStatus err, NSString *operation ) throw(NSError*) jens@14: { jens@14: NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation)); jens@14: Warn(@"EXCEPTION: %@",error.localizedDescription); jens@14: throw error; jens@14: } jens@14: jens@14: void _MYWarnCAError( OSStatus err, NSString *operation ) jens@14: { jens@14: NSError *error = MYCAError(err, $sprintf(@"Error in %@", operation)); jens@14: Warn(@"%@",error.localizedDescription); jens@14: }