-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExampleAUGraph.m
More file actions
96 lines (77 loc) · 2.29 KB
/
ExampleAUGraph.m
File metadata and controls
96 lines (77 loc) · 2.29 KB
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
87
88
89
90
91
92
93
94
95
96
//
// ExampleAUGraph.m
// AudioUnitExample
//
// Created by Lucius Kwok on 11/28/10.
// Copyright 2010 Felt Tip Inc. All rights reserved.
//
#import "ExampleAUGraph.h"
@implementation ExampleAUGraph
- (id)init {
self = [super init];
if (self) {
OSStatus err;
// Create a new AUGraph.
err = NewAUGraph (&auGraph);
NSAssert1 (err == noErr, @"NewAUGraph() error %d", err);
// Always keep the graph open
err = AUGraphOpen (auGraph);
NSAssert1 (err == noErr, @"AUGraphOpen() error %d", err);
// Always initialized.
[self initialize];
}
return self;
}
- (void)dealloc {
DisposeAUGraph(auGraph);
[super dealloc];
}
- (AUNode)addNodeWithComponentType:(OSType)componentType subType:(OSType)subType manufacturer:(OSType)manufacturer
{
AUNode aNode = 0;
AudioComponentDescription desc;
desc.componentType = componentType;
desc.componentSubType = subType;
desc.componentManufacturer = manufacturer;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
OSStatus err = AUGraphAddNode (auGraph, &desc, &aNode);
NSAssert1 (err == noErr, @"AUGraphAddNode() error %d", err);
return aNode;
}
- (AUNode)addNodeWithComponentDescription:(AudioComponentDescription)desc {
AUNode aNode = 0;
OSStatus err = AUGraphAddNode (auGraph, &desc, &aNode);
NSAssert1 (err == noErr, @"AUGraphAddNode() error %d", err);
return aNode;
}
- (void)removeNode:(AUNode)aNode {
if (aNode == 0) return;
OSStatus err = AUGraphRemoveNode (auGraph, aNode);
NSAssert1 (err == noErr, @"AUGraphRemoveNode() error %d", err);
}
- (AudioUnit)audioUnitForNode:(AUNode)aNode {
AudioUnit unit;
OSStatus err = AUGraphNodeInfo(auGraph, aNode, NULL, &unit);
NSAssert1 (err == noErr, @"AUGraphNodeInfo() error %d", err);
return unit;
}
- (void)update {
OSStatus err = AUGraphUpdate(auGraph, NULL);
NSAssert1 (err == noErr, @"AUGraphUpdate() error %d", err);
}
- (BOOL)isInitialized {
Boolean result = NO;
OSStatus err = AUGraphIsInitialized(auGraph, &result);
NSAssert1 (err == noErr, @"AUGraphIsInitialized() error %d", err);
return (result != 0);
}
- (void)initialize {
OSStatus err = AUGraphInitialize(auGraph);
NSAssert1 (err == noErr, @"AUGraphInitialize() error %d", err);
}
- (void)uninitialize {
OSStatus err = AUGraphUninitialize(auGraph);
NSAssert1 (err == noErr, @"AUGraphUninitialize() error %d", err);
}
@end