Jamoma API  0.6.0.a19
CAHALAudioStream.cpp
1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
2 
3  Disclaimer: IMPORTANT: This Apple software is supplied to you by
4  Apple Inc. ("Apple") in consideration of your agreement to the
5  following terms, and your use, installation, modification or
6  redistribution of this Apple software constitutes acceptance of these
7  terms. If you do not agree with these terms, please do not use,
8  install, modify or redistribute this Apple software.
9 
10  In consideration of your agreement to abide by the following terms, and
11  subject to these terms, Apple grants you a personal, non-exclusive
12  license, under Apple's copyrights in this original Apple software (the
13  "Apple Software"), to use, reproduce, modify and redistribute the Apple
14  Software, with or without modifications, in source and/or binary forms;
15  provided that if you redistribute the Apple Software in its entirety and
16  without modifications, you must retain this notice and the following
17  text and disclaimers in all such redistributions of the Apple Software.
18  Neither the name, trademarks, service marks or logos of Apple Inc.
19  may be used to endorse or promote products derived from the Apple
20  Software without specific prior written permission from Apple. Except
21  as expressly stated in this notice, no other rights or licenses, express
22  or implied, are granted by Apple herein, including but not limited to
23  any patent rights that may be infringed by your derivative works or by
24  other works in which the Apple Software may be incorporated.
25 
26  The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
31 
32  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39  POSSIBILITY OF SUCH DAMAGE.
40 */
41 //==================================================================================================
42 // Includes
43 //==================================================================================================
44 
45 // Self Include
46 #include "CAHALAudioStream.h"
47 
48 // PublicUtility Includes
49 #include "CAAutoDisposer.h"
50 #include "CADebugMacros.h"
51 #include "CAException.h"
52 #include "CAPropertyAddress.h"
53 
54 //==================================================================================================
55 // CAHALAudioStream
56 //==================================================================================================
57 
58 CAHALAudioStream::CAHALAudioStream(AudioObjectID inAudioStream)
59 :
60  CAHALAudioObject(inAudioStream)
61 {
62 }
63 
64 CAHALAudioStream::~CAHALAudioStream()
65 {
66 }
67 
68 UInt32 CAHALAudioStream::GetDirection() const
69 {
70  CAPropertyAddress theAddress(kAudioStreamPropertyDirection);
71  return GetPropertyData_UInt32(theAddress, 0, NULL);
72 }
73 
74 UInt32 CAHALAudioStream::GetTerminalType() const
75 {
76  CAPropertyAddress theAddress(kAudioStreamPropertyTerminalType);
77  return GetPropertyData_UInt32(theAddress, 0, NULL);
78 }
79 
80 UInt32 CAHALAudioStream::GetStartingChannel() const
81 {
82  CAPropertyAddress theAddress(kAudioStreamPropertyStartingChannel);
83  return GetPropertyData_UInt32(theAddress, 0, NULL);
84 }
85 
86 UInt32 CAHALAudioStream::GetLatency() const
87 {
88  CAPropertyAddress theAddress(kAudioStreamPropertyLatency);
89  return GetPropertyData_UInt32(theAddress, 0, NULL);
90 }
91 
92 void CAHALAudioStream::GetCurrentVirtualFormat(AudioStreamBasicDescription& outFormat) const
93 {
94  CAPropertyAddress theAddress(kAudioStreamPropertyVirtualFormat);
95  UInt32 theSize = sizeof(AudioStreamBasicDescription);
96  GetPropertyData(theAddress, 0, NULL, theSize, &outFormat);
97 }
98 
99 void CAHALAudioStream::SetCurrentVirtualFormat(const AudioStreamBasicDescription& inFormat)
100 {
101  CAPropertyAddress theAddress(kAudioStreamPropertyVirtualFormat);
102  SetPropertyData(theAddress, 0, NULL, sizeof(AudioStreamBasicDescription), &inFormat);
103 }
104 
105 UInt32 CAHALAudioStream::GetNumberAvailableVirtualFormats() const
106 {
107  CAPropertyAddress theAddress(kAudioStreamPropertyAvailableVirtualFormats);
108  UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL);
109  theAnswer /= sizeof(AudioStreamRangedDescription);
110  return theAnswer;
111 }
112 
113 void CAHALAudioStream::GetAvailableVirtualFormats(UInt32& ioNumberFormats, AudioStreamRangedDescription* outFormats) const
114 {
115  CAPropertyAddress theAddress(kAudioStreamPropertyAvailableVirtualFormats);
116  UInt32 theSize = ioNumberFormats * sizeof(AudioStreamRangedDescription);
117  GetPropertyData(theAddress, 0, NULL, theSize, outFormats);
118  ioNumberFormats = theSize / sizeof(AudioStreamRangedDescription);
119 }
120 
121 void CAHALAudioStream::GetAvailableVirtualFormatByIndex(UInt32 inIndex, AudioStreamRangedDescription& outFormat) const
122 {
123  UInt32 theNumberFormats = GetNumberAvailableVirtualFormats();
124  if((theNumberFormats > 0) && (inIndex < theNumberFormats))
125  {
126  CAAutoArrayDelete<AudioStreamRangedDescription> theFormats(theNumberFormats);
127  GetAvailableVirtualFormats(theNumberFormats, theFormats);
128  if((theNumberFormats > 0) && (inIndex < theNumberFormats))
129  {
130  outFormat = theFormats[inIndex];
131  }
132  }
133 }
134 
135 void CAHALAudioStream::GetCurrentPhysicalFormat(AudioStreamBasicDescription& outFormat) const
136 {
137  CAPropertyAddress theAddress(kAudioStreamPropertyPhysicalFormat);
138  UInt32 theSize = sizeof(AudioStreamBasicDescription);
139  GetPropertyData(theAddress, 0, NULL, theSize, &outFormat);
140 }
141 
142 void CAHALAudioStream::SetCurrentPhysicalFormat(const AudioStreamBasicDescription& inFormat)
143 {
144  CAPropertyAddress theAddress(kAudioStreamPropertyPhysicalFormat);
145  SetPropertyData(theAddress, 0, NULL, sizeof(AudioStreamBasicDescription), &inFormat);
146 }
147 
148 UInt32 CAHALAudioStream::GetNumberAvailablePhysicalFormats() const
149 {
150  CAPropertyAddress theAddress(kAudioStreamPropertyAvailablePhysicalFormats);
151  UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL);
152  theAnswer /= sizeof(AudioStreamRangedDescription);
153  return theAnswer;
154 }
155 
156 void CAHALAudioStream::GetAvailablePhysicalFormats(UInt32& ioNumberFormats, AudioStreamRangedDescription* outFormats) const
157 {
158  CAPropertyAddress theAddress(kAudioStreamPropertyAvailablePhysicalFormats);
159  UInt32 theSize = ioNumberFormats * sizeof(AudioStreamRangedDescription);
160  GetPropertyData(theAddress, 0, NULL, theSize, outFormats);
161  ioNumberFormats = theSize / sizeof(AudioStreamRangedDescription);
162 }
163 
164 void CAHALAudioStream::GetAvailablePhysicalFormatByIndex(UInt32 inIndex, AudioStreamRangedDescription& outFormat) const
165 {
166  UInt32 theNumberFormats = GetNumberAvailablePhysicalFormats();
167  if((theNumberFormats > 0) && (inIndex < theNumberFormats))
168  {
169  CAAutoArrayDelete<AudioStreamRangedDescription> theFormats(theNumberFormats);
170  GetAvailablePhysicalFormats(theNumberFormats, theFormats);
171  if((theNumberFormats > 0) && (inIndex < theNumberFormats))
172  {
173  outFormat = theFormats[inIndex];
174  }
175  }
176 }