Skip to content

Commit 90c4c7a

Browse files
committed
first commit - working clone of the 'normalize' NRT buffer instance method
0 parents  commit 90c4c7a

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
**/.DS_Store

BufRev.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// BufRev, an NRT buffer samples swapper
2+
// Pierre Alexandre Tremblay, 2018
3+
// A digital debris of the FluCoMa project, funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 725899)
4+
5+
#include "SC_PlugIn.h"
6+
7+
static InterfaceTable *ft;
8+
9+
static void normalize_samples(int size, float* data, float peak)
10+
{
11+
float maxamp = 0.f;
12+
for (int i=0; i<size; ++i) {
13+
float absamp = std::abs(data[i]);
14+
if (absamp > maxamp) maxamp = absamp;
15+
}
16+
if (maxamp != 0.f && maxamp != peak) {
17+
float ampfac = peak / maxamp;
18+
for (int i=0; i<size; ++i) {
19+
data[i] *= ampfac;
20+
}
21+
}
22+
}
23+
24+
void BufRev(World *world, struct SndBuf *buf, struct sc_msg_iter *msg)
25+
{
26+
float newmax;
27+
if(msg->remain() != 0){
28+
newmax = msg->getf();
29+
}else{
30+
newmax = 1.f;
31+
}
32+
float *data = buf->data;
33+
int size = buf->samples;
34+
normalize_samples(size, data, newmax);
35+
}
36+
37+
PluginLoad(BufRevUGens) {
38+
ft = inTable;
39+
DefineBufGen("reverse", BufRev);
40+
}

BufRev.sc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
+ Buffer {
2+
reverse { arg newmax=1;
3+
if(bufnum.isNil) { Error("Cannot call % on a % that has been freed".format(thisMethod.name, this.class.name)).throw };
4+
server.listSendMsg([\b_gen, bufnum, "reverse", newmax])
5+
}
6+
}
7+

CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
cmake_minimum_required (VERSION 2.8)
2+
set(PROJECT "BufRev")
3+
project (${PROJECT})
4+
5+
include_directories(${SC_PATH}/include/plugin_interface)
6+
include_directories(${SC_PATH}/include/common)
7+
include_directories(${SC_PATH}/common)
8+
9+
10+
set(CMAKE_SHARED_MODULE_PREFIX "")
11+
if(APPLE OR WIN32)
12+
set(CMAKE_SHARED_MODULE_SUFFIX ".scx")
13+
endif()
14+
15+
option(CPP11 "Build with c++11." ON)
16+
17+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
18+
add_definitions(-fvisibility=hidden)
19+
20+
include (CheckCCompilerFlag)
21+
include (CheckCXXCompilerFlag)
22+
23+
CHECK_C_COMPILER_FLAG(-msse HAS_SSE)
24+
CHECK_CXX_COMPILER_FLAG(-msse HAS_CXX_SSE)
25+
26+
if (HAS_SSE)
27+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse")
28+
endif()
29+
if (HAS_CXX_SSE)
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse")
31+
endif()
32+
33+
CHECK_C_COMPILER_FLAG(-msse2 HAS_SSE2)
34+
CHECK_CXX_COMPILER_FLAG(-msse2 HAS_CXX_SSE2)
35+
36+
if (HAS_SSE2)
37+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
38+
endif()
39+
if (HAS_CXX_SSE2)
40+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
41+
endif()
42+
43+
CHECK_C_COMPILER_FLAG(-mfpmath=sse HAS_FPMATH_SSE)
44+
CHECK_CXX_COMPILER_FLAG(-mfpmath=sse HAS_CXX_FPMATH_SSE)
45+
46+
if (HAS_FPMATH_SSE)
47+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse")
48+
endif()
49+
if (HAS_CXX_FPMATH_SSE)
50+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse")
51+
endif()
52+
53+
if(NATIVE)
54+
add_definitions(-march=native)
55+
endif()
56+
57+
if(CPP11)
58+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
59+
if(CMAKE_COMPILER_IS_CLANG)
60+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
61+
endif()
62+
endif()
63+
endif()
64+
if(MINGW)
65+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign")
66+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign")
67+
endif()
68+
69+
add_library(${PROJECT} MODULE BufRev.cpp)

tests.scd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
b = Buffer.alloc(s,16);
2+
b.setn(0, Array.fill(16, {0.1.rand2}));
3+
4+
b.plot
5+
6+
b.reverse
7+
8+
b.plot

0 commit comments

Comments
 (0)