Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions hvcc/core/hv2ir/HIrRFFT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (C) 2014-2018 Enzien Audio, Ltd.
# Copyright (C) 2023 Wasted Audio
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Dict, Optional

from .HeavyIrObject import HeavyIrObject
from .HeavyGraph import HeavyGraph


class HIrRFFT(HeavyIrObject):
""" __rfft~f
"""

def __init__(
self,
obj_type: str,
args: Optional[Dict] = None,
graph: Optional[HeavyGraph] = None,
annotations: Optional[Dict] = None
) -> None:
assert obj_type in {"__rfft~f", "__rifft~f"}
super().__init__(obj_type, args=args, graph=graph, annotations=annotations)

def reduce(self) -> Optional[tuple]:
if self.graph is not None:
self.args["block_size"] = self.graph.args["block_size"]
return ({self}, [])

return None
1 change: 0 additions & 1 deletion hvcc/core/hv2ir/HeavyGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ def resolve_object_for_name(
from this graph. Returns None if no objects are available.
This is a convenience method.
"""

objs = self.resolve_objects_for_name(name, obj_types, local_graph)
return objs[0] if len(objs) > 0 else None

Expand Down
11 changes: 11 additions & 0 deletions hvcc/core/hv2ir/HeavyParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .HIrLorenz import HIrLorenz
from .HIrOutlet import HIrOutlet
from .HIrPack import HIrPack
from .HIrRFFT import HIrRFFT
from .HIrSwitchcase import HIrSwitchcase
from .HIrTabhead import HIrTabhead
from .HIrTabread import HIrTabread
Expand Down Expand Up @@ -114,6 +115,14 @@ def graph_from_object(
"""
# resolve default graph arguments
graph_args = graph_args or {}

# set the block size
try:
if json_heavy["block_size"] is not None:
graph_args["block_size"] = int(json_heavy["block_size"])
except KeyError:
graph_args["block_size"] = 64

for a in json_heavy["args"]:
if a["name"] not in graph_args:
if a["required"]:
Expand Down Expand Up @@ -307,6 +316,8 @@ def reduce(self) -> Tuple[Set, List]:
"__tabwrite~f": HIrTabwrite,
"__tabwrite_stoppable~f": HIrTabwrite,
"__tabwrite": HIrTabwrite,
"__rfft~f": HIrRFFT,
"__rifft~f": HIrRFFT,
"receive": HLangReceive,
"send": HLangSend,
"__switchcase": HIrSwitchcase,
Expand Down
38 changes: 38 additions & 0 deletions hvcc/core/json/heavy.ir.json
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,44 @@
"-->"
]
},
"__rfft~f": {
"inlets": [
"~f>"
],
"ir": {
"control": false,
"signal": true,
"init": true
},
"outlets": [
"~f>",
"~f>"
],
"args": [],
"perf": {
"avx": 0,
"sse": 0
}
},
"__rifft~f": {
"inlets": [
"~f>",
"~f>"
],
"ir": {
"control": false,
"signal": true,
"init": true
},
"outlets": [
"~f>"
],
"args": [],
"perf": {
"avx": 0,
"sse": 0
}
},
"__rpole~f": {
"inlets": [
"~f>",
Expand Down
109 changes: 109 additions & 0 deletions hvcc/generators/ir2c/SignalRFFT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright (C) 2014-2018 Enzien Audio, Ltd.
# Copyright (C) 2023 Wasted Audio
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Dict, List

from .HeavyObject import HeavyObject

from hvcc.types.IR import IRSignalList


class SignalRFFT(HeavyObject):

c_struct = "SignalRFFT"
preamble = "sRFFT"

@classmethod
def get_C_header_set(cls) -> set:
return {"HvSignalRFFT.h"}

@classmethod
def get_C_file_set(cls) -> set:
return {"HvSignalRFFT.h", "HvSignalRFFT.c"}

@classmethod
def get_C_init(cls, obj_type: str, obj_id: str, args: Dict) -> List[str]:
return [
"sRFFT_init(&sRFFT_{0}, {1});".format(
obj_id,
args["block_size"])
]

@classmethod
def get_C_onMessage(cls, obj_type: str, obj_id: str, inlet_index: int, args: Dict) -> List[str]:
return [
"sRFFT_onMessage(_c, &Context(_c)->sRFFT_{0}, {1}, m, NULL);".format(
obj_id,
inlet_index)
]

@classmethod
def get_C_process(cls, process_dict: IRSignalList, obj_type: str, obj_id: str, args: Dict) -> List[str]:
if obj_type == "__rfft~f":
return [
"__hv_rfft_f(&sRFFT_{0}, VIf({1}), VOf({2}), VOf({3}));".format(
process_dict.id,
cls._c_buffer(process_dict.inputBuffers[0]),
cls._c_buffer(process_dict.outputBuffers[0]),
cls._c_buffer(process_dict.outputBuffers[1])
)
]
else:
raise Exception


class SignalRIFFT(HeavyObject):

c_struct = "SignalRIFFT"
preamble = "sRIFFT"

@classmethod
def get_C_header_set(cls) -> set:
return {"HvSignalRFFT.h"}

@classmethod
def get_C_file_set(cls) -> set:
return {"HvSignalRFFT.h", "HvSignalRFFT.c"}

@classmethod
def get_C_init(cls, obj_type: str, obj_id: str, args: Dict) -> List[str]:
return [
"sRIFFT_init(&sRIFFT_{0}, {1});".format(
obj_id,
args["block_size"])
]

@classmethod
def get_C_onMessage(cls, obj_type: str, obj_id: str, inlet_index: int, args: Dict) -> List[str]:
return [
"sRIFFT_onMessage(_c, &Context(_c)->sRIFFT_{0}, {1}, m, NULL);".format(
obj_id,
inlet_index)
]

@classmethod
def get_C_process(cls, process_dict: IRSignalList, obj_type: str, obj_id: str, args: Dict) -> List[str]:
if obj_type == "__rifft~f":
return [
"__hv_rifft_f(&sRIFFT_{0}, VIf({1}), VIf({2}), VOf({3}));".format(
process_dict.id,
cls._c_buffer(process_dict.inputBuffers[0]),
cls._c_buffer(process_dict.inputBuffers[1]),
cls._c_buffer(process_dict.outputBuffers[0])
)
]
else:
raise Exception
3 changes: 3 additions & 0 deletions hvcc/generators/ir2c/ir2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from hvcc.generators.ir2c.SignalLorenz import SignalLorenz
from hvcc.generators.ir2c.SignalMath import SignalMath
from hvcc.generators.ir2c.SignalPhasor import SignalPhasor
from hvcc.generators.ir2c.SignalRFFT import SignalRFFT, SignalRIFFT
from hvcc.generators.ir2c.SignalRPole import SignalRPole
from hvcc.generators.ir2c.SignalSample import SignalSample
from hvcc.generators.ir2c.SignalSamphold import SignalSamphold
Expand Down Expand Up @@ -105,6 +106,8 @@ class ir2c:
"__tabwrite_stoppable~f": SignalTabwrite,
"__phasor~f": SignalPhasor,
"__phasor_k~f": SignalPhasor,
"__rfft~f": SignalRFFT,
"__rifft~f": SignalRIFFT,
"__sample~f": SignalSample,
"__samphold~f": SignalSamphold,
"__slice": ControlSlice,
Expand Down
65 changes: 65 additions & 0 deletions hvcc/generators/ir2c/static/HvSignalRFFT.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2023 Wasted Audio
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/

#include "HvSignalRFFT.h"

hv_size_t sRFFT_init(SignalRFFT *o, const int size) {
hv_size_t numBytes = hTable_init(&o->input, size);
numBytes += hTable_init(&o->outputReal, size/2+1);
numBytes += hTable_init(&o->outputImagin, size/2+1);
return numBytes;
}

void sRFFT_free(SignalRFFT *o) {
hTable_free(&o->input);
hTable_free(&o->outputReal);
hTable_free(&o->outputImagin);
}

void __hv_rfft_f(SignalRFFT *o, hv_bInf_t bIn, hv_bOutf_t bOut0, hv_bOutf_t bOut1) {
// do fft stuff
}

void sRFFT_onMessage(HeavyContextInterface *_c, SignalRFFT *o, int letIndex,
const HvMessage *m, void *sendMessage) {
switch (letIndex) {
default: return;
}
}

hv_size_t sRIFFT_init(SignalRIFFT *o, const int size) {
hv_size_t numBytes = hTable_init(&o->inputReal, size/2+1);
numBytes += hTable_init(&o->inputImagin, size/2+1);
numBytes += hTable_init(&o->output, size);
return numBytes;
}

void sRIFFT_free(SignalRIFFT *o) {
hTable_free(&o->inputReal);
hTable_free(&o->inputImagin);
hTable_free(&o->output);
}

void __hv_rifft_f(SignalRIFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut) {
// do ifft stuff
}

void sRIFFT_onMessage(HeavyContextInterface *_c, SignalRIFFT *o, int letIndex,
const HvMessage *m, void *sendMessage) {
switch (letIndex) {
default: return;
}
}
53 changes: 53 additions & 0 deletions hvcc/generators/ir2c/static/HvSignalRFFT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2023 Wasted Audio
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef _SIGNAL_RFFT_H_
#define _SIGNAL_RFFT_H_

#include "HvHeavyInternal.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef struct SignalRFFT {
struct HvTable input;
struct HvTable outputReal;
struct HvTable outputImagin;
} SignalRFFT;

hv_size_t sRFFT_init(SignalRFFT *o, const int size);
void sRFFT_free(SignalRFFT *o);
void sRFFT_onMessage(HeavyContextInterface *_c, SignalRFFT *o, int letIndex, const HvMessage *m, void *sendMessage);
void __hv_rfft_f(SignalRFFT *o, hv_bInf_t bIn, hv_bOutf_t bOut0, hv_bOutf_t bOut1);

typedef struct SignalRIFFT {
struct HvTable inputReal;
struct HvTable inputImagin;
struct HvTable output;
} SignalRIFFT;

hv_size_t sRIFFT_init(SignalRIFFT *o, const int size);
void sRIFFT_free(SignalRIFFT *o);
void sRIFFT_onMessage(HeavyContextInterface *_c, SignalRIFFT *o, int letIndex, const HvMessage *m, void *sendMessage);
void __hv_rifft_f(SignalRIFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // _SIGNAL_RFFT_H_
4 changes: 4 additions & 0 deletions hvcc/interpreters/pd2hv/PdGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __init__(
# only used is this graph is actually a subpatch
self.subpatch_name: Optional[str] = None

# the block size of this graph (used for rfft window size)
self.block_size: Optional[int] = None

# TODO(dromer) these are virtual attributes that are only instantiated with internal representation
self._PdGraph__connections: List[Connection] = []
self._PdGraph__pd_path: str = ""
Expand Down Expand Up @@ -227,6 +230,7 @@ def to_hv(self, export_args: bool = False) -> Dict:
assert all(a is not None for a in self.hv_args), "Graph is missing a @hv_arg."
return {
"type": "graph",
"block_size": self.block_size,
"imports": [],
"args": self.hv_args if export_args else [],
"objects": {o.obj_id: o.to_hv() for o in self.__objs},
Expand Down
Loading
Loading