Skip to content

Commit cfd3a34

Browse files
committed
split rfft/rifft C impl; tables in init
1 parent c0e218b commit cfd3a34

9 files changed

Lines changed: 104 additions & 177 deletions

File tree

hvcc/core/hv2ir/HIrRFFT.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ def __init__(
3737
def reduce(self) -> Optional[tuple]:
3838
if self.graph is not None:
3939
self.args["block_size"] = self.graph.args["block_size"]
40-
table_obj = self.graph.resolve_object_for_name(
41-
self.args["table"],
42-
["table", "__table"])
43-
if table_obj is not None:
44-
self.args["table_id"] = table_obj.id
45-
return ({self}, [])
46-
else:
47-
self.add_error(f"Cannot find table named \"{self.args['table']}\" for object {self}.")
40+
return ({self}, [])
4841

4942
return None

hvcc/core/hv2ir/HeavyParser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def graph_from_object(
115115
"""
116116
# resolve default graph arguments
117117
graph_args = graph_args or {}
118-
if(json_heavy["block_size"] is not None):
118+
if json_heavy["block_size"] is not None:
119119
graph_args["block_size"] = int(json_heavy["block_size"])
120120
for a in json_heavy["args"]:
121121
if a["name"] not in graph_args:

hvcc/core/json/heavy.ir.json

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,9 +2273,7 @@
22732273
},
22742274
"__rfft~f": {
22752275
"inlets": [
2276-
"~f>",
2277-
"-->",
2278-
"-->"
2276+
"~f>"
22792277
],
22802278
"ir": {
22812279
"control": false,
@@ -2286,13 +2284,7 @@
22862284
"~f>",
22872285
"~f>"
22882286
],
2289-
"args": [{
2290-
"name": "table",
2291-
"value_type": "string",
2292-
"description": "",
2293-
"default": "",
2294-
"required": true
2295-
}],
2287+
"args": [],
22962288
"perf": {
22972289
"avx": 0,
22982290
"sse": 0
@@ -2301,9 +2293,7 @@
23012293
"__rifft~f": {
23022294
"inlets": [
23032295
"~f>",
2304-
"~f>",
2305-
"-->",
2306-
"-->"
2296+
"~f>"
23072297
],
23082298
"ir": {
23092299
"control": false,
@@ -2313,13 +2303,7 @@
23132303
"outlets": [
23142304
"~f>"
23152305
],
2316-
"args": [{
2317-
"name": "table",
2318-
"value_type": "string",
2319-
"description": "",
2320-
"default": "",
2321-
"required": true
2322-
}],
2306+
"args": [],
23232307
"perf": {
23242308
"avx": 0,
23252309
"sse": 0

hvcc/generators/ir2c/SignalRFFT.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def get_C_file_set(cls) -> set:
3737
@classmethod
3838
def get_C_init(cls, obj_type: str, obj_id: str, args: Dict) -> List[str]:
3939
return [
40-
"sRFFT_init(&sRFFT_{0}, &hTable_{1}, {2});".format(
40+
"sRFFT_init(&sRFFT_{0}, {1});".format(
4141
obj_id,
42-
args["table_id"],
4342
args["block_size"])
4443
]
4544

@@ -62,9 +61,44 @@ def get_C_process(cls, process_dict: IRSignalList, obj_type: str, obj_id: str, a
6261
cls._c_buffer(process_dict.outputBuffers[1])
6362
)
6463
]
65-
elif obj_type == "__rifft~f":
64+
else:
65+
raise Exception
66+
67+
68+
class SignalRIFFT(HeavyObject):
69+
70+
c_struct = "SignalRIFFT"
71+
preamble = "sRIFFT"
72+
73+
@classmethod
74+
def get_C_header_set(cls) -> set:
75+
return {"HvSignalRFFT.h"}
76+
77+
@classmethod
78+
def get_C_file_set(cls) -> set:
79+
return {"HvSignalRFFT.h", "HvSignalRFFT.c"}
80+
81+
@classmethod
82+
def get_C_init(cls, obj_type: str, obj_id: str, args: Dict) -> List[str]:
83+
return [
84+
"sRIFFT_init(&sRIFFT_{0}, {1});".format(
85+
obj_id,
86+
args["block_size"])
87+
]
88+
89+
@classmethod
90+
def get_C_onMessage(cls, obj_type: str, obj_id: str, inlet_index: int, args: Dict) -> List[str]:
91+
return [
92+
"sRIFFT_onMessage(_c, &Context(_c)->sRFFT_{0}, {1}, m, NULL);".format(
93+
obj_id,
94+
inlet_index)
95+
]
96+
97+
@classmethod
98+
def get_C_process(cls, process_dict: IRSignalList, obj_type: str, obj_id: str, args: Dict) -> List[str]:
99+
if obj_type == "__rifft~f":
66100
return [
67-
"__hv_rifft_f(&sRFFT_{0}, VIf({1}), VIf({2}), VOf({3}));".format(
101+
"__hv_rifft_f(&sRIFFT_{0}, VIf({1}), VIf({2}), VOf({3}));".format(
68102
process_dict.id,
69103
cls._c_buffer(process_dict.inputBuffers[0]),
70104
cls._c_buffer(process_dict.inputBuffers[1]),

hvcc/generators/ir2c/ir2c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from hvcc.generators.ir2c.SignalLorenz import SignalLorenz
6060
from hvcc.generators.ir2c.SignalMath import SignalMath
6161
from hvcc.generators.ir2c.SignalPhasor import SignalPhasor
62-
from hvcc.generators.ir2c.SignalRFFT import SignalRFFT
62+
from hvcc.generators.ir2c.SignalRFFT import SignalRFFT, SignalRIFFT
6363
from hvcc.generators.ir2c.SignalRPole import SignalRPole
6464
from hvcc.generators.ir2c.SignalSample import SignalSample
6565
from hvcc.generators.ir2c.SignalSamphold import SignalSamphold
@@ -107,7 +107,7 @@ class ir2c:
107107
"__phasor~f": SignalPhasor,
108108
"__phasor_k~f": SignalPhasor,
109109
"__rfft~f": SignalRFFT,
110-
"__rifft~f": SignalRFFT,
110+
"__rifft~f": SignalRIFFT,
111111
"__sample~f": SignalSample,
112112
"__samphold~f": SignalSamphold,
113113
"__slice": ControlSlice,

hvcc/generators/ir2c/static/HvSignalRFFT.c

Lines changed: 27 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -16,109 +16,50 @@
1616

1717
#include "HvSignalRFFT.h"
1818

19-
hv_size_t sRFFT_init(SignalRFFT *o, struct HvTable *table, const int size) {
20-
o->table = table;
21-
hv_size_t numBytes = hTable_init(&o->inputs, size);
19+
hv_size_t sRFFT_init(SignalRFFT *o, const int size) {
20+
hv_size_t numBytes = hTable_init(&o->input, size);
21+
numBytes += hTable_init(&o->outputReal, size/2+1);
22+
numBytes += hTable_init(&o->outputImagin, size/2+1);
2223
return numBytes;
2324
}
2425

2526
void sRFFT_free(SignalRFFT *o) {
26-
o->table = NULL;
27-
hTable_free(&o->inputs);
27+
hTable_free(&o->input);
28+
hTable_free(&o->outputReal);
29+
hTable_free(&o->outputImagin);
30+
}
31+
32+
void __hv_rfft_f(SignalRFFT *o, hv_bInf_t bIn, hv_bOutf_t bOut0, hv_bOutf_t bOut1) {
33+
// do fft stuff
2834
}
2935

3036
void sRFFT_onMessage(HeavyContextInterface *_c, SignalRFFT *o, int letIndex,
3137
const HvMessage *m, void *sendMessage) {
3238
switch (letIndex) {
33-
case 1: {
34-
if (msg_isHashLike(m,0)) {
35-
HvTable *table = hv_table_get(_c, msg_getHash(m,0));
36-
if (table != NULL) {
37-
o->table = table;
38-
if (hTable_getSize(&o->inputs) != hTable_getSize(table)) {
39-
hTable_resize(&o->inputs,
40-
(hv_uint32_t) hv_min_ui(hTable_getSize(&o->inputs), hTable_getSize(table)));
41-
}
42-
}
43-
}
44-
break;
45-
}
46-
case 2: {
47-
if (msg_isFloat(m,0)) {
48-
// rfft size should never exceed the coefficient table size
49-
hTable_resize(&o->inputs, (hv_uint32_t) msg_getFloat(m,0));
50-
}
51-
break;
52-
}
5339
default: return;
5440
}
5541
}
5642

57-
58-
static inline int wrap(const int i, const int n) {
59-
if (i < 0) return (i+n);
60-
if (i >= n) return (i-n);
61-
return i;
43+
hv_size_t sRIFFT_init(SignalRIFFT *o, const int size) {
44+
hv_size_t numBytes = hTable_init(&o->inputReal, size/2+1);
45+
numBytes += hTable_init(&o->inputImagin, size/2+1);
46+
numBytes += hTable_init(&o->output, size);
47+
return numBytes;
6248
}
6349

64-
65-
void __hv_rfft_f(SignalRFFT *o, hv_bInf_t bIn, hv_bOutf_t bOut0, hv_bOutf_t bOut1) {
66-
hv_assert(o->table != NULL);
67-
float *const work = hTable_getBuffer(o->table);
68-
hv_assert(work != NULL);
69-
const int n = hTable_getSize(o->table); // length fir filter
70-
hv_assert((n&HV_N_SIMD_MASK) == 0); // n is a multiple of HV_N_SIMD
71-
72-
float *const inputs = hTable_getBuffer(&o->inputs);
73-
hv_assert(inputs != NULL);
74-
const int m = hTable_getSize(&o->inputs); // length of input buffer.
75-
hv_assert(m >= n);
76-
const int h_orig = hTable_getHead(&o->inputs);
77-
78-
// float *const bOut = (float *)(hv_alloca(2*n*sizeof(float)));
79-
float *const bOut = (float *)(hv_alloca(sizeof(bIn)));
80-
81-
// do fft stuff
82-
83-
// uninterleave result into the output buffers
84-
for (int j = 0; j < n; ++j) {
85-
bOut0[n+j] = bOut[0+2*j];
86-
bOut1[n+j] = bOut[1+2*j];
87-
}
88-
89-
__hv_store_f(inputs+h_orig, bIn); // store the new input to the inputs buffer
90-
hTable_setHead(&o->inputs, wrap(h_orig+HV_N_SIMD, m));
50+
void sRIFFT_free(SignalRIFFT *o) {
51+
hTable_free(&o->inputReal);
52+
hTable_free(&o->inputImagin);
53+
hTable_free(&o->output);
9154
}
9255

56+
void __hv_rifft_f(SignalRIFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut) {
57+
// do ifft stuff
58+
}
9359

94-
void __hv_rifft_f(SignalRFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut) {
95-
hv_assert(o->table != NULL);
96-
float *const work = hTable_getBuffer(o->table);
97-
hv_assert(work != NULL);
98-
const int n = hTable_getSize(o->table); // length fir filter
99-
hv_assert((n&HV_N_SIMD_MASK) == 0); // n is a multiple of HV_N_SIMD
100-
101-
float *const inputs = hTable_getBuffer(&o->inputs);
102-
hv_assert(inputs != NULL);
103-
const int m = hTable_getSize(&o->inputs); // length of input buffer.
104-
hv_assert(m >= n);
105-
const int h_orig = hTable_getHead(&o->inputs);
106-
107-
float *bIn00 = &bIn0;
108-
float *bIn10 = &bIn1;
109-
// float *const bIn = (float *)(hv_alloca(2*n*sizeof(float)));
110-
float *const bIn = (float *)(hv_alloca(sizeof(bOut)));
111-
112-
// interleave the input buffers into the transform buffer
113-
for (int i = 0; i < 2; ++i) {
114-
for (int j = 0; j < n; ++j) {
115-
bIn[0+2*j] = bIn00[n+j];
116-
bIn[1+2*j] = bIn10[n+j];
117-
}
60+
void sRIFFT_onMessage(HeavyContextInterface *_c, SignalRIFFT *o, int letIndex,
61+
const HvMessage *m, void *sendMessage) {
62+
switch (letIndex) {
63+
default: return;
11864
}
119-
120-
// do ifft stuff
121-
122-
// __hv_store_f(inputs+h_orig, bIn); // store the new input to the inputs buffer
123-
hTable_setHead(&o->inputs, wrap(h_orig+HV_N_SIMD, m));
12465
}

hvcc/generators/ir2c/static/HvSignalRFFT.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,25 @@ extern "C" {
2525

2626

2727
typedef struct SignalRFFT {
28-
struct HvTable *table;
29-
struct HvTable inputs;
28+
struct HvTable input;
29+
struct HvTable outputReal;
30+
struct HvTable outputImagin;
3031
} SignalRFFT;
3132

32-
hv_size_t sRFFT_init(SignalRFFT *o, struct HvTable *table, const int size);
33-
33+
hv_size_t sRFFT_init(SignalRFFT *o, const int size);
3434
void sRFFT_free(SignalRFFT *o);
35-
36-
void sRFFT_onMessage(HeavyContextInterface *_c, SignalRFFT *o, int letIndex,
37-
const HvMessage *m, void *sendMessage);
38-
35+
void sRFFT_onMessage(HeavyContextInterface *_c, SignalRFFT *o, int letIndex, const HvMessage *m, void *sendMessage);
3936
void __hv_rfft_f(SignalRFFT *o, hv_bInf_t bIn, hv_bOutf_t bOut0, hv_bOutf_t bOut1);
4037

41-
void __hv_rifft_f(SignalRFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut);
38+
typedef struct SignalRIFFT {
39+
struct HvTable inputReal;
40+
struct HvTable inputImagin;
41+
struct HvTable output;
42+
} SignalRIFFT;
43+
44+
hv_size_t sRIFFT_init(SignalRIFFT *o, const int size);
45+
void sRIFFT_free(SignalRIFFT *o);
46+
void __hv_rifft_f(SignalRIFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut);
4247

4348
#ifdef __cplusplus
4449
} // extern "C"
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
#N canvas 629 481 436 234 12;
2-
#X obj 25 15 inlet~;
1+
#N canvas 532 457 436 234 12;
2+
#X obj 59 59 inlet~;
3+
#X obj 59 120 outlet~;
4+
#X obj 190 121 outlet~;
35
#N canvas 0 22 450 300 @hv_obj 0;
4-
#X obj 146 77 inlet;
5-
#X obj 147 120 outlet;
6-
#X restore 211 129 pd @hv_obj system;
7-
#X text 80 22 measured after initialisation;
8-
#X obj 25 184 outlet~;
9-
#X obj 211 48 loadbang;
10-
#X obj 211 185 outlet~;
11-
#X msg 211 104 table \$1 size;
12-
#X obj 71 62 table rfft_\$0;
13-
#X obj 211 76 symbol rfft_\$0;
14-
#N canvas 0 22 450 300 @hv_obj 1;
156
#X obj 55 136 outlet~;
167
#X obj 55 75 inlet~;
17-
#X obj 190 74 inlet;
188
#X obj 167 137 outlet~;
19-
#X restore 25 155 pd @hv_obj __rfft~f rfft_\$0;
20-
#X text 80 11 NOTE(dreamer): ensure that the table size is;
21-
#X connect 0 0 9 0;
22-
#X connect 1 0 9 1;
23-
#X connect 4 0 8 0;
24-
#X connect 6 0 1 0;
25-
#X connect 8 0 6 0;
26-
#X connect 9 0 3 0;
27-
#X connect 9 1 5 0;
9+
#X restore 59 91 pd @hv_obj __rfft~f;
10+
#X connect 0 0 3 0;
11+
#X connect 3 0 1 0;
12+
#X connect 3 1 2 0;
Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
#N canvas 1038 308 486 278 12;
2-
#X obj 24 59 inlet~;
3-
#X text 23 24 measured after initialisation;
4-
#X text 22 14 NOTE(mhroth): ensure that the table size is;
5-
#X obj 24 227 outlet~;
6-
#X obj 123 59 inlet~;
7-
#N canvas 0 22 450 300 @hv_obj 1;
1+
#N canvas 1222 648 486 278 12;
2+
#X obj 74 59 inlet~;
3+
#X obj 74 127 outlet~;
4+
#X obj 211 59 inlet~;
5+
#N canvas 0 22 450 300 @hv_obj 0;
86
#X obj 55 136 outlet~;
97
#X obj 55 75 inlet~;
10-
#X obj 180 75 inlet;
118
#X obj 117 75 inlet~;
12-
#X restore 24 197 pd @hv_obj __rifft~f rifft_\$0;
13-
#N canvas 0 22 450 300 @hv_obj 0;
14-
#X obj 146 77 inlet;
15-
#X obj 147 120 outlet;
16-
#X restore 287 144 pd @hv_obj system;
17-
#X obj 287 63 loadbang;
18-
#X msg 287 119 table \$1 size;
19-
#X obj 150 116 table rifft_\$0;
20-
#X obj 287 91 symbol rifft_\$0;
21-
#X connect 0 0 5 0;
22-
#X connect 4 0 5 1;
23-
#X connect 5 0 3 0;
24-
#X connect 6 0 5 2;
25-
#X connect 7 0 10 0;
26-
#X connect 8 0 6 0;
27-
#X connect 10 0 8 0;
9+
#X restore 74 98 pd @hv_obj __rifft~f;
10+
#X connect 0 0 3 0;
11+
#X connect 2 0 3 1;
12+
#X connect 3 0 1 0;

0 commit comments

Comments
 (0)