Пример #1
0
float soundProcessor::Process(float Sample)
{
    // push input sample up input buffer
    m_pX[m_Ix] = Sample;

    float y = CoreProcess();

    // push output sample up output buffer
    m_pY[m_Iy] = y;

    // increment pointers
    m_Ix = (m_Ix + 1) % BUF_MASK;
    m_Iy = (m_Iy + 1) % BUF_MASK;

    return y;
}
Пример #2
0
void SRS_Source_Out::Process(void* pSamples, int sampleBytes, int sampleRate, int countChans){
	// Will NOT touch Audio in these cases...
	if (sampleRate < 0) return;
	if (countChans != 2) return;
	if (DidAPIInit == false) APIInit(sampleRate, countChans);
	if (DidAPIInit == false) return;	// Still not ready?
	
	int tFrames = sampleBytes/(sizeof(int16_t)*countChans);
	if (Framesize != tFrames){
		Framesize = tFrames;
		if ((Framesize%256 != 0) && (UseCache == false)){
			SRS_LOG("Framesize of %d forcing Cache!!", Framesize);
			InitCaching();
		}
	}
	
	int16_t FadeHold[512];	// 256*stereo
	
	bool tWantProcess = WillProcess();
	
	if (tWantProcess == false){	// Turning off...
		if (ProcState == PROCST_OFF) return;	// Already off...
		else if (ProcState == PROCST_IN){	// Was fading in, fade out...
			ProcState = PROCST_OUT;
			ProcTrack = PROC_FADELEN-ProcTrack;
		} else if (ProcState == PROCST_ON){	// start fade out..
			ProcState = PROCST_OUT;
			ProcTrack = 0;
		}
		// else already fading out - keep going...
	} else {
		if (ProcState == PROCST_OFF){
			ProcState = PROCST_IN;
			ProcTrack = 0;
			if (UseCache == true) InitCaching();	// Caching?  Reset...
		} else if (ProcState == PROCST_OUT){
			ProcState = PROCST_IN;
			ProcTrack = PROC_FADELEN-ProcTrack;
		}
	}
		
	int16_t* pSampsIn = (int16_t*)pSamples;
		
	// Fade In/Out... may return early...
	while ((ProcState == PROCST_OUT) || (ProcState == PROCST_IN)){
		SRS_LOG("Fading %d - %d", ProcState, ProcTrack);
		int tProcLen = (tFrames<256)?tFrames:256;	// How many samples to process?
		tFrames -= tProcLen;	// Pull that many off...
		
		int16_t* pSampsOrig = FadeHold;
		memcpy(FadeHold, pSampsIn, tProcLen*sizeof(int16_t)*countChans);	// Back up data for fade...
		CoreProcess(pSampsIn, tProcLen);	// Process...
		
		int tProcRemain = PROC_FADELEN-ProcTrack;	// How much can we process?
		int tDoProc = (tProcRemain<tProcLen)?tProcRemain:tProcLen;	// How many will we process?
		int tDoPass = (tProcLen>tDoProc)?(tProcLen-tDoProc):0;		// How many will we fill from history/processed?
		int32_t tTween = ProcTrack*gProcStep;	// Where we are in the fade...
		ProcTrack += tDoProc;
		
		if (ProcState == PROCST_OUT){	// Fading out...
			FadeLoop_2Chan(pSampsIn, pSampsOrig, pSampsIn, tTween, gProcStep, tDoProc);
			pSampsIn += 2*tDoProc;
			pSampsOrig += 2*tDoProc;
			
			if (tDoPass > 0){	// We over processed - so restore from the originals we saved...
				memcpy(pSampsIn, pSampsOrig, tDoPass*sizeof(int16_t)*countChans);
				pSampsIn += 2*tDoPass;
			}
			
			if (ProcTrack >= PROC_FADELEN){
				ProcState = PROCST_OFF;	// Done!!!
				return;
			}
		} else {						// Fading in...
			tTween -= PROC_DELAYIN*gProcStep;	// Adjust for the fade-in delay...
			FadeLoop_2Chan(pSampsIn, pSampsIn, pSampsOrig, tTween, gProcStep, tDoProc);
			pSampsIn += 2*tProcLen;		// Anything past tDoProc until tProcLen will be what we processed... no 'pass' phase...
			
			if (ProcTrack >= PROC_FADELEN){
				ProcState = PROCST_ON;	// Done!!!
			}
		}
		
		if (tFrames <= 0) break;
	}
	
	if (tFrames > 0) CoreProcess(pSampsIn, tFrames);
}