Unified · Split
| @@ -1,3 +1,11 @@ | |||
| 1 | 2007-06-15 Erik de Castro Lopo <erikd AT mega-nerd DOT com> | ||
| 2 | |||
| 3 | * src/*_coeffs.h | ||
| 4 | Change the way the coefficients are defined for improved safety. | ||
| 5 | |||
| 6 | * src/src_sinc.c | ||
| 7 | Adapt to the above. | ||
| 8 | |||
| 1 | 2007-05-24 Erik de Castro Lopo <erikd AT mega-nerd DOT com> | 9 | 2007-05-24 Erik de Castro Lopo <erikd AT mega-nerd DOT com> |
| 2 | 10 | ||
| 3 | * src/src_sinc.c | 11 | * src/src_sinc.c |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com> | 2 | ** Copyright (C) 2002-2004, 2007 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 3 | ** | 3 | ** |
| 4 | ** This program is free software; you can redistribute it and/or modify | 4 | ** This program is free software; you can redistribute it and/or modify |
| 5 | ** it under the terms of the GNU General Public License as published by | 5 | ** it under the terms of the GNU General Public License as published by |
| @@ -31,6 +31,12 @@ · 25 unmodified lines | |||
| 31 | ** increment : 128 | 31 | ** increment : 128 |
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | static const struct fastest_coeffs_s | ||
| 35 | { int increment ; | ||
| 36 | coeff_t coeffs [2464] ; | ||
| 37 | } fastest_coeffs = | ||
| 38 | { 128, | ||
| 39 | { | ||
| 34 | 8.31472372954840555082e-01, | 40 | 8.31472372954840555082e-01, |
| 35 | 8.31414005540308198583e-01, | 41 | 8.31414005540308198583e-01, |
| 36 | 8.31238918266223869580e-01, | 42 | 8.31238918266223869580e-01, |
| @@ -2494,13 +2500,6 @@ · 2457 unmodified lines | |||
| 2494 | -3.59691078491283933177e-07, | 2500 | -3.59691078491283933177e-07, |
| 2495 | -2.38952398011216803052e-07, | 2501 | -2.38952398011216803052e-07, |
| 2496 | -1.22889677382464548894e-07, | 2502 | -1.22889677382464548894e-07, |
| 2497 | 0 /* Need a final zero coefficient */ | 2503 | 0.0 /* Need a final zero coefficient */ |
| 2498 | 2504 | } | |
| 2499 | /* | 2505 | } ; /* fastest_coeffs */ |
| 2500 | ** Do not edit or modify anything in this comment block. | ||
| 2501 | ** The arch-tag line is a file identity tag for the GNU Arch | ||
| 2502 | ** revision control system. | ||
| 2503 | ** | ||
| 2504 | ** arch-tag: 82d149f9-28f4-4c47-b442-77a0a2d752b4 | ||
| 2505 | */ | ||
| 2506 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com> | 2 | ** Copyright (C) 2002-2004, 2007 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 3 | ** | 3 | ** |
| 4 | ** This program is free software; you can redistribute it and/or modify | 4 | ** This program is free software; you can redistribute it and/or modify |
| 5 | ** it under the terms of the GNU General Public License as published by | 5 | ** it under the terms of the GNU General Public License as published by |
| @@ -31,6 +31,12 @@ · 25 unmodified lines | |||
| 31 | ** increment : 128 | 31 | ** increment : 128 |
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | static const struct high_qual_coeffs_s | ||
| 35 | { int increment ; | ||
| 36 | coeff_t coeffs [17088] ; | ||
| 37 | } high_qual_coeffs = | ||
| 38 | { 128, | ||
| 39 | { | ||
| 34 | 9.73822959712628111184e-01, | 40 | 9.73822959712628111184e-01, |
| 35 | 9.73730227534126968614e-01, | 41 | 9.73730227534126968614e-01, |
| 36 | 9.73452062795049033461e-01, | 42 | 9.73452062795049033461e-01, |
| @@ -17118,13 +17124,6 @@ · 17081 unmodified lines | |||
| 17118 | -6.22922070331324441674e-08, | 17124 | -6.22922070331324441674e-08, |
| 17119 | -4.33275254142092293362e-08, | 17125 | -4.33275254142092293362e-08, |
| 17120 | -2.44520526242285169324e-08, | 17126 | -2.44520526242285169324e-08, |
| 17121 | 0 /* Need a final zero coefficient */ | 17127 | 0.0 /* Need a final zero coefficient */ |
| 17122 | 17128 | } | |
| 17123 | /* | 17129 | } ; /* high_qual_coeffs */ |
| 17124 | ** Do not edit or modify anything in this comment block. | ||
| 17125 | ** The arch-tag line is a file identity tag for the GNU Arch | ||
| 17126 | ** revision control system. | ||
| 17127 | ** | ||
| 17128 | ** arch-tag: e62a151f-7d00-4df6-8e18-c8032ced3be2 | ||
| 17129 | */ | ||
| 17130 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com> | 2 | ** Copyright (C) 2002-2004, 2007 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 3 | ** | 3 | ** |
| 4 | ** This program is free software; you can redistribute it and/or modify | 4 | ** This program is free software; you can redistribute it and/or modify |
| 5 | ** it under the terms of the GNU General Public License as published by | 5 | ** it under the terms of the GNU General Public License as published by |
| @@ -31,6 +31,12 @@ · 25 unmodified lines | |||
| 31 | ** increment : 128 | 31 | ** increment : 128 |
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | static const struct mid_qual_coeffs_s | ||
| 35 | { int increment ; | ||
| 36 | coeff_t coeffs [5286] ; | ||
| 37 | } mid_qual_coeffs = | ||
| 38 | { 128, | ||
| 39 | { | ||
| 34 | 9.20381425342432724079e-01, | 40 | 9.20381425342432724079e-01, |
| 35 | 9.20302993473144703707e-01, | 41 | 9.20302993473144703707e-01, |
| 36 | 9.20067721990720843728e-01, | 42 | 9.20067721990720843728e-01, |
| @@ -5316,13 +5322,6 @@ · 5279 unmodified lines | |||
| 5316 | -1.63621651764123018711e-07, | 5322 | -1.63621651764123018711e-07, |
| 5317 | -1.03664673187799380991e-07, | 5323 | -1.03664673187799380991e-07, |
| 5318 | -4.47970746308059675830e-08, | 5324 | -4.47970746308059675830e-08, |
| 5319 | 0 /* Need a final zero coefficient */ | 5325 | 0.0 /* Need a final zero coefficient */ |
| 5320 | 5326 | } | |
| 5321 | /* | 5327 | } ; /* mid_qual_coeffs */ |
| 5322 | ** Do not edit or modify anything in this comment block. | ||
| 5323 | ** The arch-tag line is a file identity tag for the GNU Arch | ||
| 5324 | ** revision control system. | ||
| 5325 | ** | ||
| 5326 | ** arch-tag: aa7e5110-c82f-4c2f-8296-57bd4fa94766 | ||
| 5327 | */ | ||
| 5328 | |||
| @@ -37,7 +37,7 @@ · 36 unmodified lines | |||
| 37 | 37 | ||
| 38 | #define MAKE_INCREMENT_T(x) ((increment_t) (x)) | 38 | #define MAKE_INCREMENT_T(x) ((increment_t) (x)) |
| 39 | 39 | ||
| 40 | #define SHIFT_BITS 16 | 40 | #define SHIFT_BITS 14 |
| 41 | #define FP_ONE ((double) (((increment_t) 1) << SHIFT_BITS)) | 41 | #define FP_ONE ((double) (((increment_t) 1) << SHIFT_BITS)) |
| 42 | #define INV_FP_ONE (1.0 / FP_ONE) | 42 | #define INV_FP_ONE (1.0 / FP_ONE) |
| 43 | 43 | ||
| @@ -47,6 +47,10 @@ · 3 unmodified lines | |||
| 47 | typedef int32_t increment_t ; | 47 | typedef int32_t increment_t ; |
| 48 | typedef float coeff_t ; | 48 | typedef float coeff_t ; |
| 49 | 49 | ||
| 50 | #include "high_qual_coeffs.h" | ||
| 51 | #include "mid_qual_coeffs.h" | ||
| 52 | #include "fastest_coeffs.h" | ||
| 53 | |||
| 50 | typedef struct | 54 | typedef struct |
| 51 | { int sinc_magic_marker ; | 55 | { int sinc_magic_marker ; |
| 52 | 56 | ||
| @@ -55,11 +59,9 @@ typedef struct · 2 unmodified lines | |||
| 55 | long out_count, out_gen ; | 59 | long out_count, out_gen ; |
| 56 | 60 | ||
| 57 | int coeff_half_len, index_inc ; | 61 | int coeff_half_len, index_inc ; |
| 58 | int has_diffs ; | ||
| 59 | 62 | ||
| 60 | double src_ratio, input_index ; | 63 | double src_ratio, input_index ; |
| 61 | 64 | ||
| 62 | int coeff_len ; | ||
| 63 | coeff_t const *coeffs ; | 65 | coeff_t const *coeffs ; |
| 64 | 66 | ||
| 65 | int b_current, b_end, b_real_end, b_len ; | 67 | int b_current, b_end, b_real_end, b_len ; |
| @@ -74,22 +76,6 @@ static void prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_c · 8 unmodified lines | |||
| 74 | 76 | ||
| 75 | static void sinc_reset (SRC_PRIVATE *psrc) ; | 77 | static void sinc_reset (SRC_PRIVATE *psrc) ; |
| 76 | 78 | ||
| 77 | static coeff_t const high_qual_coeffs [] = | ||
| 78 | { | ||
| 79 | #include "high_qual_coeffs.h" | ||
| 80 | } ; /* high_qual_coeffs */ | ||
| 81 | |||
| 82 | static coeff_t const mid_qual_coeffs [] = | ||
| 83 | { | ||
| 84 | #include "mid_qual_coeffs.h" | ||
| 85 | } ; /* mid_qual_coeffs */ | ||
| 86 | |||
| 87 | static coeff_t const fastest_coeffs [] = | ||
| 88 | { | ||
| 89 | #include "fastest_coeffs.h" | ||
| 90 | } ; /* fastest_coeffs */ | ||
| 91 | |||
| 92 | |||
| 93 | static inline increment_t | 79 | static inline increment_t |
| 94 | double_to_fp (double x) | 80 | double_to_fp (double x) |
| 95 | { if (sizeof (increment_t) == 8) | 81 | { if (sizeof (increment_t) == 8) |
| @@ -184,27 +170,21 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) · 88 unmodified lines | |||
| 184 | 170 | ||
| 185 | switch (src_enum) | 171 | switch (src_enum) |
| 186 | { case SRC_SINC_BEST_QUALITY : | 172 | { case SRC_SINC_BEST_QUALITY : |
| 187 | temp_filter.coeffs = high_qual_coeffs ; | 173 | temp_filter.coeffs = high_qual_coeffs.coeffs ; |
| 188 | temp_filter.coeff_half_len = ARRAY_LEN (high_qual_coeffs) - 1 ; | 174 | temp_filter.coeff_half_len = ARRAY_LEN (high_qual_coeffs.coeffs) - 1 ; |
| 189 | temp_filter.index_inc = 128 ; | 175 | temp_filter.index_inc = high_qual_coeffs.increment ; |
| 190 | temp_filter.has_diffs = SRC_FALSE ; | ||
| 191 | temp_filter.coeff_len = ARRAY_LEN (high_qual_coeffs) ; | ||
| 192 | break ; | 176 | break ; |
| 193 | 177 | ||
| 194 | case SRC_SINC_MEDIUM_QUALITY : | 178 | case SRC_SINC_MEDIUM_QUALITY : |
| 195 | temp_filter.coeffs = mid_qual_coeffs ; | 179 | temp_filter.coeffs = mid_qual_coeffs.coeffs ; |
| 196 | temp_filter.coeff_half_len = ARRAY_LEN (mid_qual_coeffs) - 1 ; | 180 | temp_filter.coeff_half_len = ARRAY_LEN (mid_qual_coeffs.coeffs) - 1 ; |
| 197 | temp_filter.index_inc = 128 ; | 181 | temp_filter.index_inc = mid_qual_coeffs.increment ; |
| 198 | temp_filter.has_diffs = SRC_FALSE ; | ||
| 199 | temp_filter.coeff_len = ARRAY_LEN (mid_qual_coeffs) ; | ||
| 200 | break ; | 182 | break ; |
| 201 | 183 | ||
| 202 | case SRC_SINC_FASTEST : | 184 | case SRC_SINC_FASTEST : |
| 203 | temp_filter.coeffs = fastest_coeffs ; | 185 | temp_filter.coeffs = fastest_coeffs.coeffs ; |
| 204 | temp_filter.coeff_half_len = ARRAY_LEN (fastest_coeffs) - 1 ; | 186 | temp_filter.coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 1 ; |
| 205 | temp_filter.index_inc = 128 ; | 187 | temp_filter.index_inc = fastest_coeffs.increment ; |
| 206 | temp_filter.has_diffs = SRC_FALSE ; | ||
| 207 | temp_filter.coeff_len = ARRAY_LEN (fastest_coeffs) ; | ||
| 208 | break ; | 188 | break ; |
| 209 | 189 | ||
| 210 | default : | 190 | default : |
| @@ -216,7 +196,7 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) · 5 unmodified lines | |||
| 216 | ** a better way. Need to look at prepare_data () at the same time. | 196 | ** a better way. Need to look at prepare_data () at the same time. |
| 217 | */ | 197 | */ |
| 218 | 198 | ||
| 219 | temp_filter.b_len = 1000 + 2 * lrint (0.5 + temp_filter.coeff_len / (temp_filter.index_inc * 1.0) * SRC_MAX_RATIO) ; | 199 | temp_filter.b_len = 1000 + 2 * lrint (0.5 + 2 * temp_filter.coeff_half_len / (temp_filter.index_inc * 1.0) * SRC_MAX_RATIO) ; |
| 220 | temp_filter.b_len = MIN (temp_filter.b_len, 4096) ; | 200 | temp_filter.b_len = MIN (temp_filter.b_len, 4096) ; |
| 221 | temp_filter.b_len *= temp_filter.channels ; | 201 | temp_filter.b_len *= temp_filter.channels ; |
| 222 | 202 | ||