forked from len0rd/rockbox
FFT plugin: eliminate 64-bit math. This should result in faster and probably more accurate calculations.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25790 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
7f9d30ba3e
commit
af466f3cbf
3 changed files with 21 additions and 23 deletions
|
@ -1,4 +1,3 @@
|
||||||
kiss_fft.c
|
kiss_fft.c
|
||||||
kiss_fftr.c
|
kiss_fftr.c
|
||||||
fft.c
|
fft.c
|
||||||
math.c
|
|
||||||
|
|
|
@ -307,8 +307,8 @@ struct {
|
||||||
/************************* End of globals *************************/
|
/************************* End of globals *************************/
|
||||||
|
|
||||||
/************************* Math functions *************************/
|
/************************* Math functions *************************/
|
||||||
#define QLOG_MAX 286286
|
#define QLOG_MAX 0x00040000
|
||||||
#define QLIN_MAX 1534588906
|
#define QLIN_MAX 0x5B000000
|
||||||
#define QLN_10 float_q16(2.302585093)
|
#define QLN_10 float_q16(2.302585093)
|
||||||
#define LIN_MAX (QLIN_MAX >> 16)
|
#define LIN_MAX (QLIN_MAX >> 16)
|
||||||
|
|
||||||
|
@ -350,24 +350,31 @@ void apply_window_func(char mode)
|
||||||
/* Calculates the magnitudes from complex numbers and returns the maximum */
|
/* Calculates the magnitudes from complex numbers and returns the maximum */
|
||||||
int32_t calc_magnitudes(bool logarithmic)
|
int32_t calc_magnitudes(bool logarithmic)
|
||||||
{
|
{
|
||||||
int64_t tmp;
|
/* A major assumption made when calculating the Q*MAX constants
|
||||||
|
* is that the maximum magnitude is 29 bits long. */
|
||||||
|
|
||||||
|
uint32_t tmp;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
int32_t max = -2147483647;
|
int32_t max = 0;
|
||||||
|
|
||||||
/* Calculate the magnitude, discarding the phase.
|
/* Calculate the magnitude, discarding the phase. */
|
||||||
* The sum of the squares can easily overflow the 15-bit (s15.16)
|
|
||||||
* requirement for fsqrt, so we scale the data down */
|
|
||||||
for (i = 0; i < ARRAYSIZE_PLOT; ++i)
|
for (i = 0; i < ARRAYSIZE_PLOT; ++i)
|
||||||
{
|
{
|
||||||
tmp = output[i].r * output[i].r + output[i].i * output[i].i;
|
tmp = output[i].r * output[i].r + output[i].i * output[i].i;
|
||||||
|
|
||||||
|
if (tmp > 0x7FFFFFFF) tmp >>= 1; /* if our assumptions are correct,
|
||||||
|
this should never happen. It's just
|
||||||
|
a safeguard. */
|
||||||
|
if (tmp > 0)
|
||||||
|
{
|
||||||
|
tmp = fp_sqrt(tmp, 0); /* linear scaling, nothing
|
||||||
|
bad should happen */
|
||||||
tmp <<= 16;
|
tmp <<= 16;
|
||||||
|
|
||||||
tmp = fsqrt64(tmp, 16);
|
|
||||||
|
|
||||||
if (logarithmic)
|
if (logarithmic)
|
||||||
tmp = get_log_value(tmp & 0x7FFFFFFF);
|
tmp = get_log_value(tmp);/* the log function
|
||||||
|
expects s15.16 values */
|
||||||
|
}
|
||||||
plot[i] = tmp;
|
plot[i] = tmp;
|
||||||
|
|
||||||
if (plot[i] > max)
|
if (plot[i] > max)
|
||||||
|
|
|
@ -17,12 +17,4 @@
|
||||||
#define float_q15(a) float_q(a, 15)
|
#define float_q15(a) float_q(a, 15)
|
||||||
#define float_q16(a) float_q(a, 16)
|
#define float_q16(a) float_q(a, 16)
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixed point square root via Newton-Raphson.
|
|
||||||
* @param a square root argument.
|
|
||||||
* @param fracbits specifies number of fractional bits in argument.
|
|
||||||
* @return Square root of argument in same fixed point format as input.
|
|
||||||
*/
|
|
||||||
int64_t fsqrt64(int64_t a, unsigned int fracbits);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue