Skip to content

Commit c5aa4a5

Browse files
committed
updated CMake and -1 bug investigation
1 parent f1031a4 commit c5aa4a5

File tree

3 files changed

+100
-27
lines changed

3 files changed

+100
-27
lines changed

CMakeLists.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1+
set(FILENAME "IBufWr.cpp") #specify the .cpp file here
12
cmake_minimum_required (VERSION 2.8)
2-
set(PROJECT "IBufWr")
3+
get_filename_component(PROJECT ${FILENAME} NAME_WE) #automatically sets project name from the filename
4+
# set(PROJECT "my_name") #alternatively set project name manually
5+
message(STATUS "Project name is ${PROJECT}")
36
project (${PROJECT})
47

58
include_directories(${SC_PATH}/include/plugin_interface)
69
include_directories(${SC_PATH}/include/common)
710
include_directories(${SC_PATH}/common)
811

9-
1012
set(CMAKE_SHARED_MODULE_PREFIX "")
1113
if(APPLE OR WIN32)
1214
set(CMAKE_SHARED_MODULE_SUFFIX ".scx")
1315
endif()
1416

17+
option(SUPERNOVA "Build plugins for supernova" OFF)
18+
if (SUPERNOVA)
19+
include_directories(${SC_PATH}/external_libraries/nova-tt)
20+
# actually just boost.atomic
21+
include_directories(${SC_PATH}/external_libraries/boost)
22+
include_directories(${SC_PATH}/external_libraries/boost_lockfree)
23+
include_directories(${SC_PATH}/external_libraries/boost-lockfree)
24+
endif()
25+
1526
option(CPP11 "Build with c++11." ON)
1627

28+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
29+
set(CMAKE_COMPILER_IS_CLANG 1)
30+
endif()
31+
1732
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
1833
add_definitions(-fvisibility=hidden)
1934

@@ -66,4 +81,9 @@ if(MINGW)
6681
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign")
6782
endif()
6883

69-
add_library(${PROJECT} MODULE IBufWr.cpp)
84+
add_library(${PROJECT} MODULE ${FILENAME})
85+
if(SUPERNOVA)
86+
add_library(${PROJECT}_supernova MODULE ${FILENAME})
87+
set_property(TARGET ${PROJECT}_supernova
88+
PROPERTY COMPILE_DEFINITIONS SUPERNOVA)
89+
endif()

release-packaging/IBufWr/HelpSource/Classes/IBufWr.schelp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ For a more detailed explanation and thorough justification of the usefulness of
6969
STRONG:: Basic Usage: Comparing BufWr and IBufWr::
7070

7171
code::
72+
s.boot;
73+
7274
(
7375
// define 2 small buffers
7476
b = Buffer.alloc(s, s.sampleRate);
@@ -115,12 +117,16 @@ c.getn(0,31, {|msg| msg.postln});
115117
// but it gets nasty if you change the speed of playback, especially if you read faster than the writing was done, because of these empty indices skipped in the writing process.
116118
{BufRd.ar(1,[b.bufnum, c.bufnum],Phasor.ar(0, 11 , 0, b.numFrames),0,1)}.play
117119

120+
// clean up
121+
b.free;c.free;
118122
::
119123

120124

121125
STRONG:: A More Musical Example: Emulating a Resampling Digital Delay::
122126

123127
code::
128+
s.boot;
129+
124130
//create a one second buffer
125131
b = Buffer.alloc(s, s.sampleRate);
126132

@@ -174,14 +180,15 @@ y.set(\gain, 0)
174180
x.free
175181
y.set(\feedback, 0.8)
176182

177-
// free the delay
178-
y.free
179-
b.free
183+
// free the delay and both buffers
184+
y.free; b.free; d.free;
180185
::
181186

182187
STRONG:: Yet Another Musical Example: Processing Within the Feedback Loop::
183188

184189
code::
190+
s.boot;
191+
185192
//create a one second buffer
186193
b = Buffer.alloc(s, s.sampleRate);
187194

@@ -195,7 +202,7 @@ d = Buffer.read(s, p);
195202
x = d.play(true, 0.1)
196203

197204
// add a basic delay after using the built-in DelayN, 6dB lower -- feedbback does not work, needs a block delay (InFeedback)
198-
y = {arg gain = 0.5, feed = 0.5; [0, DelayN.ar((In.ar(0) * gain) + (In.ar(1) * feed),0.2,0.2)]}.play(addAction:'addToTail')
205+
y = {arg gain = 0.5, feed = 0.5; [0, DelayN.ar((In.ar(0) * gain) + (In.ar(1) * feed),1,1)]}.play(addAction:'addToTail')
199206

200207
// so free that
201208
y.free
@@ -216,10 +223,10 @@ y = {
216223

217224
// ...but gets nasty when the duration is changed, especially when shorter than the original, as it skips samples and most probably reads in these samples skipped at writing time...
218225
y.set(\dur, 0.91111)
219-
x.free
226+
x.free;
220227

221-
y.free
222-
b.zero;
228+
// clean up
229+
y.free; b.zero;
223230

224231
// this works better using IBufWr
225232
// start the sound source
@@ -241,9 +248,7 @@ y = {
241248
y.set(\dur, 0.91111)
242249

243250
// and more fun - set a 400 ms filtered looper
244-
y.set(\gain, 0);
245-
y.set(\feedback, 1);
246-
y.set(\dur, 0.4);
251+
y.set(\gain, 0, \feedback, 1, \dur, 0.4);
247252

248253
// send some stuff in, then cut the source
249254
y.set(\gain, 1);
@@ -253,29 +258,25 @@ y.set(\gain, 0);
253258
y.set(\dur, 0.8)
254259

255260
// with smoothing
256-
(
257-
y.set(\gain, 1);
258-
y.set(\lag, 0.4);
259-
y.set(\dur, 0.2);
260-
y.set(\feedback, 0.7);
261-
)
261+
y.set(\gain, 1, \lag, 0.4, \dur, 0.2, \feedback, 0.7);
262262

263263
// cool stop!
264264
(
265-
y.set(\feedback, 0.9);
266-
y.set(\lag, 2);
267-
y.set(\dur, 2);
268-
x.free
265+
y.set(\feedback, 0.9, \lag, 2, \dur, 2);
266+
x.free;
269267
)
270268

271-
y.free
269+
//clean up
270+
y.free; b.free; d.free;
272271
::
273272

274273
STRONG:: A kr example: using a synchronously mutating stereo buffer as sequencer::
275274

276275
code::
276+
s.boot;
277+
277278
// allocate a small buffer for the sequence
278-
e= Buffer.alloc(s,1000,2)
279+
e= Buffer.alloc(s,1000,2);
279280

280281
// start the fun!
281282
(
@@ -291,8 +292,11 @@ e= Buffer.alloc(s,1000,2)
291292
)
292293

293294
// plot regularly to enjoy the sequence
294-
e.plot
295+
e.plot;
295296

296297
// when it's too much, zero the lfo buffer
297-
e.zero
298+
e.zero;
299+
300+
// clean up
301+
e.free;
298302
::

release-packaging/IBufWr/HelpSource/Guides/BufferWritingGuide.schelp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Both link::Classes/BufWr:: and link::Classes/IBufWr:: behave the same way, which
1313

1414
strong::Example 1: Basic Stereo Buffer Writing::
1515
code::
16+
s.boot;
17+
1618
// allocate a stereo buffer
1719
c = Buffer.alloc(s, s.sampleRate,2);
1820

@@ -32,10 +34,15 @@ c = Buffer.alloc(s, s.sampleRate,2);
3234
);
3335
}.plot(0.1)
3436
)
37+
38+
//clean up
39+
c.free;
3540
::
3641

3742
strong::Example 2: Common Error, too large an input array::
3843
code::
44+
s.boot;
45+
3946
// allocate a stereo buffer
4047
c = Buffer.alloc(s, s.sampleRate,2);
4148

@@ -50,10 +57,15 @@ c = Buffer.alloc(s, s.sampleRate,2);
5057
}.plot(0.1)
5158
)
5259
// check the Post Window, you get told off!
60+
61+
//clean up
62+
c.free;
5363
::
5464

5565
strong::Example 3: Common Error, multichannel expansion of the index (phase) input::
5666
code::
67+
s.boot;
68+
5769
// this code will try to multichannel expand the index(phase) input.
5870
// allocate a stereo buffer
5971
c = Buffer.alloc(s, s.sampleRate,2);
@@ -74,6 +86,9 @@ c = Buffer.alloc(s, s.sampleRate,2);
7486
);
7587
}.plot(0.1)
7688
) // if that was working we would expect 2 parallel lines, the 2nd perforated since we skip at the same speed than the values...
89+
90+
//clean up
91+
c.free;
7792
::
7893

7994
subsection:: The Main Differences between BufWr and IBufWr
@@ -85,6 +100,8 @@ strong:: Variable CPU taxing::
85100
link::Classes/IBufWr:: needs to check if there is an index or more that has been skipped, which implies some branching in the code, which takes CPU time. Even at one-sample-per-sample writing speed, it is less efficient than link::Classes/BufWr:: because of that check.
86101

87102
code::
103+
s.boot;
104+
88105
// declare a buffer
89106
b = Buffer.alloc(s, s.sampleRate);
90107

@@ -154,14 +171,22 @@ g = Group.new;
154171
)
155172
// now the interpolation hits even more.
156173
g.free
174+
175+
//free the buffer
176+
b.free;
157177
::
158178

159179
strong:: 1 sample late::
160180

161181
The way link::Classes/IBufWr:: interpolates is by making the difference between indices. What this implies is that at the end of a vector, the known value of the last sample will not be known until the first value of the next vector. In a code where the writing happens right before the playing, it creates a whole in the output. The discriminating ear will have heard that in the previous examples above. This is in fact written as soon as possible, as one can see in the example below:
162182

163183
code::
184+
s.boot;
185+
186+
//allocate a small buffer
164187
b = Buffer.alloc(s, 200);
188+
189+
//writing at the same time as reading
165190
(
166191
b.zero;
167192
{
@@ -189,3 +214,27 @@ b.plot
189214
strong::negative index::
190215

191216
A feature of link::Classes/IBufWr:: is that the writing can be paused at any time, by providing negative indices. Once the writing starts again, the first index is not interpolated from the previous positive entry.
217+
218+
code::
219+
s.boot;
220+
221+
//allocate a second-long buffer
222+
b = Buffer.alloc(s, s.sampleRate/10);
223+
224+
//writing with a switch on the index every 250ms
225+
(
226+
b.zero;
227+
{
228+
IBufWr.ar(
229+
Phasor.ar(0, 1 , 0, b.numFrames),// writing values, incremented one sample per sample
230+
b.bufnum,
231+
LFPulse.ar(40,mul:Phasor.ar(0, 1 , 1, b.numFrames+1),add:-1), // writes one sample per sample when the pulse is up, otherwise is stable at -1
232+
1
233+
);
234+
}.plot(0.1)
235+
)
236+
237+
b.plot
238+
239+
b.free
240+
::

0 commit comments

Comments
 (0)