summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/fft.h
blob: a278b50a8c83273193d1f063291ae2cc8a192bc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// license:BSD-3-Clause
// copyright-holders:Justin Frankel
/*
	WDL - fft.h
	Copyright (C) 2006 and later Cockos Incorporated

	This software is provided 'as-is', without any express or implied
	warranty.  In no event will the authors be held liable for any damages
	arising from the use of this software.

	Permission is granted to anyone to use this software for any purpose,
	including commercial applications, and to alter it and redistribute it
	freely, subject to the following restrictions:

	1. The origin of this software must not be misrepresented; you must not
       claim that you wrote the original software. If you use this software
	   in a product, an acknowledgment in the product documentation would be
	   appreciated but is not required.
	2. Altered source versions must be plainly marked as such, and must not be
	   misrepresented as being the original software.
	3. This notice may not be removed or altered from any source distribution.



	This file defines the interface to the WDL FFT library. These routines are based on the
	DJBFFT library, which are   Copyright 1999 D. J. Bernstein, djb@pobox.com

	The DJB FFT web page is:  http://cr.yp.to/djbfft.html


	This file is modified from the original; it has been reformatted for 4-space
	tabs.
*/

#ifndef WDL_FFT_H
#define WDL_FFT_H

#ifdef __cplusplus
extern "C" {
#endif

#ifndef WDL_FFT_REALSIZE
#define WDL_FFT_REALSIZE 8
#endif

#if WDL_FFT_REALSIZE == 4
typedef float WDL_FFT_REAL;
#elif WDL_FFT_REALSIZE == 8
typedef double WDL_FFT_REAL;
#else
#error invalid FFT item size
#endif

typedef struct {
	WDL_FFT_REAL re;
	WDL_FFT_REAL im;
} WDL_FFT_COMPLEX;

extern void WDL_fft_init();

extern void WDL_fft_complexmul(WDL_FFT_COMPLEX *dest, WDL_FFT_COMPLEX *src, int len);
extern void WDL_fft_complexmul2(WDL_FFT_COMPLEX *dest, WDL_FFT_COMPLEX *src, WDL_FFT_COMPLEX *src2, int len);
extern void WDL_fft_complexmul3(WDL_FFT_COMPLEX *destAdd, WDL_FFT_COMPLEX *src, WDL_FFT_COMPLEX *src2, int len);

/* Expects WDL_FFT_COMPLEX input[0..len-1] scaled by 1.0/len, returns
WDL_FFT_COMPLEX output[0..len-1] order by WDL_fft_permute(len). */
extern void WDL_fft(WDL_FFT_COMPLEX *, int len, int isInverse);

/* Expects WDL_FFT_REAL input[0..len-1] scaled by 0.5/len, returns
WDL_FFT_COMPLEX output[0..len/2-1], for len >= 4 order by
WDL_fft_permute(len/2). Note that output[len/2].re is stored in
output[0].im. */
extern void WDL_real_fft(WDL_FFT_REAL *, int len, int isInverse);

extern int WDL_fft_permute(int fftsize, int idx);
extern int *WDL_fft_permute_tab(int fftsize);

#ifdef __cplusplus
};
#endif

#endif