Пример #1
0
void vsvesq(const float* sourceP,
            int sourceStride,
            float* sumP,
            size_t framesToProcess) {
    vDSP_svesq(const_cast<float*>(sourceP), sourceStride, sumP, framesToProcess);
}
Пример #2
0
bool SFB::Audio::ReplayGainAnalyzer::AnalyzeSamples(const float *left_samples, const float *right_samples, size_t num_samples, bool stereo)
{
	if(0 == num_samples)
		return true;

	const float *curleft;
	const float *curright;

	long cursamplepos = 0;
	long batchsamples = (long)num_samples;

	if(!stereo)
		right_samples = left_samples;

	if(num_samples < MAX_ORDER) {
		memcpy(priv->linprebuf + MAX_ORDER, left_samples,  num_samples * sizeof(float));
		memcpy(priv->rinprebuf + MAX_ORDER, right_samples, num_samples * sizeof(float));
	}
	else {
		memcpy(priv->linprebuf + MAX_ORDER, left_samples,  MAX_ORDER   * sizeof(float));
		memcpy(priv->rinprebuf + MAX_ORDER, right_samples, MAX_ORDER   * sizeof(float));
	}
	
	while(batchsamples > 0) {
		long cursamples = std::min((long)priv->sampleWindow - (long)priv->totsamp, batchsamples);
		if(cursamplepos < MAX_ORDER) {
			curleft  = priv->linpre + cursamplepos;
			curright = priv->rinpre + cursamplepos;
			if(cursamples > MAX_ORDER - cursamplepos)
				cursamples = MAX_ORDER - cursamplepos;
		}
		else {
			curleft  = left_samples  + cursamplepos;
			curright = right_samples + cursamplepos;
		}
		
		filter(curleft , priv->lstep + priv->totsamp, (size_t)cursamples, AYule[priv->freqindex], BYule[priv->freqindex], YULE_ORDER);
		filter(curright, priv->rstep + priv->totsamp, (size_t)cursamples, AYule[priv->freqindex], BYule[priv->freqindex], YULE_ORDER);
		
		filter(priv->lstep + priv->totsamp, priv->lout + priv->totsamp, (size_t)cursamples, AButter[priv->freqindex], BButter[priv->freqindex], BUTTER_ORDER);
		filter(priv->rstep + priv->totsamp, priv->rout + priv->totsamp, (size_t)cursamples, AButter[priv->freqindex], BButter[priv->freqindex], BUTTER_ORDER);
		
		/* Get the squared values */
		float sum;
		vDSP_svesq(priv->lout + priv->totsamp, 1, &sum, (vDSP_Length)cursamples);
		priv->lsum += sum;

		vDSP_svesq(priv->rout + priv->totsamp, 1, &sum, (vDSP_Length)cursamples);
		priv->rsum += sum;

		batchsamples -= cursamples;
		cursamplepos += cursamples;
		priv->totsamp += (unsigned long)cursamples;

		/* Get the Root Mean Square (RMS) for this set of samples */
		if(priv->totsamp == priv->sampleWindow) {
			double  val  = STEPS_per_dB * 10. * log10((priv->lsum + priv->rsum) / priv->totsamp * 0.5 + 1.e-37);
			int     ival = (int) val;
			if(ival < 0)
				ival = 0;
			if(ival >= (int)(sizeof(priv->A)/sizeof(*(priv->A))))
				ival = (int)(sizeof(priv->A)/sizeof(*(priv->A))) - 1;

			priv->A [ival]++;
			priv->lsum = priv->rsum = 0.;

			memmove(priv->loutbuf , priv->loutbuf  + priv->totsamp, MAX_ORDER * sizeof(float));
			memmove(priv->routbuf , priv->routbuf  + priv->totsamp, MAX_ORDER * sizeof(float));
			memmove(priv->lstepbuf, priv->lstepbuf + priv->totsamp, MAX_ORDER * sizeof(float));
			memmove(priv->rstepbuf, priv->rstepbuf + priv->totsamp, MAX_ORDER * sizeof(float));

			priv->totsamp = 0;
		}

		/* somehow I really screwed up: Error in programming! Contact author about totsamp > sampleWindow */
		if(priv->totsamp > priv->sampleWindow)
			return false;
	}

	if(num_samples < MAX_ORDER) {
		memmove(priv->linprebuf,                           priv->linprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(float));
		memmove(priv->rinprebuf,                           priv->rinprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(float));
		memcpy (priv->linprebuf + MAX_ORDER - num_samples, left_samples,                  num_samples             * sizeof(float));
		memcpy (priv->rinprebuf + MAX_ORDER - num_samples, right_samples,                 num_samples             * sizeof(float));
	}
	else {
		memcpy (priv->linprebuf, left_samples  + num_samples - MAX_ORDER, MAX_ORDER * sizeof(float));
		memcpy (priv->rinprebuf, right_samples + num_samples - MAX_ORDER, MAX_ORDER * sizeof(float));
	}

    return true;
}