Jamoma API  0.6.0.a19
MatrixMixerVolumes.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 #include "MatrixMixerVolumes.h"
42 #include "CAXException.h"
43 
44 OSStatus NumberChannels (AudioUnit au,
45  AudioUnitScope inScope,
46  AudioUnitElement inEl,
47  UInt32 &outChans);
48 
49 
50 OSStatus PrintBuses (FILE* file, char* str, AudioUnit au, AudioUnitScope inScope)
51 {
52  OSStatus result;
53  UInt32 busCount;
54  UInt32 theSize = sizeof(busCount);
55 
56  ca_require_noerr (result = AudioUnitGetProperty (au, kAudioUnitProperty_ElementCount,
57  inScope, 0, &busCount, &theSize), home);
58 
59  fprintf (file, "\t%s Elements:\n\t\t", str);
60  for (UInt32 i = 0; i < busCount; ++i) {
61  Float32 val;
62  ca_require_noerr (result = AudioUnitGetParameter (au, kMatrixMixerParam_Enable, inScope, i, &val), home);
63  UInt32 numChans;
64  ca_require_noerr (result = NumberChannels (au, inScope, i, numChans), home);
65  char frameCharStart = (val != 0 ? '[' : '{');
66  char frameCharEnd = (val != 0 ? ']' : '}');
67  fprintf (file, "%d:%c%d, %c%c ", (int)i, frameCharStart, (int)numChans, (val != 0 ? 'T' : 'F'), frameCharEnd);
68  }
69  fprintf (file, "\n");
70 home:
71  return result;
72 }
73 
74 void PrintMatrixMixerVolumes (FILE* file, AudioUnit au)
75 {
76  UInt32 dims[2];
77  UInt32 theSize = sizeof(UInt32) * 2;
78  Float32 *theVols = NULL;
79  OSStatus result;
80 
81 // this call will fail if the unit is NOT initialized as it would present an incomplete state
82  ca_require_noerr (result = AudioUnitGetProperty (au, kAudioUnitProperty_MatrixDimensions,
83  kAudioUnitScope_Global, 0, dims, &theSize), home);
84 
85  theSize = ((dims[0] + 1) * (dims[1] + 1)) * sizeof(Float32);
86 
87  theVols = static_cast<Float32*> (malloc (theSize));
88 
89  ca_require_noerr (result = AudioUnitGetProperty (au, kAudioUnitProperty_MatrixLevels,
90  kAudioUnitScope_Global, 0, theVols, &theSize), home);
91 
92 home:
93  if (result) {
94  if (theVols)
95  free(theVols);
96  return;
97  }
98 
99  theSize /= sizeof(Float32);
100 
101  unsigned int inputs = dims[0];
102  unsigned int outputs = dims[1];
103 
104  fprintf (file, "\tInput Channels = %d, Output Channels = %d\n", (int)dims[0], (int)dims[1]);
105  PrintBuses (file, "Input", au, kAudioUnitScope_Input);
106  PrintBuses (file, "Output", au, kAudioUnitScope_Output);
107  fprintf (file, "\tGlobal Volume: %.3f\n", theVols [theSize - 1]);
108  for (unsigned int i = 0; i < (inputs + 1); ++i) {
109  if (i < inputs) {
110  fprintf (file, "\t%.3f ", theVols[(i + 1) * (outputs + 1) - 1]);
111 
112  for (unsigned int j = 0; j < outputs; ++j)
113  fprintf (file, "(%.3f) ", theVols[(i * (outputs + 1)) + j]);
114  } else {
115  fprintf (file, "\t ");
116  for (unsigned int j = 0; j < outputs; ++j)
117  fprintf (file, " %.3f ", theVols[(i * (outputs + 1)) + j]);
118  }
119  fprintf (file, "\n");
120  }
121 
122 #if 0
123  for (unsigned int i = 0; i < theSize; ++i)
124  printf ("%f, ", theVols[i]);
125 #endif
126  free(theVols);
127 }
128 
129 // Utility routine that gets the number of channels from an audio unit
130 OSStatus NumberChannels (AudioUnit au,
131  AudioUnitScope inScope,
132  AudioUnitElement inEl,
133  UInt32 &outChans)
134 {
135  AudioStreamBasicDescription desc;
136  UInt32 dataSize = sizeof (AudioStreamBasicDescription);
137  OSStatus result = AudioUnitGetProperty (au, kAudioUnitProperty_StreamFormat,
138  inScope, inEl,
139  &desc, &dataSize);
140  if (!result)
141  outChans = desc.mChannelsPerFrame;
142  return result;
143 }