[svn-commits] dvossel: branch dvossel/funk_effects r249319 - /team/dvossel/funk_effects/funcs/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Feb 27 11:16:34 CST 2010


Author: dvossel
Date: Sat Feb 27 11:16:30 2010
New Revision: 249319

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=249319
Log:
coding guideline fixes

Modified:
    team/dvossel/funk_effects/funcs/func_pitchshift.c

Modified: team/dvossel/funk_effects/funcs/func_pitchshift.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/funk_effects/funcs/func_pitchshift.c?view=diff&rev=249319&r1=249318&r2=249319
==============================================================================
--- team/dvossel/funk_effects/funcs/func_pitchshift.c (original)
+++ team/dvossel/funk_effects/funcs/func_pitchshift.c Sat Feb 27 11:16:30 2010
@@ -115,7 +115,7 @@
 	struct fft_data tx;
 };
 
-static void smb_fft(float *fftBuffer, long fft_frame_size, long sign);
+static void smb_fft(float *fft_buffer, long fft_frame_size, long sign);
 static void smb_pitch_shift(float pitchShift, long num_samps_to_process, long fft_frame_size, long osamp, float sample_rate, int16_t *indata, int16_t *outdata, struct fft_data *fft_data);
 static int pitch_shift(struct ast_frame *f, float amount, struct fft_data *fft_data);
 
@@ -155,9 +155,9 @@
 	shift = datastore->data;
 
 	/* READ for tx WRITE for rx */
-	if ((direction == AST_AUDIOHOOK_DIRECTION_READ) && shift->tx.shift_amount) {
+	if (direction == AST_AUDIOHOOK_DIRECTION_READ) {
 		pitch_shift(f, shift->tx.shift_amount, &shift->tx);
-	} else if ((direction == AST_AUDIOHOOK_DIRECTION_WRITE) && shift->rx.shift_amount) {
+	} else {
 		pitch_shift(f, shift->rx.shift_amount, &shift->rx);
 	}
 
@@ -222,36 +222,38 @@
 	return -1;
 }
 
-static void smb_fft(float *fftBuffer, long fft_frame_size, long sign)
+static void smb_fft(float *fft_buffer, long fft_frame_size, long sign)
 {
 	float wr, wi, arg, *p1, *p2, temp;
 	float tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i;
 	long i, bitm, j, le, le2, k;
 
-	for (i = 2; i < 2*fft_frame_size-2; i += 2) {
-		for (bitm = 2, j = 0; bitm < 2*fft_frame_size; bitm <<= 1) {
-			if (i & bitm) j++;
+	for (i = 2; i < 2 * fft_frame_size - 2; i += 2) {
+		for (bitm = 2, j = 0; bitm < 2 * fft_frame_size; bitm <<= 1) {
+			if (i & bitm) {
+				j++;
+			}
 			j <<= 1;
 		}
 		if (i < j) {
-			p1 = fftBuffer+i; p2 = fftBuffer+j;
+			p1 = fft_buffer + i; p2 = fft_buffer + j;
 			temp = *p1; *(p1++) = *p2;
 			*(p2++) = temp; temp = *p1;
 			*p1 = *p2; *p2 = temp;
 		}
 	}
-	for (k = 0, le = 2; k < (long)(log(fft_frame_size)/log(2.)+.5); k++) {
+	for (k = 0, le = 2; k < (long) (log(fft_frame_size) / log(2.) + .5); k++) {
 		le <<= 1;
 		le2 = le>>1;
 		ur = 1.0;
 		ui = 0.0;
 		arg = M_PI / (le2>>1);
 		wr = cos(arg);
-		wi = sign*sin(arg);
+		wi = sign * sin(arg);
 		for (j = 0; j < le2; j += 2) {
-			p1r = fftBuffer+j; p1i = p1r+1;
-			p2r = p1r+le2; p2i = p2r+1;
-			for (i = j; i < 2*fft_frame_size; i += le) {
+			p1r = fft_buffer+j; p1i = p1r + 1;
+			p2r = p1r + le2; p2i = p2r + 1;
+			for (i = j; i < 2 * fft_frame_size; i += le) {
 				tr = *p2r * ur - *p2i * ui;
 				ti = *p2r * ui + *p2i * ur;
 				*p2r = *p1r - tr; *p2i = *p1i - ti;
@@ -259,8 +261,8 @@
 				p1r += le; p1i += le;
 				p2r += le; p2i += le;
 			}
-			tr = ur*wr - ui*wi;
-			ui = ur*wi + ui*wr;
+			tr = ur * wr - ui * wi;
+			ui = ur * wi + ui * wr;
 			ur = tr;
 		}
 	}
@@ -284,19 +286,22 @@
 	long i,k, qpd, index, in_fifo_latency, step_size, fft_frame_size2;
 
 	/* set up some handy variables */
-	fft_frame_size2 = fft_frame_size/2;
-	step_size = fft_frame_size/osamp;
-	freq_per_bin = sample_rate/(double)fft_frame_size;
-	expct = 2.*M_PI*(double)step_size/(double)fft_frame_size;
+	fft_frame_size2 = fft_frame_size / 2;
+	step_size = fft_frame_size / osamp;
+	freq_per_bin = sample_rate / (double) fft_frame_size;
+	expct = 2. * M_PI * (double) step_size / (double) fft_frame_size;
 	in_fifo_latency = fft_frame_size-step_size;
-	if (fft_data->gRover == 0) fft_data->gRover = in_fifo_latency;
+
+	if (fft_data->gRover == 0) {
+		fft_data->gRover = in_fifo_latency;
+	}
 
 	/* main processing loop */
 	for (i = 0; i < num_samps_to_process; i++){
 
 		/* As long as we have not yet collected enough data just read in */
 		in_fifo[fft_data->gRover] = indata[i];
-		outdata[i] = out_fifo[fft_data->gRover-in_fifo_latency];
+		outdata[i] = out_fifo[fft_data->gRover - in_fifo_latency];
 		fft_data->gRover++;
 
 		/* now we have enough data for processing */
@@ -305,7 +310,7 @@
 
 			/* do windowing and re,im interleave */
 			for (k = 0; k < fft_frame_size;k++) {
-				window = -.5*cos(2.*M_PI*(double)k/(double)fft_frame_size)+.5;
+				window = -.5 * cos(2. * M_PI * (double) k / (double) fft_frame_size) + .5;
 				fft_worksp[2*k] = in_fifo[k] * window;
 				fft_worksp[2*k+1] = 0.;
 			}
@@ -322,27 +327,30 @@
 				imag = fft_worksp[2*k+1];
 
 				/* compute magnitude and phase */
-				magn = 2.*sqrt(real*real + imag*imag);
-				phase = atan2(imag,real);
+				magn = 2. * sqrt(real * real + imag * imag);
+				phase = atan2(imag, real);
 
 				/* compute phase difference */
 				tmp = phase - last_phase[k];
 				last_phase[k] = phase;
 
 				/* subtract expected phase difference */
-				tmp -= (double)k*expct;
+				tmp -= (double) k * expct;
 
 				/* map delta phase into +/- Pi interval */
-				qpd = tmp/M_PI;
-				if (qpd >= 0) qpd += qpd&1;
-				else qpd -= qpd&1;
-				tmp -= M_PI*(double)qpd;
+				qpd = tmp / M_PI;
+				if (qpd >= 0) {
+					qpd += qpd & 1;
+				} else {
+					qpd -= qpd & 1;
+				}
+				tmp -= M_PI * (double) qpd;
 
 				/* get deviation from bin frequency from the +/- Pi interval */
-				tmp = osamp*tmp/(2.*M_PI);
+				tmp = osamp * tmp / (2. * M_PI);
 
 				/* compute the k-th partials' true frequency */
-				tmp = (double)k*freq_per_bin + tmp*freq_per_bin;
+				tmp = (double) k * freq_per_bin + tmp * freq_per_bin;
 
 				/* store magnitude and true frequency in analysis arrays */
 				ana_magn[k] = magn;
@@ -352,10 +360,10 @@
 
 			/* ***************** PROCESSING ******************* */
 			/* this does the actual pitch shifting */
-			memset(sys_magn, 0, fft_frame_size*sizeof(float));
-			memset(syn_freq, 0, fft_frame_size*sizeof(float));
+			memset(sys_magn, 0, fft_frame_size * sizeof(float));
+			memset(syn_freq, 0, fft_frame_size * sizeof(float));
 			for (k = 0; k <= fft_frame_size2; k++) {
-				index = k*pitchShift;
+				index = k * pitchShift;
 				if (index <= fft_frame_size2) {
 					sys_magn[index] += ana_magn[k];
 					syn_freq[index] = ana_freq[k] * pitchShift;
@@ -371,41 +379,41 @@
 				tmp = syn_freq[k];
 
 				/* subtract bin mid frequency */
-				tmp -= (double)k*freq_per_bin;
+				tmp -= (double) k * freq_per_bin;
 
 				/* get bin deviation from freq deviation */
 				tmp /= freq_per_bin;
 
 				/* take osamp into account */
-				tmp = 2.*M_PI*tmp/osamp;
+				tmp = 2. * M_PI * tmp / osamp;
 
 				/* add the overlap phase advance back in */
-				tmp += (double)k*expct;
+				tmp += (double) k * expct;
 
 				/* accumulate delta phase to get bin phase */
 				sum_phase[k] += tmp;
 				phase = sum_phase[k];
 
 				/* get real and imag part and re-interleave */
-				fft_worksp[2*k] = magn*cos(phase);
-				fft_worksp[2*k+1] = magn*sin(phase);
+				fft_worksp[2*k] = magn * cos(phase);
+				fft_worksp[2*k+1] = magn * sin(phase);
 			}
 
 			/* zero negative frequencies */
-			for (k = fft_frame_size+2; k < 2*fft_frame_size; k++) fft_worksp[k] = 0.;
+			for (k = fft_frame_size + 2; k < 2 * fft_frame_size; k++) fft_worksp[k] = 0.;
 
 			/* do inverse transform */
 			smb_fft(fft_worksp, fft_frame_size, 1);
 
 			/* do windowing and add to output accumulator */
-			for(k=0; k < fft_frame_size; k++) {
-				window = -.5*cos(2.*M_PI*(double)k/(double)fft_frame_size)+.5;
-				output_accum[k] += 2.*window*fft_worksp[2*k]/(fft_frame_size2*osamp);
+			for (k=0; k < fft_frame_size; k++) {
+				window = -.5 * cos(2. * M_PI * (double) k / (double) fft_frame_size) + .5;
+				output_accum[k] += 2. * window * fft_worksp[2*k] / (fft_frame_size2 * osamp);
 			}
 			for (k = 0; k < step_size; k++) out_fifo[k] = output_accum[k];
 
 			/* shift accumulator */
-			memmove(output_accum, output_accum+step_size, fft_frame_size*sizeof(float));
+			memmove(output_accum, output_accum+step_size, fft_frame_size * sizeof(float));
 
 			/* move input FIFO */
 			for (k = 0; k < in_fifo_latency; k++) in_fifo[k] = in_fifo[k+step_size];
@@ -419,7 +427,7 @@
 	int samples;
 
 	/* an amount of 1 has no effect */
-	if (amount == 1) {
+	if (!amount || amount == 1 || !fun) {
 		return 0;
 	}
 	for (samples = 0; samples < f->samples; samples += 32) {




More information about the svn-commits mailing list