forked from libpd/libpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioHelpers.h
86 lines (71 loc) · 2.7 KB
/
AudioHelpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// AudioHelpers.h
// libpd
//
// Created on 18/10/11.
//
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "LICENSE.txt," in this distribution.
//
// Updated 2018, 2020 Dan Wilcox <danomatika@gmail.com>
//
#import <Foundation/Foundation.h>
#pragma mark Audio Unit / Audio Session Debugging
/// uncomment this to log more information from the audio classes
/// or define it in "Other C Flags" build settings
//#define AU_DEBUG_VERBOSE
/// returns AVAudioSession OSStatus error code as a string
extern NSString *AVStatusCodeAsString(OSStatus status);
/// returns the AudioUnit OSStatus error code as a string
extern NSString *AUStatusCodeAsString(OSStatus status);
/// log debug info along with the class, function, and line number
#define AU_LOG(nslog_string, ...) do {\
NSLog((@"%s[%d] " nslog_string), __func__, __LINE__, ##__VA_ARGS__);\
} while (0)
/// same as AU_LOG, but only logs if AU_DEBUG_VERBOSE is defined
#if defined(AU_DEBUG_VERBOSE)
#define AU_LOGV(nslog_string, ...) AU_LOG(nslog_string, ##__VA_ARGS__)
#else
#define AU_LOGV(nslog_string, ...)
#endif
/// a debug check, which will only log if the value is non-zero
#define AU_LOG_IF_ERROR(value, nslog_string, ...) do {\
if (value) {\
NSLog((@"*** ERROR *** %s[%d] " nslog_string), __func__, __LINE__, ##__VA_ARGS__);\
}\
} while (0)
/// check if the audio unit had an error, and if so print it and return
#define AU_RETURN_IF_ERROR(status) do {\
if (status) {\
NSLog(@"*** ERROR *** %s[%d] status code = %@", __func__, __LINE__, AUStatusCodeAsString(status));\
return;\
}\
} while (0)
/// check if the audio unit had an error, and if so print it and return false
#define AU_RETURN_FALSE_IF_ERROR(status) do {\
if (status) {\
NSLog(@"*** ERROR *** %s[%d] status code = %@", __func__, __LINE__, AUStatusCodeAsString(status));\
return false;\
}\
} while (0)
/// check if the audio unit had an error, and if so print it, dispose the audio unit, and return
#define AU_DISPOSE_IF_ERROR(status, audioUnit) do {\
if (status) {\
AudioComponentInstanceDispose(audioUnit);\
NSLog(@"*** ERROR *** %s[%d] status code = %@", __func__, __LINE__, AUStatusCodeAsString(status));\
return;\
}\
} while (0)
/// check if the audio unit had an error, and if so print it, dispose the audio unit, and return false
#define AU_DISPOSE_FALSE_IF_ERROR(status, audioUnit) do {\
if (status) {\
AudioComponentInstanceDispose(audioUnit);\
NSLog(@"*** ERROR *** %s[%d] status code = %@", __func__, __LINE__, AUStatusCodeAsString(status));\
return false;\
}\
} while (0)
#pragma mark Math Helpers
/// returns YES if floats are equal within 0.0001
extern BOOL floatsAreEqual(Float64 f1, Float64 f2);
/// log shift calculation
extern int log2int(int x);