/*
// Copyright 2015 2016 Intel Corporation All Rights Reserved.
//
// The source code, information and material ("Material") contained herein is
// owned by Intel Corporation or its suppliers or licensors, and title
// to such Material remains with Intel Corporation or its suppliers or
// licensors. The Material contains proprietary information of Intel
// or its suppliers and licensors. The Material is protected by worldwide
// copyright laws and treaty provisions. No part of the Material may be used,
// copied, reproduced, modified, published, uploaded, posted, transmitted,
// distributed or disclosed in any way without Intel's prior express written
// permission. No license under any patent, copyright or other intellectual
// property rights in the Material is granted to or conferred upon you,
// either expressly, by implication, inducement, estoppel or otherwise.
// Any license under such intellectual property rights must be express and
// approved by Intel in writing.
//
// Unless otherwise agreed by Intel in writing,
// you may not remove or alter this notice or any other notice embedded in
// Materials by Intel or Intel's suppliers or licensors in any way.
*/

//    The code example below illustrates how to use the function ippsMulPack_32f_I.
// implemented with Intel IPP functions:
//     ippsFFTGetSize_R_32f
//     ippsFFTInit_R_32f
//     ippsSet_32f
//     ippsFFTFwd_RToPack_32f
//     ippsMulPack_32f_I
//     ippsFFTInv_PackToR_32f


#include <stdio.h>
#include "ipp.h"

/* Next two defines are created to simplify code reading and understanding */
#define EXIT_MAIN exitLine:                                  /* Label for Exit */
#define check_sts(st) if((st) != ippStsNoErr) goto exitLine; /* Go to Exit if IPP function returned status different from ippStsNoErr */

/* Results of ippMalloc() are not validated because Intel(R) Integrated Performance Primitives functions perform bad arguments check and will return an appropriate status  */

int main(void)
{
    int i = 0;
    IppStatus status = ippStsNoErr;
    Ipp32f pFlt[8] = {1.0f/3,1.0f/3,1.0f/3,0,0,0,0,0};  /* Pointers to filter signal */
    Ipp32f pSrc[8],   pDst[8];    /* Pointers to source/filter/destination signals */
    Ipp32f pSrcFr[8], pFltFr[8];  /* Pointers to source/filter/destination signals into the frequency domain */

    IppsFFTSpec_R_32f* pSpec = NULL;                            /* Pointer to FFT pSpec structure */
    Ipp8u *pMemInit = NULL, *pBuffer = NULL, *pSpecMem = NULL;  /* Pointer to the work buffers */
    int sizeSpec = 0, sizeInit = 0, sizeBuf = 0;                /* size of FFT pSpec structure, Init and work buffers */

    check_sts( status = ippsFFTGetSize_R_32f(3, IPP_FFT_DIV_INV_BY_N, ippAlgHintNone, &sizeSpec, &sizeInit, &sizeBuf) )

    /* memory allocation */
    pSpecMem = (Ipp8u*) ippMalloc( sizeSpec );
    pBuffer  = (Ipp8u*) ippMalloc( sizeBuf );
    pMemInit = (Ipp8u*) ippMalloc( sizeInit );

    check_sts( status = ippsFFTInit_R_32f(&pSpec, 3, IPP_FFT_DIV_INV_BY_N, ippAlgHintNone, pSpecMem, pMemInit) )

    ippsSet_32f( 3, pSrc, 8 );
    pSrc[3] = 5;

    /* forward FFT transform : the source signal is transformed into the frequency domain*/
    check_sts( status = ippsFFTFwd_RToPack_32f( pSrc, pSrcFr, pSpec, NULL ) )

    /* forward FFT transform: the filter signal is transformed into the frequency domain */
    check_sts( status = ippsFFTFwd_RToPack_32f( pFlt, pFltFr, pSpec, NULL ) )

    /* multiplying the packed data */
    check_sts( status = ippsMulPack_32f_I( pFltFr, pSrcFr, 8 ) )

    /* inverse FFT transform : the filtered data is transformed to the time domain */
    check_sts( status = ippsFFTInv_PackToR_32f( pSrcFr, pDst, pSpec, NULL ) )

    printf("filtered =");

    for (i = 0; i < 8; ++i) printf(" %f", pDst[i]);
    printf("\n");

EXIT_MAIN
    ippFree( pMemInit );
    ippFree( pSpec );
    ippFree( pBuffer );
    printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
    return status;
}