Example #1
0
int CEditX::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CEdit::OnCreate(lpCreateStruct) == -1)
		return -1;
	UpdateMetrics();
	return 0;
}
Example #2
0
BOOL HexView::OpenFile(LPCTSTR szFileName, UINT uOpenFlags)
{
	bool fReadonly  = (uOpenFlags & HVOF_READONLY) ? true : false;
	bool fQuickload = (uOpenFlags & HVOF_QUICKLOAD) ? true : false;
	bool fQuicksave = (uOpenFlags & HVOF_QUICKSAVE) ? true : false;

	// try to open as the caller requests us
	if(m_pDataSeq->open(szFileName, fReadonly, fQuickload))
	{
		TCHAR *fp;
		DWORD e = GetLastError();
		GetFullPathName(szFileName, MAX_PATH, m_szFilePath, &fp);

		RecalcPositions();

		SetCaretPos((m_nAddressWidth + m_nHexPaddingLeft) * m_nFontHeight, 0);

		UpdateMetrics();

		SetLastError(e);

		if(m_pDataSeq->isreadonly())
			m_nEditMode = HVMODE_READONLY;
		else
			m_nEditMode = HVMODE_OVERWRITE;

		m_nSearchLen = 0;
		return TRUE;
	}

	return FALSE;
}
Example #3
0
BOOL HexView::ImportFile(LPCTSTR szFileName, UINT uImportFlags)
{
	size_w len;

	bool fReadonly  = (uImportFlags & HVOF_READONLY) ? true : false;
	bool fQuickload = (uImportFlags & HVOF_QUICKLOAD) ? true : false;

	if(m_nEditMode == HVMODE_READONLY || m_pDataSeq == 0)
		return 0;

	m_nSelectionStart = m_nCursorOffset;

	if(m_nEditMode == HVMODE_OVERWRITE)
	{
		len = m_pDataSeq->replace_file(szFileName, m_nCursorOffset, fQuickload);
	}
	else if(m_nEditMode == HVMODE_INSERT)
	{
		len = m_pDataSeq->insert_file(szFileName, m_nCursorOffset, fQuickload);
	}

	m_nSelectionEnd = m_nCursorOffset + len;
	m_nCursorOffset = m_nCursorOffset + len;

	UpdateMetrics();
	ScrollToCaret();
	//SetCursor(

	return len ? TRUE : FALSE;
}
Example #4
0
//
//	WM_SETFONT handler: set a new default font
//
LONG TextView::OnSetFont(HFONT hFont)
{
	// default font is always #0
	SetFont(hFont, 0);
	UpdateMetrics();

	return 0;
}
Example #5
0
//
//	Add a secondary font to the TextView
//
LONG TextView::AddFont(HFONT hFont)
{
	int idx = m_nNumFonts++;

	SetFont(hFont, idx);
	UpdateMetrics();

	return 0;
}
RETURN_CODE refresh_fm_ui(void)
{
	RETURN_CODE ret = SUCCESS;
	LCD_Clear(LCD_CLEAR_LINE2);
	ret |= UpdateMetrics();
	show_freq(0,0);

    eeprom_save_parameter();

	return ret;	
}
Example #7
0
//*****************************************************************************
//
// Function Name: RGridCtrl::OnSize(UINT nType, int cx, int cy) 
//
// Description:   Message handler for WM_SIZE
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::OnSize(UINT /*nType*/, int cx, int cy) 
{
	if (m_fResizeCells) 
	{
		SizeCellsToClient( m_cxVisibleRows , m_nNumCols ) ;
	}
	else
	{
		m_cxVisibleRows = WORD( cy / m_cxCellHeight ) ;
		m_cxVisibleCols = WORD( cx / m_cxCellWidth ) ;
		UpdateMetrics() ;
	}
}
Example #8
0
LONG AsmView::ClearFile()
{
	if(m_pTextDoc)
		m_pTextDoc->clear();

	m_nLineCount   = m_pTextDoc->linecount();
	m_nLongestLine = m_pTextDoc->longestline(4);

	m_nVScrollPos  = 0;
	m_nHScrollPos  = 0;

	UpdateMetrics();

	return TRUE;
}
void TextView::Smeg(BOOL fAdvancing)
{
	m_pTextDoc->init_linebuffer();

	m_nLineCount   = m_pTextDoc->linecount();

	UpdateMetrics();
	UpdateMarginWidth();
	SetupScrollbars();

	UpdateCaretOffset(m_nCursorOffset, fAdvancing, &m_nCaretPosX, &m_nCurrentLine);
	
	m_nAnchorPosX = m_nCaretPosX;
	ScrollToPosition(m_nCaretPosX, m_nCurrentLine);
	RepositionCaret();
}
Example #10
0
//*****************************************************************************
//
// Function Name: RGridCtrlBase::SetStyle() 
//
// Description:   Sets the style flags for the grid control
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::SetGridStyle( UINT uiStyles ) 
{
	UINT uiFlags = m_uiFlags ;
	m_uiFlags = uiStyles ;

	if (GetSafeHwnd())
	{
		// if adding spacing or removing spacing, we
		// need to allow the control to resize itself
		if (uiStyles & kAddSpacing && !(uiFlags  & kAddSpacing) ||
			 uiFlags  & kAddSpacing && !(uiStyles & kAddSpacing))
		{
			UpdateMetrics() ;
		}

		// Update the display
		Invalidate() ;
	}
}
Example #11
0
BOOL HexView::ClearFile()
{
	if(m_pDataSeq)
	{
		m_pDataSeq->clear();
	}

	m_nVScrollPos		= 0;
	m_nHScrollPos		= 0;

	m_nSelectionStart	= 0;
	m_nSelectionEnd		= 0;
	m_nCursorOffset		= 0;
	m_nSearchLen		= 0;
	m_szFilePath[0]		= '\0';

	UpdateMetrics();

	return TRUE;
}
Example #12
0
BOOL GridView::ToggleRow(GVRow *rowptr, ULONG lineNo)
{
	if(rowptr->HasChildren())
	{
		if(rowptr->items[0].state & GVIS_EXPANDED)
		{
			if(rowptr->IsChild(m_gvData.GetRow(m_nCurrentLine)))
				m_nCurrentLine = lineNo;
			
			rowptr->items[0].state &= ~GVIS_EXPANDED;				
		}
		else
		{
			rowptr->items[0].state |=GVIS_EXPANDED;
		}
		
		UpdateMetrics();
	}
	return TRUE;
}
Example #13
0
BOOL HexView::InitBuf(const BYTE *buffer, size_t len, bool copybuf, bool readonly)
{
	if(m_pDataSeq->init(buffer, len, copybuf))
	{
		m_szFilePath[0] = '\0';
		
		m_nEditMode = readonly ? HVMODE_READONLY : HVMODE_OVERWRITE;

		RecalcPositions();
		SetCaretPos((m_nAddressWidth + m_nHexPaddingLeft) * m_nFontHeight, 0);
		UpdateMetrics();

		m_nSearchLen = 0;

		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
Example #14
0
BOOL HexView::SaveFile(LPCTSTR szFileName, UINT uMethod)
{
	// filename might be NULL, in which case we overwrite current file
	if(m_pDataSeq->save(szFileName))
	{
		if(szFileName)
		{
			TCHAR *fp;
			GetFullPathName(szFileName, MAX_PATH, m_szFilePath, &fp);
		}

		UpdateMetrics();
		m_nSearchLen = 0;

		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
Example #15
0
//*****************************************************************************
//
// Function Name: RGridCtrlBase::SizeCellsToClient( int nNumRows, int nNumCols )
//
// Description:   Adjusts the cell width and height so that the
//					   number of rows and columns, specified by nNumRows
//                and nNumCols respectively, will fit into the 
//                client area.
//
// Returns:	      None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::SizeCellsToClient( int nNumRows, int nNumCols )
{
	ASSERT( GetSafeHwnd() ) ;

	CRect rect ;
	GetClientRect( rect ) ;

	// Set the number of cells per row.  
	SetNumCols( nNumCols ) ;
	m_fResizeCells = TRUE ;

	// Reset the cell dimensions 
	// with the new calculations
	SetCellDimensions( 
		(rect.Width()  / nNumCols) - 1, 
		(rect.Height() / nNumRows) - 1 ) ;

	m_cxVisibleRows = WORD( rect.Height() / m_cxCellHeight ) ;
	m_cxVisibleCols = WORD( rect.Width()  / m_cxCellWidth ) ;

	UpdateMetrics() ;
}
Example #16
0
//*****************************************************************************
//
// Function Name: RGridCtrl::OnItemAdded( int nIndex )
//
// Description:   Helper function for performing all the necessary 
//                updates to the control each time an item is added.
//
// Returns:		   None
//
// Exceptions:	   None
//
//*****************************************************************************
void RGridCtrlBase::OnItemAdded( int nIndex )
{
	if (0 == nIndex)
	{
		// Measure the item.  This is only 
		// necessary on the first addition.
		UpdateMetrics() ;
	}

	// Update the scroll bars as necessary.
	UpdateScrollBars() ;

	//
	// Determine if the current selection needs moved.
	//
	if (GetCurSel() >= nIndex)
	{
		SetCurSel( GetCurSel() + 1 ) ;
	}

	//
	// Determine if the display needs updated
	//
	CRect rect ;

	if (LB_ERR != GetItemRect( nIndex, rect ))
	{
		InvalidateRect( rect, TRUE ) ;
	}

/*	int nItemRow = nIndex / m_nNumCols ;
	int nTopRow  = GetTopIndex() / m_nNumCols ;

	if (nItemRow <= nTopRow + m_cxVisibleRows)
	{
		InvalidateRect( NULL ) ;
	}
*/
}
Example #17
0
LONG AsmView::OpenFile(TCHAR *szFileName)
{
	ClearFile();

	if(m_pTextDoc->init(szFileName))
	{
		m_nLineCount   = m_pTextDoc->linecount();
		m_nLongestLine = m_pTextDoc->longestline(4);

		m_nVScrollPos  = 0;
		m_nHScrollPos  = 0;

		m_nSelectionStart	= 0;
		m_nSelectionEnd		= 0;
		m_nCursorOffset		= 0;

		UpdateMetrics();
		UpdateMarginWidth();
		return TRUE;
	}

	return FALSE;
}
Example #18
0
void CEditX::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
{
	UpdateMetrics();
	CEdit::OnSettingChange(uFlags, lpszSection);
}
Example #19
0
void CEditX::PreSubclassWindow()
{
	UpdateMetrics();
	CEdit::PreSubclassWindow();
}
Example #20
0
static void ProcessBlock(aec_t *aec, const short *farend,
                              const short *nearend, const short *nearendH,
                              short *output, short *outputH)
{
    int i;
    float d[PART_LEN], y[PART_LEN], e[PART_LEN], dH[PART_LEN];
    short eInt16[PART_LEN];
    float scale;

    float fft[PART_LEN2];
    float xf[2][PART_LEN1], yf[2][PART_LEN1], ef[2][PART_LEN1];
    complex_t df[PART_LEN1];
    int ip[IP_LEN];
    float wfft[W_LEN];

    const float gPow[2] = {0.9f, 0.1f};

    // Noise estimate constants.
    const int noiseInitBlocks = 500 * aec->mult;
    const float step = 0.1f;
    const float ramp = 1.0002f;
    const float gInitNoise[2] = {0.999f, 0.001f};

#ifdef AEC_DEBUG
    fwrite(farend, sizeof(short), PART_LEN, aec->farFile);
    fwrite(nearend, sizeof(short), PART_LEN, aec->nearFile);
#endif

    memset(dH, 0, sizeof(dH));

    // ---------- Ooura fft ----------
    // Concatenate old and new farend blocks.
    for (i = 0; i < PART_LEN; i++) {
        aec->xBuf[i + PART_LEN] = (float)farend[i];
        d[i] = (float)nearend[i];
    }

    if (aec->sampFreq == 32000) {
        for (i = 0; i < PART_LEN; i++) {
            dH[i] = (float)nearendH[i];
        }
    }


    memcpy(fft, aec->xBuf, sizeof(float) * PART_LEN2);
    memcpy(aec->dBuf + PART_LEN, d, sizeof(float) * PART_LEN);
    // For H band
    if (aec->sampFreq == 32000) {
        memcpy(aec->dBufH + PART_LEN, dH, sizeof(float) * PART_LEN);
    }

    // Setting this on the first call initializes work arrays.
    ip[0] = 0;
    aec_rdft_128(1, fft, ip, wfft);

    // Far fft
    xf[1][0] = 0;
    xf[1][PART_LEN] = 0;
    xf[0][0] = fft[0];
    xf[0][PART_LEN] = fft[1];

    for (i = 1; i < PART_LEN; i++) {
        xf[0][i] = fft[2 * i];
        xf[1][i] = fft[2 * i + 1];
    }

    // Near fft
    memcpy(fft, aec->dBuf, sizeof(float) * PART_LEN2);
    aec_rdft_128(1, fft, ip, wfft);
    df[0][1] = 0;
    df[PART_LEN][1] = 0;
    df[0][0] = fft[0];
    df[PART_LEN][0] = fft[1];

    for (i = 1; i < PART_LEN; i++) {
        df[i][0] = fft[2 * i];
        df[i][1] = fft[2 * i + 1];
    }

    // Power smoothing
    for (i = 0; i < PART_LEN1; i++) {
        aec->xPow[i] = gPow[0] * aec->xPow[i] + gPow[1] * NR_PART *
            (xf[0][i] * xf[0][i] + xf[1][i] * xf[1][i]);
        aec->dPow[i] = gPow[0] * aec->dPow[i] + gPow[1] *
            (df[i][0] * df[i][0] + df[i][1] * df[i][1]);
    }

    // Estimate noise power. Wait until dPow is more stable.
    if (aec->noiseEstCtr > 50) {
        for (i = 0; i < PART_LEN1; i++) {
            if (aec->dPow[i] < aec->dMinPow[i]) {
                aec->dMinPow[i] = (aec->dPow[i] + step * (aec->dMinPow[i] -
                    aec->dPow[i])) * ramp;
            }
            else {
                aec->dMinPow[i] *= ramp;
            }
        }
    }

    // Smooth increasing noise power from zero at the start,
    // to avoid a sudden burst of comfort noise.
    if (aec->noiseEstCtr < noiseInitBlocks) {
        aec->noiseEstCtr++;
        for (i = 0; i < PART_LEN1; i++) {
            if (aec->dMinPow[i] > aec->dInitMinPow[i]) {
                aec->dInitMinPow[i] = gInitNoise[0] * aec->dInitMinPow[i] +
                    gInitNoise[1] * aec->dMinPow[i];
            }
            else {
                aec->dInitMinPow[i] = aec->dMinPow[i];
            }
        }
        aec->noisePow = aec->dInitMinPow;
    }
    else {
        aec->noisePow = aec->dMinPow;
    }


    // Update the xfBuf block position.
    aec->xfBufBlockPos--;
    if (aec->xfBufBlockPos == -1) {
        aec->xfBufBlockPos = NR_PART - 1;
    }

    // Buffer xf
    memcpy(aec->xfBuf[0] + aec->xfBufBlockPos * PART_LEN1, xf[0],
           sizeof(float) * PART_LEN1);
    memcpy(aec->xfBuf[1] + aec->xfBufBlockPos * PART_LEN1, xf[1],
           sizeof(float) * PART_LEN1);

    memset(yf[0], 0, sizeof(float) * (PART_LEN1 * 2));

    // Filter far
    WebRtcAec_FilterFar(aec, yf);

    // Inverse fft to obtain echo estimate and error.
    fft[0] = yf[0][0];
    fft[1] = yf[0][PART_LEN];
    for (i = 1; i < PART_LEN; i++) {
        fft[2 * i] = yf[0][i];
        fft[2 * i + 1] = yf[1][i];
    }
    aec_rdft_128(-1, fft, ip, wfft);

    scale = 2.0f / PART_LEN2;
    for (i = 0; i < PART_LEN; i++) {
        y[i] = fft[PART_LEN + i] * scale; // fft scaling
    }

    for (i = 0; i < PART_LEN; i++) {
        e[i] = d[i] - y[i];
    }

    // Error fft
    memcpy(aec->eBuf + PART_LEN, e, sizeof(float) * PART_LEN);
    memset(fft, 0, sizeof(float) * PART_LEN);
    memcpy(fft + PART_LEN, e, sizeof(float) * PART_LEN);
    aec_rdft_128(1, fft, ip, wfft);

    ef[1][0] = 0;
    ef[1][PART_LEN] = 0;
    ef[0][0] = fft[0];
    ef[0][PART_LEN] = fft[1];
    for (i = 1; i < PART_LEN; i++) {
        ef[0][i] = fft[2 * i];
        ef[1][i] = fft[2 * i + 1];
    }

    // Scale error signal inversely with far power.
    WebRtcAec_ScaleErrorSignal(aec, ef);
#ifdef G167
    if (aec->adaptToggle) {
#endif
        // Filter adaptation
        WebRtcAec_FilterAdaptation(aec, fft, ef, ip, wfft);
#ifdef G167
    }
#endif

    NonLinearProcessing(aec, ip, wfft, output, outputH);

#if defined(AEC_DEBUG) || defined(G167)
    for (i = 0; i < PART_LEN; i++) {
        eInt16[i] = (short)WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, e[i],
            WEBRTC_SPL_WORD16_MIN);
    }
#endif
#ifdef G167
    if (aec->nlpToggle == 0) {
        memcpy(output, eInt16, sizeof(eInt16));
    }
#endif

    if (aec->metricsMode == 1) {
        for (i = 0; i < PART_LEN; i++) {
            eInt16[i] = (short)WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, e[i],
                WEBRTC_SPL_WORD16_MIN);
        }

        // Update power levels and echo metrics
        UpdateLevel(&aec->farlevel, farend);
        UpdateLevel(&aec->nearlevel, nearend);
        UpdateLevel(&aec->linoutlevel, eInt16);
        UpdateLevel(&aec->nlpoutlevel, output);
        UpdateMetrics(aec);
    }

#ifdef AEC_DEBUG
    fwrite(eInt16, sizeof(short), PART_LEN, aec->outLpFile);
    fwrite(output, sizeof(short), PART_LEN, aec->outFile);
#endif
}
Example #21
0
void StatsAggregator::Aggregate(int64_t &interval_cnt, double &alpha,
                                double &weighted_avg_throughput) {
  interval_cnt++;
  LOG_INFO(
      "\n//////////////////////////////////////////////////////"
      "//////////////////////////////////////////////////////\n");
  LOG_INFO("TIME ELAPSED: %ld sec\n", interval_cnt);

  aggregated_stats_.Reset();
  std::thread::id this_id = aggregator_thread_.get_id();

  for (auto &val : backend_stats_) {
    // Exclude the txn stats generated by the aggregator thread
    if (val.first != this_id) {
      aggregated_stats_.Aggregate((*val.second));
    }
  }
  aggregated_stats_.Aggregate(stats_history_);
  LOG_INFO("%s\n", aggregated_stats_.ToString().c_str());

  int64_t current_txns_committed = 0;
  // Traverse the metric of all threads to get the total number of committed
  // txns.
  for (auto &database_item : aggregated_stats_.database_metrics_) {
    current_txns_committed +=
        database_item.second->GetTxnCommitted().GetCounter();
  }
  int64_t txns_committed_this_interval =
      current_txns_committed - total_prev_txn_committed_;
  double throughput_ = (double)txns_committed_this_interval / 1000 *
                       STATS_AGGREGATION_INTERVAL_MS;
  double avg_throughput_ = (double)current_txns_committed / interval_cnt /
                           STATS_AGGREGATION_INTERVAL_MS * 1000;
  if (interval_cnt == 1) {
    weighted_avg_throughput = throughput_;
  } else {
    weighted_avg_throughput =
        alpha * throughput_ + (1 - alpha) * weighted_avg_throughput;
  }

  total_prev_txn_committed_ = current_txns_committed;
  LOG_INFO("Average throughput:     %lf txn/s\n", avg_throughput_);
  LOG_INFO("Moving avg. throughput: %lf txn/s\n", weighted_avg_throughput);
  LOG_INFO("Current throughput:     %lf txn/s\n\n", throughput_);

  // Write the stats to metric tables
  UpdateMetrics();

  if (interval_cnt % STATS_LOG_INTERVALS == 0) {
    try {
      ofs_ << "At interval: " << interval_cnt << std::endl;
      ofs_ << aggregated_stats_.ToString();
      ofs_ << "Weighted avg. throughput=" << weighted_avg_throughput
           << std::endl;
      ofs_ << "Average throughput=" << avg_throughput_ << std::endl;
      ofs_ << "Current throughput=" << throughput_ << std::endl;
    }
    catch (std::ofstream::failure &e) {
      LOG_ERROR("Error when writing to the stats log file %s", e.what());
    }
  }
}
/****************************************************************************************
fmhd main process
******************************************************************************************/
RETURN_CODE fmhd_amhd_work_mode(void)
{
	RETURN_CODE ret = SUCCESS;

	//u8 temp_str[16];
#ifndef OPTION__OPERATE_AS_SLAVE_NO_MMI
	static bit hd_flag = 0;
	static u8 display_item_state = 0;
#endif

	if( power_flag ==0)
	{
		power_flag =1;
		fmhd_amhd_initialize();
	}

#ifndef OPTION__OPERATE_AS_SLAVE_NO_MMI
	ret |=fmhd_amhd_key_process();
	
	if(display_item_str_4ms >0)
	{
		//display_refresh_flag = 1;
		return 0;// wait for time up
	}

    if(ber_running_flag == 1)
    {
        fmhd_BER_update_display();
        return 0; // We do not want to leave this screen until we have stopped running the BER test
    }

	 if(display_refresh_flag==1)
	{
		display_refresh_flag=0;
		ret |= display_hd_ui();
	}
	else //if(display_item_str_4ms == 0)
	{
	
		display_item_str_4ms = STATUS_UPDATE_INTERVAL;
		if(item_loop == ITEM_AUTO_ROLL) // display will auto change next next 
		{
			if(work_mode == fmhd)
			{
				if(display_item_state > sizeof(FMHD_DISPLAY_ITEM)/sizeof(FMHD_DISPLAY_ITEM[0])-1)
				{
					display_item_state = 1;
				}
			}
        #ifdef OPTION__INCLUDE_MODE__AMHD
			else if(work_mode == amhd)
			{
				if(display_item_state > sizeof(AMHD_DISPLAY_ITEM)/sizeof(AMHD_DISPLAY_ITEM[0])-1)
				{
					display_item_state = 1;
				}
			}
        #endif // OPTION__INCLUDE_MODE__AMHD		
		}
		else
		{
			display_item_state = item_loop;// fix display special item switched by hold tune knobs
		}

		if(work_mode == fmhd)
		{
			if (display_data_item(FMHD_DISPLAY_ITEM[display_item_state]) == ITEM_NEXT)
			{
				display_item_state ++;
			}   
			ret = UpdateMetrics();
			if(MetricsGetFMHDPtr()->AUDIO_SOURCE != hd_flag)
			{
				hd_flag= MetricsGetFMHDPtr()->AUDIO_SOURCE;
				show_freq(0,0);
			}			 
		}
    #ifdef OPTION__INCLUDE_MODE__AMHD
		else
		{
			if (display_data_item(AMHD_DISPLAY_ITEM[display_item_state]) == ITEM_NEXT)
			{
				display_item_state ++;
			}  
			ret = UpdateMetrics();
			if(MetricsGetAMHDPtr()->AUDIO_SOURCE != hd_flag)
			{
				hd_flag= MetricsGetAMHDPtr()->AUDIO_SOURCE;
				show_freq(0,0);
			}			  
		}
    #endif //OPTION__INCLUDE_MODE__AMHD		
	}
#endif //OPTION__OPERATE_AS_SLAVE_NO_MMI

#ifdef OPTION__OPERATE_AS_SLAVE_NO_MMI
	ret |= UpdateMetrics();
	ret |= UpdateDataServiceData();
#endif //OPTION__OPERATE_AS_SLAVE_NO_MMI

    ret |= UpdateServiceList(); // Need to periodically check for updates to the service list - reconfiguration
	return ret;
}
Example #23
0
static void ProcessBlock(aec_t* aec) {
    int i;
    float d[PART_LEN], y[PART_LEN], e[PART_LEN], dH[PART_LEN];
    float scale;

    float fft[PART_LEN2];
    float xf[2][PART_LEN1], yf[2][PART_LEN1], ef[2][PART_LEN1];
    float df[2][PART_LEN1];
    float far_spectrum = 0.0f;
    float near_spectrum = 0.0f;
    float abs_far_spectrum[PART_LEN1];
    float abs_near_spectrum[PART_LEN1];

    const float gPow[2] = {0.9f, 0.1f};

    // Noise estimate constants.
    const int noiseInitBlocks = 500 * aec->mult;
    const float step = 0.1f;
    const float ramp = 1.0002f;
    const float gInitNoise[2] = {0.999f, 0.001f};

    int16_t nearend[PART_LEN];
    int16_t* nearend_ptr = NULL;
    int16_t output[PART_LEN];
    int16_t outputH[PART_LEN];

    float* xf_ptr = NULL;

    memset(dH, 0, sizeof(dH));
    if (aec->sampFreq == 32000) {
      // Get the upper band first so we can reuse |nearend|.
      WebRtc_ReadBuffer(aec->nearFrBufH,
                        (void**) &nearend_ptr,
                        nearend,
                        PART_LEN);
      for (i = 0; i < PART_LEN; i++) {
          dH[i] = (float) (nearend_ptr[i]);
      }
      memcpy(aec->dBufH + PART_LEN, dH, sizeof(float) * PART_LEN);
    }
    WebRtc_ReadBuffer(aec->nearFrBuf, (void**) &nearend_ptr, nearend, PART_LEN);

    // ---------- Ooura fft ----------
    // Concatenate old and new nearend blocks.
    for (i = 0; i < PART_LEN; i++) {
        d[i] = (float) (nearend_ptr[i]);
    }
    memcpy(aec->dBuf + PART_LEN, d, sizeof(float) * PART_LEN);

#ifdef WEBRTC_AEC_DEBUG_DUMP
    {
        int16_t farend[PART_LEN];
        int16_t* farend_ptr = NULL;
        WebRtc_ReadBuffer(aec->far_time_buf, (void**) &farend_ptr, farend, 1);
        (void)fwrite(farend_ptr, sizeof(int16_t), PART_LEN, aec->farFile);
        (void)fwrite(nearend_ptr, sizeof(int16_t), PART_LEN, aec->nearFile);
    }
#endif

    // We should always have at least one element stored in |far_buf|.
    assert(WebRtc_available_read(aec->far_buf) > 0);
    WebRtc_ReadBuffer(aec->far_buf, (void**) &xf_ptr, &xf[0][0], 1);

    // Near fft
    memcpy(fft, aec->dBuf, sizeof(float) * PART_LEN2);
    TimeToFrequency(fft, df, 0);

    // Power smoothing
    for (i = 0; i < PART_LEN1; i++) {
      far_spectrum = (xf_ptr[i] * xf_ptr[i]) +
          (xf_ptr[PART_LEN1 + i] * xf_ptr[PART_LEN1 + i]);
      aec->xPow[i] = gPow[0] * aec->xPow[i] + gPow[1] * NR_PART * far_spectrum;
      // Calculate absolute spectra
      abs_far_spectrum[i] = sqrtf(far_spectrum);

      near_spectrum = df[0][i] * df[0][i] + df[1][i] * df[1][i];
      aec->dPow[i] = gPow[0] * aec->dPow[i] + gPow[1] * near_spectrum;
      // Calculate absolute spectra
      abs_near_spectrum[i] = sqrtf(near_spectrum);
    }

    // Estimate noise power. Wait until dPow is more stable.
    if (aec->noiseEstCtr > 50) {
        for (i = 0; i < PART_LEN1; i++) {
            if (aec->dPow[i] < aec->dMinPow[i]) {
                aec->dMinPow[i] = (aec->dPow[i] + step * (aec->dMinPow[i] -
                    aec->dPow[i])) * ramp;
            }
            else {
                aec->dMinPow[i] *= ramp;
            }
        }
    }

    // Smooth increasing noise power from zero at the start,
    // to avoid a sudden burst of comfort noise.
    if (aec->noiseEstCtr < noiseInitBlocks) {
        aec->noiseEstCtr++;
        for (i = 0; i < PART_LEN1; i++) {
            if (aec->dMinPow[i] > aec->dInitMinPow[i]) {
                aec->dInitMinPow[i] = gInitNoise[0] * aec->dInitMinPow[i] +
                    gInitNoise[1] * aec->dMinPow[i];
            }
            else {
                aec->dInitMinPow[i] = aec->dMinPow[i];
            }
        }
        aec->noisePow = aec->dInitMinPow;
    }
    else {
        aec->noisePow = aec->dMinPow;
    }

    // Block wise delay estimation used for logging
    if (aec->delay_logging_enabled) {
      int delay_estimate = 0;
      // Estimate the delay
      delay_estimate = WebRtc_DelayEstimatorProcessFloat(aec->delay_estimator,
                                                         abs_far_spectrum,
                                                         abs_near_spectrum,
                                                         PART_LEN1);
      if (delay_estimate >= 0) {
        // Update delay estimate buffer.
        aec->delay_histogram[delay_estimate]++;
      }
    }

    // Update the xfBuf block position.
    aec->xfBufBlockPos--;
    if (aec->xfBufBlockPos == -1) {
        aec->xfBufBlockPos = NR_PART - 1;
    }

    // Buffer xf
    memcpy(aec->xfBuf[0] + aec->xfBufBlockPos * PART_LEN1, xf_ptr,
           sizeof(float) * PART_LEN1);
    memcpy(aec->xfBuf[1] + aec->xfBufBlockPos * PART_LEN1, &xf_ptr[PART_LEN1],
           sizeof(float) * PART_LEN1);

    memset(yf, 0, sizeof(yf));

    // Filter far
    WebRtcAec_FilterFar(aec, yf);

    // Inverse fft to obtain echo estimate and error.
    fft[0] = yf[0][0];
    fft[1] = yf[0][PART_LEN];
    for (i = 1; i < PART_LEN; i++) {
        fft[2 * i] = yf[0][i];
        fft[2 * i + 1] = yf[1][i];
    }
    aec_rdft_inverse_128(fft);

    scale = 2.0f / PART_LEN2;
    for (i = 0; i < PART_LEN; i++) {
        y[i] = fft[PART_LEN + i] * scale; // fft scaling
    }

    for (i = 0; i < PART_LEN; i++) {
        e[i] = d[i] - y[i];
    }

    // Error fft
    memcpy(aec->eBuf + PART_LEN, e, sizeof(float) * PART_LEN);
    memset(fft, 0, sizeof(float) * PART_LEN);
    memcpy(fft + PART_LEN, e, sizeof(float) * PART_LEN);
    // TODO(bjornv): Change to use TimeToFrequency().
    aec_rdft_forward_128(fft);

    ef[1][0] = 0;
    ef[1][PART_LEN] = 0;
    ef[0][0] = fft[0];
    ef[0][PART_LEN] = fft[1];
    for (i = 1; i < PART_LEN; i++) {
        ef[0][i] = fft[2 * i];
        ef[1][i] = fft[2 * i + 1];
    }

    if (aec->metricsMode == 1) {
      // Note that the first PART_LEN samples in fft (before transformation) are
      // zero. Hence, the scaling by two in UpdateLevel() should not be
      // performed. That scaling is taken care of in UpdateMetrics() instead.
      UpdateLevel(&aec->linoutlevel, ef);
    }

    // Scale error signal inversely with far power.
    WebRtcAec_ScaleErrorSignal(aec, ef);
    WebRtcAec_FilterAdaptation(aec, fft, ef);
    NonLinearProcessing(aec, output, outputH);

    if (aec->metricsMode == 1) {
        // Update power levels and echo metrics
        UpdateLevel(&aec->farlevel, (float (*)[PART_LEN1]) xf_ptr);
        UpdateLevel(&aec->nearlevel, df);
        UpdateMetrics(aec);
    }

    // Store the output block.
    WebRtc_WriteBuffer(aec->outFrBuf, output, PART_LEN);
    // For H band
    if (aec->sampFreq == 32000) {
        WebRtc_WriteBuffer(aec->outFrBufH, outputH, PART_LEN);
    }

#ifdef WEBRTC_AEC_DEBUG_DUMP
    {
        int16_t eInt16[PART_LEN];
        for (i = 0; i < PART_LEN; i++) {
            eInt16[i] = (int16_t)WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, e[i],
                WEBRTC_SPL_WORD16_MIN);
        }

        (void)fwrite(eInt16, sizeof(int16_t), PART_LEN, aec->outLinearFile);
        (void)fwrite(output, sizeof(int16_t), PART_LEN, aec->outFile);
    }
#endif
}
/****************************************************************************************
fm main process .include deal with key and some status update and LCD refresh 
******************************************************************************************/
RETURN_CODE fm_am_work_mode(void)
{
	RETURN_CODE ret = SUCCESS;
#ifndef OPTION__OPERATE_AS_SLAVE_NO_MMI
	static u8 display_item_state = 0;
#endif
	
	if( power_flag ==0)
	{
		power_flag =1;
		fm_am_initialize();
	}
#ifndef OPTION__OPERATE_AS_SLAVE_NO_MMI
	ret |= fm_am_key_process();

	if(display_item_str_4ms >0)
	{
		//display_refresh_flag = 1;//refresh_gui interval
		return 0;// wait for time up
	}

	if(display_refresh_flag == 1)
	{  
		display_refresh_flag = 0;
		ret |= refresh_fm_ui();
	}
	else// if(display_item_str_4ms == 0)
	{
		display_item_str_4ms = STATUS_UPDATE_INTERVAL;
		if(item_loop == ITEM_AUTO_ROLL) // display will auto change next next 
		{
			if(work_mode == fmonly)
			{
				if(display_item_state >  sizeof(FM_DISPLAY_ITEM)/sizeof(FM_DISPLAY_ITEM[0])-1)
				{
					display_item_state = 1;
				}
			}
			#ifdef OPTION__INCLUDE_MODE__AM
			else
			{
				if(display_item_state >  sizeof(AM_DISPLAY_ITEM)/sizeof(AM_DISPLAY_ITEM[0])-1)
				{
					display_item_state = 1;
				}
			}
			#endif				
		}
		else
		{
			display_item_state = item_loop;// fix display special item switched by hold tune knobs
		}

		if(work_mode == fmonly)
		{
			if (display_data_item(FM_DISPLAY_ITEM[display_item_state]) == ITEM_NEXT)
			{
				display_item_state ++;
			}
		}
		#ifdef OPTION__INCLUDE_MODE__AM
		
		else
		{
			if (display_data_item(AM_DISPLAY_ITEM[display_item_state]) == ITEM_NEXT)
			{
				display_item_state ++;
			}
		}
		
		#endif			
		//show_freq(0,0);//refresh the frequency display
	}
#endif //OPTION__OPERATE_AS_SLAVE_NO_MMI

#ifdef OPTION__OPERATE_AS_SLAVE_NO_MMI
	ret |= UpdateMetrics();
	ret |= UpdateDataServiceData();
#endif //OPTION__OPERATE_AS_SLAVE_NO_MMI

	return ret;
}