Initial commit.
[libsalac.git] / src / lib / alac / codec / ALACEncoder.h
blob0e6c68904cec5c521d286becc82e3cdf4750de06
1 /*
2 * Copyright (c) 2011 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
22 File: ALACEncoder.h
25 #pragma once
27 #include <stdint.h>
29 #include "ALACAudioTypes.h"
32 struct BitBuffer;
34 class ALACEncoder
36 public:
37 ALACEncoder();
38 virtual ~ALACEncoder();
40 virtual int32_t Encode(AudioFormatDescription theInputFormat, AudioFormatDescription theOutputFormat,
41 unsigned char * theReadBuffer, unsigned char * theWriteBuffer, int32_t * ioNumBytes);
42 virtual int32_t Finish( );
44 void SetFastMode( bool fast ) { mFastMode = fast; };
46 // this must be called *before* InitializeEncoder()
47 void SetFrameSize( uint32_t frameSize ) { mFrameSize = frameSize; };
49 void GetConfig( ALACSpecificConfig & config );
50 uint32_t GetMagicCookieSize(uint32_t inNumChannels);
51 void GetMagicCookie( void * config, uint32_t * ioSize );
53 virtual int32_t InitializeEncoder(AudioFormatDescription theOutputFormat);
55 protected:
56 virtual void GetSourceFormat( const AudioFormatDescription * source, AudioFormatDescription * output );
58 int32_t EncodeStereo( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t channelIndex, uint32_t numSamples );
59 int32_t EncodeStereoFast( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t channelIndex, uint32_t numSamples );
60 int32_t EncodeStereoEscape( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t numSamples );
61 int32_t EncodeMono( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t channelIndex, uint32_t numSamples );
64 // ALAC encoder parameters
65 int16_t mBitDepth;
66 bool mFastMode;
68 // encoding state
69 int16_t mLastMixRes[kALACMaxChannels];
71 // encoding buffers
72 int32_t * mMixBufferU;
73 int32_t * mMixBufferV;
74 int32_t * mPredictorU;
75 int32_t * mPredictorV;
76 uint16_t * mShiftBufferUV;
78 uint8_t * mWorkBuffer;
80 // per-channel coefficients buffers
81 int16_t mCoefsU[kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs];
82 int16_t mCoefsV[kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs];
84 // encoding statistics
85 uint32_t mTotalBytesGenerated;
86 uint32_t mAvgBitRate;
87 uint32_t mMaxFrameBytes;
88 uint32_t mFrameSize;
89 uint32_t mMaxOutputBytes;
90 uint32_t mNumChannels;
91 uint32_t mOutputSampleRate;