root/trunk/A52/ACShepA52Codec.cpp

Revision 50, 4.0 kB (checked in by gbooker, 2 years ago)

My multi-channel/2 channel output test.
Bumped the version so that it can be tested with perian

Line 
1 /*
2         A52 / AC-3 Codec Base Class
3         2004, Shepmaster <shepmaster@applesolutions.com>
4        
5         Uses code from the CoreAudio SDK.
6 */
7
8 //=============================================================================
9 //      Includes
10 //=============================================================================
11
12 #include "ACShepA52Codec.h"
13
14 //=============================================================================
15 //      ACShepA52Codec
16 //=============================================================================
17
18 ACShepA52Codec::ACShepA52Codec(UInt32 inInputBufferByteSize) : ACSimpleCodec(inInputBufferByteSize) {
19 }
20
21 ACShepA52Codec::~ACShepA52Codec() {
22 }
23
24
25
26 void    ACShepA52Codec::Initialize(const AudioStreamBasicDescription* inInputFormat,
27                                                                    const AudioStreamBasicDescription* inOutputFormat,
28                                                                    const void* inMagicCookie, UInt32 inMagicCookieByteSize) {
29
30         //      use the given arguments, if necessary
31         if(inInputFormat != NULL)
32         {
33                 SetCurrentInputFormat(*inInputFormat);
34         }
35
36         if(inOutputFormat != NULL)
37         {
38                 SetCurrentOutputFormat(*inOutputFormat);
39         }
40
41         //      make sure the sample rate and number of channels match between the input format and the output format
42                
43         if( (mInputFormat.mSampleRate != mOutputFormat.mSampleRate))
44         {
45                 CODEC_THROW(kAudioCodecUnsupportedFormatError);
46         }
47
48        
49         ACSimpleCodec::Initialize(inInputFormat, inOutputFormat, inMagicCookie, inMagicCookieByteSize);
50 }
51
52 void    ACShepA52Codec::Reset() {
53         ACSimpleCodec::Reset();
54 }
55
56 void    ACShepA52Codec::GetPropertyInfo(AudioCodecPropertyID inPropertyID, UInt32& outPropertyDataSize, bool& outWritable) {
57         switch(inPropertyID)
58         {
59                 case kAudioCodecPropertyMaximumPacketByteSize:
60                         outPropertyDataSize = sizeof(UInt32);
61                         outWritable = false;
62                         break;
63                
64                 case kAudioCodecPropertyRequiresPacketDescription:
65                         outPropertyDataSize = sizeof(UInt32);
66                         outWritable = false;
67                         break;
68
69                 case kAudioCodecPropertyHasVariablePacketByteSizes:
70                         outPropertyDataSize = sizeof(UInt32);
71                         outWritable = false;
72                         break;
73            
74                 case kAudioCodecPropertyPacketFrameSize:
75                         outPropertyDataSize = sizeof(UInt32);
76                         outWritable = false;
77                         break;
78                        
79                 default:
80                         ACSimpleCodec::GetPropertyInfo(inPropertyID, outPropertyDataSize, outWritable);
81                         break;
82                        
83         };
84 }
85
86 void    ACShepA52Codec::GetProperty(AudioCodecPropertyID inPropertyID, UInt32& ioPropertyDataSize, void* outPropertyData) {     
87         switch(inPropertyID) {
88                 case kAudioCodecPropertyManufacturerCFString:
89                 {
90                         if (ioPropertyDataSize != sizeof(CFStringRef)) {
91                                 CODEC_THROW(kAudioCodecBadPropertySizeError);
92                         }
93                        
94                         CFStringRef name = CFCopyLocalizedStringFromTableInBundle(CFSTR("Shepmaster Productions"), CFSTR("CodecNames"), GetCodecBundle(), CFSTR(""));
95                         *(CFStringRef*)outPropertyData = name;
96                         break;
97                 }
98                
99                 case kAudioCodecPropertyMaximumPacketByteSize:
100                        
101                         if(ioPropertyDataSize == sizeof(UInt32)) {
102                 *reinterpret_cast<UInt32*>(outPropertyData) = 3840; //Stolen from liba52 docs
103             } else {
104                                 CODEC_THROW(kAudioCodecBadPropertySizeError);
105                         }
106                        
107             break;
108         case kAudioCodecPropertyRequiresPacketDescription:
109                        
110                         if(ioPropertyDataSize == sizeof(UInt32)) {
111                 *reinterpret_cast<UInt32*>(outPropertyData) = 0;
112             } else {
113                                 CODEC_THROW(kAudioCodecBadPropertySizeError);
114                         }
115                        
116             break;
117         case kAudioCodecPropertyHasVariablePacketByteSizes:
118                        
119                         if(ioPropertyDataSize == sizeof(UInt32)) {
120                 *reinterpret_cast<UInt32*>(outPropertyData) = 1;
121             } else {
122                                 CODEC_THROW(kAudioCodecBadPropertySizeError);
123                         }
124                        
125             break;
126                 case kAudioCodecPropertyPacketFrameSize:
127                        
128                         if(ioPropertyDataSize == sizeof(UInt32)) {
129                 *reinterpret_cast<UInt32*>(outPropertyData) = 6 * 256; // A frame has 6 blocks of 256 samples
130             } else {
131                                 CODEC_THROW(kAudioCodecBadPropertySizeError);
132                         }
133                        
134                         break;
135                 default:
136                         ACSimpleCodec::GetProperty(inPropertyID, ioPropertyDataSize, outPropertyData);
137         }
138 }
139
140 void ACShepA52Codec::ReallocateInputBuffer(UInt32 inInputBufferByteSize) {
141         ACSimpleCodec::ReallocateInputBuffer(inInputBufferByteSize);
142 }
Note: See TracBrowser for help on using the browser.