/*++ BB11BSpd is a simple implementation of software power detection. Return: E_FETCH_SIGNAL_HW_TIMEOUT, E_FETCH_SIGNAL_FORCE_STOPPED, BB11B_E_PD_LAG, BB11B_CHANNEL_CLEAN, BB11B_OK_POWER_DETECTED --*/ HRESULT BB11BSpd(PBB11B_SPD_CONTEXT pSpdContext, PSORA_RADIO_RX_STREAM pRxStream) { // Alias FLAG *b_workIndicator = pSpdContext->b_workIndicator; // pointer to flag, 0 for force stop, 1 for work vcs& DcOffset = (vcs&)pSpdContext->dcOffset; vui& BlockEnergySum = (vui&)pSpdContext->BlockEnergySum; FLAG touched; ULONG PeekBlockCount = 0; HRESULT hr = S_OK; int energyLevel; if (pSpdContext->b_resetFlag) { //DbgPrint("[TEMP1] reset\n"); BB11BSpdResetHistory(pSpdContext); } SignalBlock block; do { if (pSpdContext->b_reestimateOffset) { hr = BB11BGetAccurateDCOffset( pRxStream, DcOffset, &PeekBlockCount, &touched); FAILED_BREAK(hr); pSpdContext->b_reestimateOffset = 0; } while (TRUE) { hr = SoraRadioReadRxStream(pRxStream, &touched, block); FAILED_BREAK(hr); // Check whether force stopped if (*b_workIndicator == 0) { hr = BB11B_E_FORCE_STOP; break; } // Estimate and update DC offset SoraUpdateDC(block, DcOffset); RemoveDC(block, DcOffset); BlockEnergySum = SoraGetNorm(block); PeekBlockCount++; energyLevel = BB11BSpdUpdateEngeryHistoryAndCheckThreshold( pSpdContext, pSpdContext->b_threshold, pSpdContext->b_gainLevel ? pSpdContext->b_thresholdHL : pSpdContext->b_thresholdLH ); if (energyLevel != EL_NOISE) { if (pSpdContext->b_gainLevel == 0 && energyLevel == EL_HIGH) pSpdContext->b_gainLevelNext = 1; else if (pSpdContext->b_gainLevel == 1 && energyLevel == EL_LOW) pSpdContext->b_gainLevelNext = 0; pSpdContext->b_evalEnergy = BlockEnergySum[0]; hr = BB11B_OK_POWER_DETECTED; break; } if (touched && PeekBlockCount > pSpdContext->b_minDescCount) { hr = BB11B_CHANNEL_CLEAN; break; } if (PeekBlockCount >= pSpdContext->b_maxDescCount) { hr = BB11B_E_PD_LAG; break; } } } while(FALSE); pSpdContext->b_dcOffset = DcOffset[0]; return hr; }
//extract one sentence of MFCC/LFCC int CMFCC::MFCCbySentence(short *pnWav, int SampleCount, float *&pfMFCC, int &FrmCount, int &Dim, int FrmWidth, int FrmOffst) { int i; if(FrmWidth>N || FrmOffst>FrmWidth) return FAILURE; //compute frame count & dim of feature vector & allocate memory space FrmCount=(SampleCount-FrmWidth)/FrmOffst+1; if(FrmCount<=0) return FAILURE; if(Info&DCEPS) { if(FrmCount<=10) return FAILURE; } Dim=P; if(Info&DCEPS) Dim+=P; if(Info&DDCEPS) Dim+=P; pfMFCC = new float[FrmCount*Dim]; //remove DC component RemoveDC(pnWav, SampleCount); //extract one sentence of MFCC for(i=0 ; i<FrmCount ; i++) { MFCCbyFrame(&pnWav[i*FrmOffst], FrmWidth, &pfMFCC[i*Dim], P); } //CMS if(Info&CMS) { CepsMeanSub(pfMFCC, FrmCount, Dim, P); } //extract one sentence of DMFCC if(Info&DCEPS) { DMFCCbyFrame(&pfMFCC[0], &pfMFCC[0], &pfMFCC[0], &pfMFCC[1*Dim], &pfMFCC[2*Dim], &pfMFCC[P], P); DMFCCbyFrame(&pfMFCC[0], &pfMFCC[0], &pfMFCC[1*Dim], &pfMFCC[2*Dim], &pfMFCC[3*Dim], &pfMFCC[1*Dim+P], P); for(i=2 ; i<=FrmCount-3 ; i++) DMFCCbyFrame(&pfMFCC[(i-2)*Dim], &pfMFCC[(i-1)*Dim], &pfMFCC[i*Dim], &pfMFCC[(i+1)*Dim], &pfMFCC[(i+2)*Dim], &pfMFCC[i*Dim+P], P); DMFCCbyFrame(&pfMFCC[(FrmCount-4)*Dim], &pfMFCC[(FrmCount-3)*Dim], &pfMFCC[(FrmCount-2)*Dim], &pfMFCC[(FrmCount-1)*Dim], &pfMFCC[(FrmCount-1)*Dim], &pfMFCC[(FrmCount-2)*Dim+P], P); DMFCCbyFrame(&pfMFCC[(FrmCount-3)*Dim], &pfMFCC[(FrmCount-2)*Dim], &pfMFCC[(FrmCount-1)*Dim], &pfMFCC[(FrmCount-1)*Dim], &pfMFCC[(FrmCount-1)*Dim], &pfMFCC[(FrmCount-1)*Dim+P], P); } //extract one sentence of DDMFCC if(Info&DDCEPS) { for(i=0 ; i<P ; i++) { pfMFCC[2*P+i] = pfMFCC[(FrmCount-1)*Dim+2*P+i] = 0; } for(i=1 ; i<=FrmCount-2 ; i++) { DDMFCCbyFrame(&pfMFCC[(i-1)*Dim+P], &pfMFCC[i*Dim+P], &pfMFCC[(i+1)*Dim+P], &pfMFCC[i*Dim+2*P], P); } } return SUCCESS; }