shithub: libsamplerate

Download patch

ref: 18106d3bc0e0795a4a91d63e0c6fbdc8efd9e201
parent: 3ab82169d817d566a9f295b2d388e583431fc2fe
author: Erik de Castro Lopo <erikd@miles>
date: Mon Nov 1 15:35:12 EST 2004

Add log magnitude calculations.

--- a/FIR-POLY/fir_interp.cc
+++ b/FIR-POLY/fir_interp.cc
@@ -69,6 +69,7 @@
 	double window [2048] ;
 	double filter [2048] ;
 	double mag [1024] ;
+	double logmag [1024] ;
 	double phase [1024] ;
 } FIR_INTERP ;
 
@@ -128,7 +129,7 @@
 static double
 evaluate_filter (FIR_INTERP *interp)
 {
-	mag_spectrum (interp->filter, ARRAY_LEN (interp->filter), interp->mag, interp->phase) ;
+	mag_spectrum (interp->filter, ARRAY_LEN (interp->filter), interp->mag, interp->logmag, interp->phase) ;
 
 	return 1.0 ;
 } /* evaluate_filter */
@@ -359,6 +360,14 @@
 
 	for (k = 0 ; k < ARRAY_LEN (interp->mag) ; k++)
 		fprintf (file, "% f\n", interp->mag [k]) ;
+
+	fprintf (file, "# name: logmag\n") ;
+	fprintf (file, "# type: matrix\n") ;
+	fprintf (file, "# rows: %d\n", ARRAY_LEN (interp->logmag)) ;
+	fprintf (file, "# columns: 1\n") ;
+
+	for (k = 0 ; k < ARRAY_LEN (interp->logmag) ; k++)
+		fprintf (file, "% f\n", interp->logmag [k]) ;
 
 	fprintf (file, "# name: phase\n") ;
 	fprintf (file, "# type: matrix\n") ;
--- a/FIR-POLY/mag_spectrum.cc
+++ b/FIR-POLY/mag_spectrum.cc
@@ -26,7 +26,7 @@
 #include <fftw3.h>
 
 void
-mag_spectrum (double *input, int len, double *magnitude, double *phase)
+mag_spectrum (double *input, int len, double *magnitude, double *logmag, double *phase)
 {	static fftw_plan plan = NULL ;
 	static int saved_len = -1 ;
 	static double *fft_data = NULL ;
@@ -61,6 +61,7 @@
 	maxval = 0.0 ;
 	for (k = 0 ; k < len / 2 ; k++)
 	{	magnitude [k] = sqrt (fft_data [k] * fft_data [k] + fft_data [len - k - 1] * fft_data [len - k - 1]) ;
+		logmag [k] = (magnitude [k] < 1e-10) ? -200.0 : 20 * log10 (magnitude [k]) ;
 		phase [k] = atan2 (fft_data [len - k - 1], fft_data [k]) ;
 		} ;
 
--- a/FIR-POLY/mag_spectrum.hh
+++ b/FIR-POLY/mag_spectrum.hh
@@ -18,7 +18,7 @@
 ** written permission of Erik de Castro Lopo.
 */
 
-void mag_spectrum (double *input, int len, double *magnitude, double *phase) ;
+void mag_spectrum (double *input, int len, double *magnitude, double *logmag, double *phase) ;
 
 // Do not edit or modify anything in this comment block.
 // The following line is a file identity tag for the GNU Arch