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