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