| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (I)RDFT transforms | 2 * (I)RDFT transforms |
| 3 * Copyright (c) 2009 Alex Converse <alex dot converse at gmail dot com> | 3 * Copyright (c) 2009 Alex Converse <alex dot converse at gmail dot com> |
| 4 * | 4 * |
| 5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
| 6 * | 6 * |
| 7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * FFmpeg is distributed in the hope that it will be useful, | 12 * FFmpeg is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Lesser General Public License for more details. | 15 * Lesser General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Lesser General Public | 17 * You should have received a copy of the GNU Lesser General Public |
| 18 * License along with FFmpeg; if not, write to the Free Software | 18 * License along with FFmpeg; if not, write to the Free Software |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 */ | 20 */ |
| 21 #include <math.h> | 21 #include <math.h> |
| 22 #include "dsputil.h" | 22 #include "libavutil/mathematics.h" |
| 23 #include "fft.h" |
| 23 | 24 |
| 24 /** | 25 /** |
| 25 * @file libavcodec/rdft.c | 26 * @file libavcodec/rdft.c |
| 26 * (Inverse) Real Discrete Fourier Transforms. | 27 * (Inverse) Real Discrete Fourier Transforms. |
| 27 */ | 28 */ |
| 28 | 29 |
| 29 /* sin(2*pi*x/n) for 0<=x<n/4, followed by n/2<=x<3n/4 */ | 30 /* sin(2*pi*x/n) for 0<=x<n/4, followed by n/2<=x<3n/4 */ |
| 30 #if !CONFIG_HARDCODED_TABLES | 31 #if !CONFIG_HARDCODED_TABLES |
| 31 SINTABLE(16); | 32 SINTABLE(16); |
| 32 SINTABLE(32); | 33 SINTABLE(32); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 45 SINTABLE_CONST FFTSample * const ff_sin_tabs[] = { | 46 SINTABLE_CONST FFTSample * const ff_sin_tabs[] = { |
| 46 NULL, NULL, NULL, NULL, | 47 NULL, NULL, NULL, NULL, |
| 47 ff_sin_16, ff_sin_32, ff_sin_64, ff_sin_128, ff_sin_256, ff_sin_512, ff_sin_
1024, | 48 ff_sin_16, ff_sin_32, ff_sin_64, ff_sin_128, ff_sin_256, ff_sin_512, ff_sin_
1024, |
| 48 ff_sin_2048, ff_sin_4096, ff_sin_8192, ff_sin_16384, ff_sin_32768, ff_sin_65
536, | 49 ff_sin_2048, ff_sin_4096, ff_sin_8192, ff_sin_16384, ff_sin_32768, ff_sin_65
536, |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans) | 52 av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans) |
| 52 { | 53 { |
| 53 int n = 1 << nbits; | 54 int n = 1 << nbits; |
| 54 int i; | 55 int i; |
| 55 const double theta = (trans == RDFT || trans == IRIDFT ? -1 : 1)*2*M_PI/n; | 56 const double theta = (trans == DFT_R2C || trans == DFT_C2R ? -1 : 1)*2*M_PI/
n; |
| 56 | 57 |
| 57 s->nbits = nbits; | 58 s->nbits = nbits; |
| 58 s->inverse = trans == IRDFT || trans == IRIDFT; | 59 s->inverse = trans == IDFT_C2R || trans == DFT_C2R; |
| 59 s->sign_convention = trans == RIDFT || trans == IRIDFT ? 1 : -1; | 60 s->sign_convention = trans == IDFT_R2C || trans == DFT_C2R ? 1 : -1; |
| 60 | 61 |
| 61 if (nbits < 4 || nbits > 16) | 62 if (nbits < 4 || nbits > 16) |
| 62 return -1; | 63 return -1; |
| 63 | 64 |
| 64 if (ff_fft_init(&s->fft, nbits-1, trans == IRDFT || trans == RIDFT) < 0) | 65 if (ff_fft_init(&s->fft, nbits-1, trans == IDFT_C2R || trans == IDFT_R2C) <
0) |
| 65 return -1; | 66 return -1; |
| 66 | 67 |
| 67 ff_init_ff_cos_tabs(nbits); | 68 ff_init_ff_cos_tabs(nbits); |
| 68 s->tcos = ff_cos_tabs[nbits]; | 69 s->tcos = ff_cos_tabs[nbits]; |
| 69 s->tsin = ff_sin_tabs[nbits]+(trans == RDFT || trans == IRIDFT)*(n>>2); | 70 s->tsin = ff_sin_tabs[nbits]+(trans == DFT_R2C || trans == DFT_C2R)*(n>>2); |
| 70 #if !CONFIG_HARDCODED_TABLES | 71 #if !CONFIG_HARDCODED_TABLES |
| 71 for (i = 0; i < (n>>2); i++) { | 72 for (i = 0; i < (n>>2); i++) { |
| 72 s->tsin[i] = sin(i*theta); | 73 s->tsin[i] = sin(i*theta); |
| 73 } | 74 } |
| 74 #endif | 75 #endif |
| 75 return 0; | 76 return 0; |
| 76 } | 77 } |
| 77 | 78 |
| 78 /** Map one real FFT into two parallel real even and odd FFTs. Then interleave | 79 /** Map one real FFT into two parallel real even and odd FFTs. Then interleave |
| 79 * the two real FFTs into one complex FFT. Unmangle the results. | 80 * the two real FFTs into one complex FFT. Unmangle the results. |
| 80 * ref: http://www.engineeringproductivitytools.com/stuff/T0001/PT10.HTM | 81 * ref: http://www.engineeringproductivitytools.com/stuff/T0001/PT10.HTM |
| 81 */ | 82 */ |
| 82 void ff_rdft_calc_c(RDFTContext* s, FFTSample* data) | 83 static void ff_rdft_calc_c(RDFTContext* s, FFTSample* data) |
| 83 { | 84 { |
| 84 int i, i1, i2; | 85 int i, i1, i2; |
| 85 FFTComplex ev, od; | 86 FFTComplex ev, od; |
| 86 const int n = 1 << s->nbits; | 87 const int n = 1 << s->nbits; |
| 87 const float k1 = 0.5; | 88 const float k1 = 0.5; |
| 88 const float k2 = 0.5 - s->inverse; | 89 const float k2 = 0.5 - s->inverse; |
| 89 const FFTSample *tcos = s->tcos; | 90 const FFTSample *tcos = s->tcos; |
| 90 const FFTSample *tsin = s->tsin; | 91 const FFTSample *tsin = s->tsin; |
| 91 | 92 |
| 92 if (!s->inverse) { | 93 if (!s->inverse) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 123 | 124 |
| 124 void ff_rdft_calc(RDFTContext *s, FFTSample *data) | 125 void ff_rdft_calc(RDFTContext *s, FFTSample *data) |
| 125 { | 126 { |
| 126 ff_rdft_calc_c(s, data); | 127 ff_rdft_calc_c(s, data); |
| 127 } | 128 } |
| 128 | 129 |
| 129 av_cold void ff_rdft_end(RDFTContext *s) | 130 av_cold void ff_rdft_end(RDFTContext *s) |
| 130 { | 131 { |
| 131 ff_fft_end(&s->fft); | 132 ff_fft_end(&s->fft); |
| 132 } | 133 } |
| OLD | NEW |