ALACEncoder.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2011 Apple Inc. All rights reserved.
  3. *
  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
  11. *
  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.
  17. *
  18. * @APPLE_APACHE_LICENSE_HEADER_END@
  19. */
  20. /*
  21. File: ALACEncoder.h
  22. */
  23. #pragma once
  24. #include <stdint.h>
  25. #include "ALACAudioTypes.h"
  26. struct BitBuffer;
  27. class ALACEncoder
  28. {
  29. public:
  30. ALACEncoder();
  31. virtual ~ALACEncoder();
  32. virtual int32_t Encode(AudioFormatDescription theInputFormat, AudioFormatDescription theOutputFormat,
  33. unsigned char * theReadBuffer, unsigned char * theWriteBuffer, int32_t * ioNumBytes);
  34. virtual int32_t Finish( );
  35. void SetFastMode( bool fast ) { mFastMode = fast; };
  36. // this must be called *before* InitializeEncoder()
  37. void SetFrameSize( uint32_t frameSize ) { mFrameSize = frameSize; };
  38. void GetConfig( ALACSpecificConfig & config );
  39. uint32_t GetMagicCookieSize(uint32_t inNumChannels);
  40. void GetMagicCookie( void * config, uint32_t * ioSize );
  41. virtual int32_t InitializeEncoder(AudioFormatDescription theOutputFormat);
  42. protected:
  43. virtual void GetSourceFormat( const AudioFormatDescription * source, AudioFormatDescription * output );
  44. int32_t EncodeStereo( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t channelIndex, uint32_t numSamples );
  45. int32_t EncodeStereoFast( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t channelIndex, uint32_t numSamples );
  46. int32_t EncodeStereoEscape( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t numSamples );
  47. int32_t EncodeMono( struct BitBuffer * bitstream, void * input, uint32_t stride, uint32_t channelIndex, uint32_t numSamples );
  48. // ALAC encoder parameters
  49. int16_t mBitDepth;
  50. bool mFastMode;
  51. // encoding state
  52. int16_t mLastMixRes[kALACMaxChannels];
  53. // encoding buffers
  54. int32_t * mMixBufferU;
  55. int32_t * mMixBufferV;
  56. int32_t * mPredictorU;
  57. int32_t * mPredictorV;
  58. uint16_t * mShiftBufferUV;
  59. uint8_t * mWorkBuffer;
  60. // per-channel coefficients buffers
  61. int16_t mCoefsU[kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs];
  62. int16_t mCoefsV[kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs];
  63. // encoding statistics
  64. uint32_t mTotalBytesGenerated;
  65. uint32_t mAvgBitRate;
  66. uint32_t mMaxFrameBytes;
  67. uint32_t mFrameSize;
  68. uint32_t mMaxOutputBytes;
  69. uint32_t mNumChannels;
  70. uint32_t mOutputSampleRate;
  71. };