xref: /third_party/libsnd/src/ALAC/matrixlib.h (revision b815c7f3)
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:		matrixlib.h
24
25	Contains:	ALAC mixing/matrixing routines to/from 32-bit predictor buffers.
26
27	Copyright:	Copyright (C) 2004 to 2011 Apple, Inc.
28*/
29
30#ifndef __MATRIXLIB_H
31#define __MATRIXLIB_H
32
33#pragma once
34
35#include <stdint.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41// 16-bit routines
42void	mix16 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, int32_t mixbits, int32_t mixres) ;
43void	unmix16 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples, int32_t mixbits, int32_t mixres) ;
44
45// 20-bit routines
46void	mix20 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, int32_t mixbits, int32_t mixres) ;
47void	unmix20 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples, int32_t mixbits, int32_t mixres) ;
48
49// 24-bit routines
50// - 24-bit data sometimes compresses better by shifting off the bottom byte so these routines deal with
51//	 the specified "unused lower bytes" in the combined "shift" buffer
52void	mix24 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples,
53				int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ;
54void	unmix24 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples,
55					int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ;
56
57// 32-bit routines
58// - note that these really expect the internal data width to be < 32-bit but the arrays are 32-bit
59// - otherwise, the calculations might overflow into the 33rd bit and be lost
60// - therefore, these routines deal with the specified "unused lower" bytes in the combined "shift" buffer
61void	mix32 (const int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples,
62				int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ;
63void	unmix32 (const int32_t * u, int32_t * v, int32_t * out, uint32_t stride, int32_t numSamples,
64				int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted) ;
65
66// 20/24/32-bit <-> 32-bit helper routines (not really matrixing but convenient to put here)
67void	copy20ToPredictor (const int32_t * in, uint32_t stride, int32_t * out, int32_t numSamples) ;
68void	copy24ToPredictor (const int32_t * in, uint32_t stride, int32_t * out, int32_t numSamples) ;
69
70void	copyPredictorTo24 (const int32_t * in, int32_t * out, uint32_t stride, int32_t numSamples) ;
71void	copyPredictorTo24Shift (const int32_t * in, uint16_t * shift, int32_t * out, uint32_t stride, int32_t numSamples, int32_t bytesShifted) ;
72void	copyPredictorTo20 (const int32_t * in, int32_t * out, uint32_t stride, int32_t numSamples) ;
73
74void	copyPredictorTo32 (const int32_t * in, int32_t * out, uint32_t stride, int32_t numSamples) ;
75void	copyPredictorTo32Shift (const int32_t * in, uint16_t * shift, int32_t * out, uint32_t stride, int32_t numSamples, int32_t bytesShifted) ;
76
77#ifdef __cplusplus
78}
79#endif
80
81#endif	/* __MATRIXLIB_H */
82