Skip to content

Commit 6430d15

Browse files
committed
init
0 parents  commit 6430d15

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required (VERSION 2.8)
2+
project (VoxRes)
3+
set(SC_PATH /Users/acsmith/workspaces/supercollider)
4+
5+
include_directories(${SC_PATH}/include/plugin_interface)
6+
include_directories(${SC_PATH}/include/common)
7+
include_directories(${SC_PATH}/external_libraries/libsndfile/)
8+
9+
set(CMAKE_SHARED_MODULE_PREFIX "")
10+
if(APPLE OR WIN32)
11+
set(CMAKE_SHARED_MODULE_SUFFIX ".scx")
12+
endif()
13+
14+
# include_directories(/Users/acsmith/workspaces/music/rust/vox_box/target/release)
15+
add_library(VoxRes MODULE VoxRes.cpp)
16+
find_library(VOX_BOX_LIBRARIES NAMES vox_box libvox_box PATHS /Users/acsmith/workspaces/music/rust/vox_box/target/release)
17+
target_link_libraries(VoxRes PRIVATE ${VOX_BOX_LIBRARIES})
18+
install(TARGETS VoxRes DESTINATION .)

VoxRes.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include "SC_PlugIn.h"
2+
3+
// InterfaceTable contains pointers to functions in the host
4+
static InterfaceTable *ft;
5+
6+
struct VoxRes : public Unit
7+
{
8+
float* resampled;
9+
float* local_buf;
10+
int resampledFrames;
11+
float* autocor_buffer;
12+
float* lpc;
13+
float* lpc_work;
14+
float* res;
15+
float* res_work;
16+
int lpc_size;
17+
int max_resonances;
18+
SndBuf *m_buf;
19+
float m_fbufnum;
20+
int m_framepos;
21+
int offset;
22+
};
23+
24+
static void VoxRes_next_k(VoxRes *unit, int inNumSamples);
25+
static void VoxRes_Ctor(VoxRes *unit);
26+
27+
extern "C"
28+
{
29+
float* vox_box_autocorrelate_mut_f32(const float*, size_t, size_t, float*);
30+
void vox_box_resample_mut_f32(const float*, size_t, size_t, float*);
31+
void vox_box_normalize_f32(void*, size_t);
32+
void vox_box_lpc_mut_f32(const float*, size_t, size_t, float*, float*);
33+
float* vox_box_resonances_mut_f32(float*, size_t, float, int*, float*, float*);
34+
}
35+
36+
void VoxRes_Ctor(VoxRes *unit)
37+
{
38+
SETCALC(VoxRes_next_k);
39+
unit->lpc_size = ZIN0(1);
40+
unit->resampledFrames = ZIN0(2);
41+
unit->m_buf = unit->mWorld->mSndBufs;
42+
unit->m_fbufnum = -1.f;
43+
unit->m_framepos = 0;
44+
GET_BUF_SHARED;
45+
unit->max_resonances = 4;
46+
unit->offset = 0;
47+
unit->local_buf = (float*)RTAlloc(unit->mWorld, sizeof(float) * bufFrames);
48+
unit->autocor_buffer = (float*)RTAlloc(unit->mWorld, sizeof(float) * unit->resampledFrames);
49+
unit->resampled = (float*)RTAlloc(unit->mWorld, sizeof(float) * unit->resampledFrames);
50+
unit->lpc = (float*)RTAlloc(unit->mWorld, sizeof(float) * unit->lpc_size + 1);
51+
unit->lpc_work = (float*)RTAlloc(unit->mWorld, sizeof(float) * unit->lpc_size * 4);
52+
unit->res = (float*)RTAlloc(unit->mWorld, sizeof(float) * unit->lpc_size + 1);
53+
unit->res_work = (float*)RTAlloc(unit->mWorld, sizeof(float) * unit->lpc_size * 16);
54+
for (int i = 0; i < 4; i++) {
55+
*OUT(i) = 0.f;
56+
}
57+
VoxRes_next_k(unit, 1);
58+
}
59+
60+
void VoxRes_next_k(VoxRes *unit, int inNumSamples)
61+
{
62+
GET_BUF_SHARED;
63+
for (int i = 0; i < bufFrames; i++) {
64+
unit->local_buf[i] = bufData[(i + unit->offset) & (bufFrames - 1)];
65+
}
66+
vox_box_resample_mut_f32(unit->local_buf, (size_t)bufFrames, unit->resampledFrames, unit->resampled);
67+
vox_box_autocorrelate_mut_f32(unit->resampled, (size_t)unit->resampledFrames, unit->lpc_size + 2, unit->autocor_buffer);
68+
vox_box_normalize_f32(unit->autocor_buffer, unit->lpc_size + 2);
69+
vox_box_lpc_mut_f32(unit->autocor_buffer, unit->lpc_size + 2, unit->lpc_size, unit->lpc, unit->lpc_work);
70+
int resonance_count = 0;
71+
vox_box_resonances_mut_f32(unit->lpc, unit->lpc_size + 1, FULLRATE * unit->resampledFrames / (float)bufFrames, &resonance_count, unit->res_work, unit->res);
72+
for (int i = 0; (i < resonance_count) && (i < unit->max_resonances); i++) {
73+
*OUT(i) = unit->res[i];
74+
}
75+
unit->offset += (int)BUFRATE;
76+
}
77+
78+
void VoxRes_Dtor(VoxRes *unit)
79+
{
80+
RTFree(unit->mWorld, unit->local_buf);
81+
RTFree(unit->mWorld, unit->autocor_buffer);
82+
RTFree(unit->mWorld, unit->lpc);
83+
RTFree(unit->mWorld, unit->lpc_work);
84+
RTFree(unit->mWorld, unit->res);
85+
RTFree(unit->mWorld, unit->res_work);
86+
}
87+
88+
PluginLoad(VoxRes)
89+
{
90+
ft = inTable;
91+
DefineSimpleUnit(VoxRes);
92+
}
93+
94+
95+

vox_res.sc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
VoxRes : MultiOutUGen {
2+
*kr {
3+
arg in, lpcCount = 16;
4+
^this.multiNew('control', in, lpcCount)
5+
}
6+
7+
init {
8+
arg ... theInputs;
9+
inputs = theInputs;
10+
^this.initOutputs(4, rate);
11+
}
12+
}

0 commit comments

Comments
 (0)