melody_coef_cal32.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:18k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * sp_coef_cal32.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Melody FIR coefficient calibration source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include <IniFiles.hpp>
- #include <stdio.h>
- #include <math.h>
- #pragma hdrstop
- #include "misc.h"
- #include "meta_utils.h"
- #include "man_active.h"
- #include "sp_coef.h"
- #include "melody_coef_cal32.h"
- #include "math_utils.h"
- //===========================================================================
- static CMELODYCOEFCAL32* melody_coef_cal32_ptr;
- static bool g_bIsRunning;
- //===========================================================================
- //===========================================================================
- CMELODYCOEFCAL32::CMELODYCOEFCAL32(void)
- {
- g_bIsRunning = false;
- m_iConfirmState = 0;
- CoefCalBufSize = 0;
- CoefCalBuf = NULL;
- }
- //---------------------------------------------------------------------------
- CMELODYCOEFCAL32::~CMELODYCOEFCAL32()
- {
- g_bIsRunning = false;
- m_iConfirmState = 0;
- if(CoefCalBuf)
- {
- delete [] CoefCalBuf;
- CoefCalBuf = NULL;
- }
- AFT_close();
- }
- //---------------------------------------------------------------------------
- void CMELODYCOEFCAL32::REQ_Finish(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- Confirm(STATE_COEF_CAL32_OK);
- g_bIsRunning = false;
- }
- //---------------------------------------------------------------------------
- void CMELODYCOEFCAL32::REQ_Stop(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_Cancel_r(m_META_HANDLE_Obj.Get_MainHandle(), MELODYID_COEF_CAL);
- Confirm( STATE_COEF_CAL32_STOP );
- }
- //---------------------------------------------------------------------------
- void CMELODYCOEFCAL32::REQ_TimeOut(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_Cancel_r(m_META_HANDLE_Obj.Get_MainHandle(), MELODYID_COEF_CAL);
- Confirm(STATE_COEF_CAL32_TIMEOUT);
- }
- //---------------------------------------------------------------------------
- void CMELODYCOEFCAL32::Confirm(int confirm_state)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- g_bIsRunning = false;
- if (NULL == ConfirmCallback)
- {
- return;
- }
- m_iConfirmState = confirm_state;
- ActiveMan->SetActiveFunction(ConfirmCallback);
- }
- //---------------------------------------------------------------------------
- bool CMELODYCOEFCAL32::getInterpolateFreq( double start_freq, double step_freq, double end_freq, sMelodyInterpolate *p_interpolate )
- {
- if( start_freq < 0 || step_freq < 0 || end_freq < 0 || start_freq > end_freq )
- {
- return false;
- }
- for(int i=0; i<TOTAL_MELODY_SAMPLE_NUM; i++)
- {
- p_interpolate->Hz[i] = start_freq + i*step_freq;
- }
- return true;
- }
- //==============================================================================
- bool CMELODYCOEFCAL32::REQ_Write_FIR_File( char *filename, sMelodyFir *p_MelodyFirCoef )
- {
- FILE *fp;
- char str[512];
- AnsiString as_Str;
- if( strcmp(filename, "") == 0 )
- return false;
-
- fp = fopen(filename, "w");
- if(fp == NULL)
- return false;
- fprintf( fp, "%dn", (int) MELODY_FIR_TAPS);
- for( int i=0; i<MELODY_FIR_TAPS; i++ )
- {
- fprintf( fp, "%dn", (int) p_MelodyFirCoef->Mag[i]);
- }
- fclose(fp);
- return true;
- }
- //------------------------------------------------------------------------------
- bool CMELODYCOEFCAL32::CheckLicenseDat( void )
- {
- FILE *fp;
- AnsiString asPath, asFileName;
- if ( getPathFromStr(Application->ExeName, asPath) &&
- withPath( asPath) &&
- !withPath( asFileName)
- )
- {
- asFileName = asPath + "license.dat";
- }
- fp = fopen(asFileName.c_str(), "r");
- if( fp == NULL )
- {
- fclose(fp);
- return false;
- }
- fclose(fp);
- return true;
- }
- //==============================================================================
- #if 0
- void CMELODYCOEFCAL32::ReorderFirCoef( sFirCoefParameters *p_FirCoef )
- {
- // re-ordering
- int i;
- double temp_old_fir_coeffs[MAX_AUDIO_COEFF_LEN];
- for( i=0; i<p_FirCoef->taps; i++ )
- {
- temp_old_fir_coeffs[i] = p_FirCoef->FirCoef[i];
- }
- for( i=0; i<p_FirCoef->taps; i++ )
- {
- p_FirCoef->FirCoef[i] = temp_old_fir_coeffs[p_FirCoef->taps-1-i];
- }
- }
- #endif
- #if 0
- //==============================================================================
- void CMELODYCOEFCAL32::getSelHzIndex(int *p_TplHz, int *p_SelHz, int* p_SelHzIndex)
- {
- int k=0;
- for( int i=0; i<TOTAL_TRC_FREQ_NUM; i++ )
- {
- for( int j=0; j<TOTAL_SEL_FREQ_NUM; j++)
- {
- if( *(p_TplHz+i) == *(p_SelHz+j) )
- {
- p_SelHzIndex[k]=i;
- k++;
- break;
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- void CMELODYCOEFCAL32::getSeldB( double *p_TpldB, double *p_SeldB, int* p_SelHzIndex)
- {
- for(int i=0; i<TOTAL_SEL_FREQ_NUM; i++)
- {
- *(p_SeldB+i) = *(p_TpldB+*(p_SelHzIndex+i));
- }
- }
- //==============================================================================
- bool CMELODYCOEFCAL32::CheckEngineExist( void )
- {
- // engine test code
- Engine *mat;
- mat = engOpen( "