Jamoma API  0.6.0.a19
AUOutputBL.h
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 #ifndef __AUOutputBL_h__
42 #define __AUOutputBL_h__
43 
44 #include "CAStreamBasicDescription.h"
45 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
46 #else
47 #endif
48 
49 // ____________________________________________________________________________
50 //
51 // AUOutputBL - Simple Buffer List wrapper targetted to use with retrieving AU output
52 // Works in one of two ways (both adjustable)... Can use it with NULL pointers, or allocate
53 // memory to receive the data in.
54 
55 // Before using this with any call to AudioUnitRender, it needs to be Prepared
56 // as some calls to AudioUnitRender can reset the ABL
57 
58 class AUOutputBL {
59 public:
60 
61  // you CANNOT use one of these - it will crash!
62 // AUOutputBL ();
63 
64  // this is the constructor that you use
65  // it can't be reset once you've constructed it
66  AUOutputBL (const CAStreamBasicDescription &inDesc, UInt32 inDefaultNumFrames = 512);
67  ~AUOutputBL();
68 
69  void Prepare ()
70  {
71  Prepare (mFrames);
72  }
73 
74  // this version can throw if this is an allocted ABL and inNumFrames is > AllocatedFrames()
75  // you can set the bool to true if you want a NULL buffer list even if allocated
76  // inNumFrames must be a valid number (will throw if inNumFrames is 0)
77  void Prepare (UInt32 inNumFrames, bool inWantNullBufferIfAllocated = false);
78 
79  AudioBufferList* ABL() { return mBufferList; }
80 
81  // You only need to call this if you want to allocate a buffer list
82  // if you want an empty buffer list, just call Prepare()
83  // if you want to dispose previously allocted memory, pass in 0
84  // then you either have an empty buffer list, or you can re-allocate
85  // Memory is kept around if an Allocation request is less than what is currently allocated
86  void Allocate (UInt32 inNumberFrames);
87 
88  UInt32 AllocatedFrames() const { return mFrames; }
89 
90  const CAStreamBasicDescription& GetFormat() const { return mFormat; }
91 
92 #if DEBUG
93  void Print();
94 #endif
95 
96 private:
97  UInt32 AllocatedBytes () const { return (mBufferSize * mNumberBuffers); }
98 
99  CAStreamBasicDescription mFormat;
100  Byte* mBufferMemory;
101  AudioBufferList* mBufferList;
102  UInt32 mNumberBuffers;
103  UInt32 mBufferSize;
104  UInt32 mFrames;
105 
106 // don't want to copy these.. can if you want, but more code to write!
107  AUOutputBL () {}
108  AUOutputBL (const AUOutputBL &c) {}
109  AUOutputBL& operator= (const AUOutputBL& c) { return *this; }
110 };
111 
112 #endif // __AUOutputBL_h__