• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 2012-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
4  *
5  * @APPLE_APACHE_LICENSE_HEADER_START@
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License") ;
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * @APPLE_APACHE_LICENSE_HEADER_END@
20  */
21 
22 /*
23 	File:		alac_codec.h
24 */
25 
26 #ifndef ALAC_CODEC_H
27 #define ALAC_CODEC_H
28 
29 #include <stdint.h>
30 
31 #include "ALACAudioTypes.h"
32 
33 #define		ALAC_FRAME_LENGTH	4096
34 
35 struct BitBuffer ;
36 
37 typedef struct alac_decoder_s
38 {
39 	// decoding parameters (public for use in the analyzer)
40 	ALACSpecificConfig		mConfig ;
41 
42 	uint16_t				mActiveElements ;
43 
44 	// decoding buffers
45 	int32_t				mMixBufferU [ALAC_FRAME_LENGTH] ;
46 	int32_t				mMixBufferV [ALAC_FRAME_LENGTH] ;
47 	union
48 	{
49 		int32_t			mPredictor [ALAC_FRAME_LENGTH] ;
50 		uint16_t		mShiftBuffer [ALAC_FRAME_LENGTH] ;
51 	} u ;
52 	uint32_t			mNumChannels ;
53 } ALAC_DECODER ;
54 
55 typedef struct alac_encoder_s
56 {
57 	// ALAC encoder parameters
58 	int16_t			mBitDepth ;
59 
60 	// encoding state
61 	int16_t			mLastMixRes [kALACMaxChannels] ;
62 
63 	int32_t			mFastMode ;
64 
65 	// encoding buffers
66 	int32_t			mMixBufferU [ALAC_FRAME_LENGTH] ;
67 	int32_t			mMixBufferV [ALAC_FRAME_LENGTH] ;
68 	int32_t			mPredictorU [ALAC_FRAME_LENGTH] ;
69 	int32_t			mPredictorV [ALAC_FRAME_LENGTH] ;
70 	uint16_t		mShiftBufferUV [2 * ALAC_FRAME_LENGTH] ;
71 	uint8_t			mWorkBuffer [4 * ALAC_FRAME_LENGTH] ;
72 
73 	// per-channel coefficients buffers
74 	int16_t			mCoefsU [kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs] ;
75 	int16_t			mCoefsV [kALACMaxChannels][kALACMaxSearches][kALACMaxCoefs] ;
76 
77 	// encoding statistics
78 	uint32_t		mTotalBytesGenerated ;
79 	uint32_t		mAvgBitRate ;
80 	uint32_t		mMaxFrameBytes ;
81 	uint32_t		mFrameSize ;
82 	uint32_t		mMaxOutputBytes ;
83 	uint32_t		mNumChannels ;
84 	uint32_t		mOutputSampleRate ;
85 } ALAC_ENCODER ;
86 
87 
88 int32_t	alac_decoder_init (ALAC_DECODER *p, void * inMagicCookie, uint32_t inMagicCookieSize) ;
89 int32_t alac_encoder_init (ALAC_ENCODER *p, uint32_t samplerate, uint32_t channels, uint32_t format_flags, uint32_t frameSize) ;
90 
91 int32_t	alac_decode (ALAC_DECODER *, struct BitBuffer * bits, int32_t * sampleBuffer,
92 					uint32_t numSamples, uint32_t * outNumSamples) ;
93 
94 int32_t	alac_encode (ALAC_ENCODER *p, uint32_t numSamples,
95 					const int32_t * theReadBuffer, unsigned char * theWriteBuffer,
96 					uint32_t * ioNumBytes) ;
97 
98 void alac_set_fastmode (ALAC_ENCODER * p, int32_t fast) ;
99 
100 uint32_t alac_get_magic_cookie_size (uint32_t inNumChannels) ;
101 void	alac_get_magic_cookie (ALAC_ENCODER *p, void * config, uint32_t * ioSize) ;
102 void	alac_get_source_format (ALAC_ENCODER *p, const AudioFormatDescription * source, AudioFormatDescription * output) ;
103 
104 #endif
105