Skip to content

Commit 7afab47

Browse files
authored
Create ffft.h
1 parent b8132b5 commit 7afab47

1 file changed

Lines changed: 229 additions & 0 deletions

File tree

  • Tiny_Music_Visualizer/ffft

Tiny_Music_Visualizer/ffft/ffft.h

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
#ifndef FFT_N
2+
#define FFT_N 128 /* Number of samples (64,128,256,512). */
3+
#endif /* FFT_N */
4+
5+
//#define INPUT_NOUSE
6+
//#define INPUT_IQ
7+
8+
#ifndef FFFT_ASM /* for c modules */
9+
10+
typedef struct _tag_complex_t {
11+
int16_t r;
12+
int16_t i;
13+
} complex_t;
14+
15+
16+
#ifndef INPUT_NOUSE
17+
#ifdef INPUT_IQ
18+
void fft_input (const complex_t *, complex_t *);
19+
#else
20+
extern "C" { void fft_input (const int16_t *, complex_t *); }
21+
#endif
22+
#endif
23+
extern "C" {
24+
void fft_execute (complex_t *);
25+
void fft_output (complex_t *, uint16_t *);
26+
int16_t fmuls_f (int16_t, int16_t);
27+
}
28+
#include <avr/pgmspace.h>
29+
extern const int16_t PROGMEM tbl_window[];
30+
31+
#else /* for asm module */
32+
33+
#define T0L r0
34+
#define T0H r1
35+
#define T2L r2
36+
#define T2H r3
37+
#define T4L r4
38+
#define T4H r5
39+
#define T6L r6
40+
#define T6H r7
41+
#define T8L r8
42+
#define T8H r9
43+
#define T10L r10
44+
#define T10H r11
45+
#define T12L r12
46+
#define T12H r13
47+
#define T14L r14
48+
#define T14H r15
49+
#define AL r16
50+
#define AH r17
51+
#define BL r18
52+
#define BH r19
53+
#define CL r20
54+
#define CH r21
55+
#define DL r22
56+
#define DH r23
57+
#define EL r24
58+
#define EH r25
59+
#define XL r26
60+
#define XH r27
61+
#define YL r28
62+
#define YH r29
63+
#define ZL r30
64+
#define ZH r31
65+
66+
.macro ldiw dh,dl, abs
67+
ldi \dl, lo8(\abs)
68+
ldi \dh, hi8(\abs)
69+
.endm
70+
71+
.macro subiw dh,dl, abs
72+
subi \dl, lo8(\abs)
73+
sbci \dh, hi8(\abs)
74+
.endm
75+
76+
.macro addw dh,dl, sh,sl
77+
add \dl, \sl
78+
adc \dh, \sh
79+
.endm
80+
81+
.macro addd d3,d2,d1,d0, s3,s2,s1,s0
82+
add \d0, \s0
83+
adc \d1, \s1
84+
adc \d2, \s2
85+
adc \d3, \s3
86+
.endm
87+
88+
.macro subw dh,dl, sh,sl
89+
sub \dl, \sl
90+
sbc \dh, \sh
91+
.endm
92+
93+
.macro subd d3,d2,d1,d0, s3,s2,s1,s0
94+
sub \d0, \s0
95+
sbc \d1, \s1
96+
sbc \d2, \s2
97+
sbc \d3, \s3
98+
.endm
99+
100+
.macro lddw dh,dl, src
101+
ldd \dl, \src
102+
ldd \dh, \src+1
103+
.endm
104+
105+
.macro ldw dh,dl, src
106+
ld \dl, \src
107+
ld \dh, \src
108+
.endm
109+
110+
.macro stw dst, sh,sl
111+
st \dst, \sl
112+
st \dst, \sh
113+
.endm
114+
115+
.macro clrw dh, dl
116+
clr \dh
117+
clr \dl
118+
.endm
119+
120+
.macro lsrw dh, dl
121+
lsr \dh
122+
ror \dl
123+
.endm
124+
125+
.macro asrw dh, dl
126+
asr \dh
127+
ror \dl
128+
.endm
129+
130+
.macro lslw dh, dl
131+
lsl \dl
132+
rol \dh
133+
.endm
134+
135+
.macro pushw dh, dl
136+
push \dh
137+
push \dl
138+
.endm
139+
140+
.macro popw dh, dl
141+
pop \dl
142+
pop \dh
143+
.endm
144+
145+
.macro lpmw dh,dl, src
146+
lpm \dl, \src
147+
lpm \dh, \src
148+
.endm
149+
150+
.macro rjne lbl
151+
breq 99f
152+
rjmp \lbl
153+
99:
154+
.endm
155+
156+
157+
.macro FMULS16 d3,d2,d1,d0 ,s1h,s1l, s2h,s2l ;Fractional Multiply (19clk)
158+
fmuls \s1h, \s2h
159+
movw \d2, T0L
160+
fmul \s1l, \s2l
161+
movw \d0, T0L
162+
adc \d2, EH ;EH: zero reg.
163+
fmulsu \s1h, \s2l
164+
sbc \d3, EH
165+
add \d1, T0L
166+
adc \d2, T0H
167+
adc \d3, EH
168+
fmulsu \s2h, \s1l
169+
sbc \d3, EH
170+
add \d1, T0L
171+
adc \d2, T0H
172+
adc \d3, EH
173+
.endm
174+
175+
176+
.macro SQRT32 ; 32bit square root (526..542clk)
177+
clr T6L
178+
clr T6H
179+
clr T8L
180+
clr T8H
181+
ldi BL, 1
182+
ldi BH, 0
183+
clr CL
184+
clr CH
185+
ldi DH, 16
186+
90: lsl T2L
187+
rol T2H
188+
rol T4L
189+
rol T4H
190+
rol T6L
191+
rol T6H
192+
rol T8L
193+
rol T8H
194+
lsl T2L
195+
rol T2H
196+
rol T4L
197+
rol T4H
198+
rol T6L
199+
rol T6H
200+
rol T8L
201+
rol T8H
202+
brpl 91f
203+
add T6L, BL
204+
adc T6H, BH
205+
adc T8L, CL
206+
adc T8H, CH
207+
rjmp 92f
208+
91: sub T6L, BL
209+
sbc T6H, BH
210+
sbc T8L, CL
211+
sbc T8H, CH
212+
92: lsl BL
213+
rol BH
214+
rol CL
215+
andi BL, 0b11111000
216+
ori BL, 0b00000101
217+
sbrc T8H, 7
218+
subi BL, 2
219+
dec DH
220+
brne 90b
221+
lsr CL
222+
ror BH
223+
ror BL
224+
lsr CL
225+
ror BH
226+
ror BL
227+
.endm
228+
229+
#endif /* FFFT_ASM */

0 commit comments

Comments
 (0)