shithub: libsamplerate

Download patch

ref: f14fc1f0fe5d516653a0a5cd2f4ae189ff146049
parent: c13383a36ee666803c3759e96f68fc885cba3728
parent: 5003d89bbaedb986ce0d86cd8be975cea9f9609c
author: Erik de Castro Lopo <erikd@mega-nerd.com>
date: Fri Jun 15 18:16:07 EDT 2007

Merge from temp branch.

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-06-15  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
+
+    * src/*_coeffs.h
+    Change the way the coefficients are defined for improved safety.
+
+    * src/src_sinc.c
+    Adapt to the above.
+
 2007-05-24  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
 
     * src/src_sinc.c
--- a/src/fastest_coeffs.h
+++ b/src/fastest_coeffs.h
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2004, 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -31,6 +31,12 @@
 **  increment        : 128
 */
 
+static const struct fastest_coeffs_s
+{	int increment ;
+	coeff_t coeffs [2464] ;
+} fastest_coeffs =
+{	128,
+{
  8.31472372954840555082e-01,
  8.31414005540308198583e-01,
  8.31238918266223869580e-01,
@@ -2494,13 +2500,6 @@
 -3.59691078491283933177e-07,
 -2.38952398011216803052e-07,
 -1.22889677382464548894e-07,
- 0			/* Need a final zero coefficient */
-
-/*
-** Do not edit or modify anything in this comment block.
-** The arch-tag line is a file identity tag for the GNU Arch 
-** revision control system.
-**
-** arch-tag: 82d149f9-28f4-4c47-b442-77a0a2d752b4
-*/
-
+ 0.0	/* Need a final zero coefficient */
+}
+} ; /* fastest_coeffs */
--- a/src/high_qual_coeffs.h
+++ b/src/high_qual_coeffs.h
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2004, 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -31,6 +31,12 @@
 **  increment        : 128
 */
 
+static const struct high_qual_coeffs_s
+{	int increment ;
+	coeff_t coeffs [17088] ;
+} high_qual_coeffs =
+{	128,
+{
  9.73822959712628111184e-01,
  9.73730227534126968614e-01,
  9.73452062795049033461e-01,
@@ -17118,13 +17124,6 @@
 -6.22922070331324441674e-08,
 -4.33275254142092293362e-08,
 -2.44520526242285169324e-08,
- 0			/* Need a final zero coefficient */
-
-/*
-** Do not edit or modify anything in this comment block.
-** The arch-tag line is a file identity tag for the GNU Arch 
-** revision control system.
-**
-** arch-tag: e62a151f-7d00-4df6-8e18-c8032ced3be2
-*/
-
+ 0.0	/* Need a final zero coefficient */
+}
+} ; /* high_qual_coeffs */
--- a/src/mid_qual_coeffs.h
+++ b/src/mid_qual_coeffs.h
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2004, 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -31,6 +31,12 @@
 **  increment        : 128
 */
 
+static const struct mid_qual_coeffs_s
+{	int increment ;
+	coeff_t coeffs [5286] ;
+} mid_qual_coeffs =
+{	128,
+{
  9.20381425342432724079e-01,
  9.20302993473144703707e-01,
  9.20067721990720843728e-01,
@@ -5316,13 +5322,6 @@
 -1.63621651764123018711e-07,
 -1.03664673187799380991e-07,
 -4.47970746308059675830e-08,
- 0			/* Need a final zero coefficient */
-
-/*
-** Do not edit or modify anything in this comment block.
-** The arch-tag line is a file identity tag for the GNU Arch 
-** revision control system.
-**
-** arch-tag: aa7e5110-c82f-4c2f-8296-57bd4fa94766
-*/
-
+ 0.0	/* Need a final zero coefficient */
+}
+} ; /* mid_qual_coeffs */
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -37,7 +37,7 @@
 
 #define MAKE_INCREMENT_T(x) 	((increment_t) (x))
 
-#define	SHIFT_BITS				16
+#define	SHIFT_BITS				14
 #define	FP_ONE					((double) (((increment_t) 1) << SHIFT_BITS))
 #define	INV_FP_ONE				(1.0 / FP_ONE)
 
@@ -47,6 +47,10 @@
 typedef int32_t increment_t ;
 typedef float	coeff_t ;
 
+#include "high_qual_coeffs.h"
+#include "mid_qual_coeffs.h"
+#include "fastest_coeffs.h"
+
 typedef struct
 {	int		sinc_magic_marker ;
 
@@ -55,11 +59,9 @@
 	long	out_count, out_gen ;
 
 	int		coeff_half_len, index_inc ;
-	int		has_diffs ;
 
 	double	src_ratio, input_index ;
 
-	int		coeff_len ;
 	coeff_t const	*coeffs ;
 
 	int		b_current, b_end, b_real_end, b_len ;
@@ -74,22 +76,6 @@
 
 static void sinc_reset (SRC_PRIVATE *psrc) ;
 
-static coeff_t const high_qual_coeffs [] =
-{
-#include "high_qual_coeffs.h"
-} ; /* high_qual_coeffs */
-
-static coeff_t const mid_qual_coeffs [] =
-{
-#include "mid_qual_coeffs.h"
-} ; /* mid_qual_coeffs */
-
-static coeff_t const fastest_coeffs [] =
-{
-#include "fastest_coeffs.h"
-} ; /* fastest_coeffs */
-
-
 static inline increment_t
 double_to_fp (double x)
 {	if (sizeof (increment_t) == 8)
@@ -184,27 +170,21 @@
 
 	switch (src_enum)
 	{	case SRC_SINC_BEST_QUALITY :
-				temp_filter.coeffs = high_qual_coeffs ;
-				temp_filter.coeff_half_len = ARRAY_LEN (high_qual_coeffs) - 1 ;
-				temp_filter.index_inc = 128 ;
-				temp_filter.has_diffs = SRC_FALSE ;
-				temp_filter.coeff_len = ARRAY_LEN (high_qual_coeffs) ;
+				temp_filter.coeffs = high_qual_coeffs.coeffs ;
+				temp_filter.coeff_half_len = ARRAY_LEN (high_qual_coeffs.coeffs) - 1 ;
+				temp_filter.index_inc = high_qual_coeffs.increment ;
 				break ;
 
 		case SRC_SINC_MEDIUM_QUALITY :
-				temp_filter.coeffs = mid_qual_coeffs ;
-				temp_filter.coeff_half_len = ARRAY_LEN (mid_qual_coeffs) - 1 ;
-				temp_filter.index_inc = 128 ;
-				temp_filter.has_diffs = SRC_FALSE ;
-				temp_filter.coeff_len = ARRAY_LEN (mid_qual_coeffs) ;
+				temp_filter.coeffs = mid_qual_coeffs.coeffs ;
+				temp_filter.coeff_half_len = ARRAY_LEN (mid_qual_coeffs.coeffs) - 1 ;
+				temp_filter.index_inc = mid_qual_coeffs.increment ;
 				break ;
 
 		case SRC_SINC_FASTEST :
-				temp_filter.coeffs = fastest_coeffs ;
-				temp_filter.coeff_half_len = ARRAY_LEN (fastest_coeffs) - 1 ;
-				temp_filter.index_inc = 128 ;
-				temp_filter.has_diffs = SRC_FALSE ;
-				temp_filter.coeff_len = ARRAY_LEN (fastest_coeffs) ;
+				temp_filter.coeffs = fastest_coeffs.coeffs ;
+				temp_filter.coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 1 ;
+				temp_filter.index_inc = fastest_coeffs.increment ;
 				break ;
 
 		default :
@@ -216,7 +196,7 @@
 	** a better way. Need to look at prepare_data () at the same time.
 	*/
 
-	temp_filter.b_len = 1000 + 2 * lrint (0.5 + temp_filter.coeff_len / (temp_filter.index_inc * 1.0) * SRC_MAX_RATIO) ;
+	temp_filter.b_len = 1000 + 2 * lrint (0.5 + 2 * temp_filter.coeff_half_len / (temp_filter.index_inc * 1.0) * SRC_MAX_RATIO) ;
 	temp_filter.b_len = MIN (temp_filter.b_len, 4096) ;
 	temp_filter.b_len *= temp_filter.channels ;