/* ----------------------------------------------------------------------
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
*
* $Date: 19. March 2015
* $Revision: V.1.4.5
*
* Project: CMSIS DSP Library
* Title: arm_dct4_init_q15.c
*
* Description: Initialization function of DCT-4 & IDCT4 Q15
*
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of ARM LIMITED nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* -------------------------------------------------------------------- */
#include "arm_math.h"
/**
* @ingroup groupTransforms
*/
/**
* @addtogroup DCT4_IDCT4
* @{
*/
/*
* @brief Weights Table
*/
/**
* \par
* Weights tables are generated using the formula : <pre>weights[n] = e^(-j*n*pi/(2*N))</pre>
* \par
* C command to generate the table
* <pre>
* for(i = 0; i< N; i++)
* {
* weights[2*i]= cos(i*c);
* weights[(2*i)+1]= -sin(i * c);
* } </pre>
* \par
* where <code>N</code> is the Number of weights to be calculated and <code>c</code> is <code>pi/(2*N)</code>
* \par
* Converted the output to q15 format by multiplying with 2^31 and saturated if required.
* \par
* In the tables below the real and imaginary values are placed alternatively, hence the
* array length is <code>2*N</code>.
*//**
* \par
* cosFactor tables are generated using the formula : <pre> cos_factors[n] = 2 * cos((2n+1)*pi/(4*N)) </pre>
* \par
* C command to generate the table
* <pre>
* for(i = 0; i< N; i++)
* {
* cos_factors[i]= 2 * cos((2*i+1)*c/2);
* } </pre>
* \par
* where <code>N</code> is the number of factors to generate and <code>c</code> is <code>pi/(2*N)</code>
* \par
* Then converted to q15 format by multiplying with 2^31 and saturated if required.
*//**
* @brief Initialization function for the Q15 DCT4/IDCT4.
* @param[in,out] *S points to an instance of Q15 DCT4/IDCT4 structure.
* @param[in] *S_RFFT points to an instance of Q15 RFFT/RIFFT structure.
* @param[in] *S_CFFT points to an instance of Q15 CFFT/CIFFT structure.
* @param[in] N length of the DCT4.
* @param[in] Nby2 half of the length of the DCT4.
* @param[in] normalize normalizing factor.
* @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length.
* \par Normalizing factor:
* The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.
* Normalizing factors in 1.15 format are mentioned in the table below for different DCT sizes:
* \image html dct4NormalizingQ15Table.gif
*/
arm_status arm_dct4_init_q15(
arm_dct4_instance_q15 * S,
arm_rfft_instance_q15 * S_RFFT,
arm_cfft_radix4_instance_q15 * S_CFFT,
uint16_t N,
uint16_t Nby2,
q15_t normalize)
{
/* Initialise the default arm status */
arm_status status = ARM_MATH_SUCCESS;
/* Initializing the pointer array with the weight table base addresses of different lengths */
q15_t *twiddlePtr[4] = { (q15_t *) WeightsQ15_128, (q15_t *) WeightsQ15_512,
(q15_t *) WeightsQ15_2048, (q15_t *) WeightsQ15_8192
};
/* Initializing the pointer array with the cos factor table base addresses of different lengths */
q15_t *pCosFactor[4] =
{ (q15_t *) cos_factorsQ15_128, (q15_t *) cos_factorsQ15_512,
(q15_t *) cos_factorsQ15_2048, (q15_t *) cos_factorsQ15_8192
};
/* Initialize the DCT4 length */
S->N = N;
/* Initialize the half of DCT4 length */
S->Nby2 = Nby2;
/* Initialize the DCT4 Normalizing factor */
S->normalize = normalize;
/* Initialize Real FFT Instance */
S->pRfft = S_RFFT;
/* Initialize Complex FFT Instance */
S->pCfft = S_CFFT;
switch (N)
{
/* Initialize the table modifier values */
case 8192u:
S->pTwiddle = twiddlePtr[3];
S->pCosFactor = pCosFactor[3];
break;
case 2048u:
S->pTwiddle = twiddlePtr[2];
S->pCosFactor = pCosFactor[2];
break;
case 512u:
S->pTwiddle = twiddlePtr[1];
S->pCosFactor = pCosFactor[1];
break;
case 128u:
S->pTwiddle = twiddlePtr[0];
S->pCosFactor = pCosFactor[0];
break;
default:
status = ARM_MATH_ARGUMENT_ERROR;
}
/* Initialize the RFFT/RIFFT */
arm_rfft_init_q15(S->pRfft, S->N, 0u, 1u);
/* return the status of DCT4 Init function */
return (status);
}
/**
* @} end of DCT4_IDCT4 group
*/