-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
2,461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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: | ||
table_obj = self.graph.resolve_object_for_name( | ||
self.args["table"], | ||
["table", "__table"]) | ||
if table_obj is not None: | ||
self.args["table_id"] = table_obj.id | ||
return ({self}, []) | ||
else: | ||
self.add_error(f"Cannot find table named \"{self.args['table']}\" for object {self}.") | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# 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 | ||
|
||
|
||
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", "pffft.h", "pffft.c"} | ||
|
||
@classmethod | ||
def get_C_init(cls, obj_type: str, obj_id: int, args: Dict) -> List[str]: | ||
return [ | ||
"sRFFT_init(&sRFFT_{0}, &hTable_{1}, {2});".format( | ||
obj_id, | ||
args["table_id"], | ||
64) | ||
] | ||
|
||
@classmethod | ||
def get_C_onMessage(cls, obj_type: str, obj_id: int, 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: Dict, obj_type: str, obj_id: int, 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]) | ||
) | ||
] | ||
elif obj_type == "__rifft~f": | ||
return [ | ||
"__hv_rifft_f(&sRFFT_{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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* 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" | ||
#include "pffft.h" | ||
|
||
hv_size_t sRFFT_init(SignalRFFT *o, struct HvTable *table, const int size) { | ||
o->table = table; | ||
o->setup = pffft_new_setup(size, PFFFT_REAL); | ||
hv_size_t numBytes = hTable_init(&o->inputs, size); | ||
return numBytes; | ||
} | ||
|
||
void sRFFT_free(SignalRFFT *o) { | ||
o->table = NULL; | ||
hTable_free(&o->inputs); | ||
} | ||
|
||
void sRFFT_onMessage(HeavyContextInterface *_c, SignalRFFT *o, int letIndex, | ||
const HvMessage *m, void *sendMessage) { | ||
switch (letIndex) { | ||
case 1: { | ||
if (msg_isHashLike(m,0)) { | ||
HvTable *table = hv_table_get(_c, msg_getHash(m,0)); | ||
if (table != NULL) { | ||
o->table = table; | ||
if (hTable_getSize(&o->inputs) != hTable_getSize(table)) { | ||
hTable_resize(&o->inputs, | ||
(hv_uint32_t) hv_min_ui(hTable_getSize(&o->inputs), hTable_getSize(table))); | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
case 2: { | ||
if (msg_isFloat(m,0)) { | ||
// rfft size should never exceed the coefficient table size | ||
hTable_resize(&o->inputs, (hv_uint32_t) msg_getFloat(m,0)); | ||
} | ||
break; | ||
} | ||
default: return; | ||
} | ||
} | ||
|
||
|
||
static inline int wrap(const int i, const int n) { | ||
if (i < 0) return (i+n); | ||
if (i >= n) return (i-n); | ||
return i; | ||
} | ||
|
||
|
||
void __hv_rfft_f(SignalRFFT *o, hv_bInf_t bIn, hv_bOutf_t bOut0, hv_bOutf_t bOut1) { | ||
hv_assert(o->table != NULL); | ||
float *const work = hTable_getBuffer(o->table); | ||
hv_assert(work != NULL); | ||
const int n = hTable_getSize(o->table); // length fir filter | ||
hv_assert((n&HV_N_SIMD_MASK) == 0); // n is a multiple of HV_N_SIMD | ||
|
||
float *const inputs = hTable_getBuffer(&o->inputs); | ||
hv_assert(inputs != NULL); | ||
const int m = hTable_getSize(&o->inputs); // length of input buffer. | ||
hv_assert(m >= n); | ||
const int h_orig = hTable_getHead(&o->inputs); | ||
|
||
|
||
pffft_transform_ordered(o->setup, &bIn, &bOut0, work, PFFFT_FORWARD); | ||
|
||
__hv_store_f(inputs+h_orig, bIn); // store the new input to the inputs buffer | ||
hTable_setHead(&o->inputs, wrap(h_orig+HV_N_SIMD, m)); | ||
} | ||
|
||
|
||
void __hv_rifft_f(SignalRFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut) { | ||
hv_assert(o->table != NULL); | ||
float *const work = hTable_getBuffer(o->table); | ||
hv_assert(work != NULL); | ||
const int n = hTable_getSize(o->table); // length fir filter | ||
hv_assert((n&HV_N_SIMD_MASK) == 0); // n is a multiple of HV_N_SIMD | ||
|
||
float *const inputs = hTable_getBuffer(&o->inputs); | ||
hv_assert(inputs != NULL); | ||
const int m = hTable_getSize(&o->inputs); // length of input buffer. | ||
hv_assert(m >= n); | ||
const int h_orig = hTable_getHead(&o->inputs); | ||
|
||
|
||
pffft_transform_ordered(o->setup, &bIn0, &bOut, work, PFFFT_BACKWARD); | ||
|
||
__hv_store_f(inputs+h_orig, bIn0); // store the new input to the inputs buffer | ||
hTable_setHead(&o->inputs, wrap(h_orig+HV_N_SIMD, m)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* 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" | ||
#include "pffft.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef HV_SIMD_NONE | ||
#define PFFFT_SIMD_DISABLE | ||
#endif | ||
|
||
typedef struct SignalRFFT { | ||
struct HvTable *table; | ||
struct HvTable inputs; | ||
struct PFFFT_Setup *setup; | ||
} SignalRFFT; | ||
|
||
hv_size_t sRFFT_init(SignalRFFT *o, struct HvTable *coeffs, 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); | ||
|
||
void __hv_rifft_f(SignalRFFT *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif // _SIGNAL_RFFT_H_ |
Oops, something went wrong.