forked from robbiehanson/AlarmClock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTCoreAudioDevice.m
85 lines (69 loc) · 2.15 KB
/
MTCoreAudioDevice.m
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
//
// MTCoreAudioDevice.m
// MTCoreAudio.framework
//
// Created by Michael Thornburgh on Sun Dec 16 2001.
// Copyright (c) 2001 Michael Thornburgh. All rights reserved.
//
#import "MTCoreAudioDevice.h"
@implementation MTCoreAudioDevice
+ (MTCoreAudioDevice *) deviceWithID:(AudioDeviceID)theID
{
return [[[[self class] alloc] initWithDeviceID:theID] autorelease];
}
+ (MTCoreAudioDevice *) _defaultDevice:(int)whichDevice
{
OSStatus theStatus;
UInt32 theSize;
AudioDeviceID theID;
theSize = sizeof(AudioDeviceID);
theStatus = AudioHardwareGetProperty ( whichDevice, &theSize, &theID );
if (theStatus == 0)
return [[self class] deviceWithID:theID];
return nil;
}
+ (MTCoreAudioDevice *) defaultOutputDevice
{
return [[self class] _defaultDevice:kAudioHardwarePropertyDefaultOutputDevice];
}
+ (MTCoreAudioDevice *) defaultSystemOutputDevice
{
return [[self class] _defaultDevice:kAudioHardwarePropertyDefaultSystemOutputDevice];
}
- (MTCoreAudioDevice *) initWithDeviceID:(AudioDeviceID)theID
{
if(self = [super init])
{
myDevice = theID;
}
return self;
}
- (Float32) volumeForChannel:(UInt32)theChannel forDirection:(MTCoreAudioDirection)theDirection
{
OSStatus theStatus;
UInt32 theSize;
Float32 theVolumeScalar;
theSize = sizeof(Float32);
theStatus = AudioDeviceGetProperty ( myDevice, theChannel, theDirection, kAudioDevicePropertyVolumeScalar, &theSize, &theVolumeScalar );
if (theStatus == 0)
return theVolumeScalar;
else
return 0.0;
}
- (void) setVolume:(Float32)theVolume forChannel:(UInt32)theChannel forDirection:(MTCoreAudioDirection)theDirection
{
OSStatus theStatus;
UInt32 theSize;
theSize = sizeof(Float32);
theStatus = AudioDeviceSetProperty ( myDevice, NULL, theChannel, theDirection, kAudioDevicePropertyVolumeScalar, theSize, &theVolume );
}
- (void) setMute:(BOOL)isMuted forChannel:(UInt32)theChannel forDirection:(MTCoreAudioDirection)theDirection
{
OSStatus theStatus;
UInt32 theSize;
UInt32 theMuteVal;
theSize = sizeof(UInt32);
if (isMuted) theMuteVal = 1; else theMuteVal = 0;
theStatus = AudioDeviceSetProperty ( myDevice, NULL, theChannel, theDirection, kAudioDevicePropertyMute, theSize, &theMuteVal );
}
@end