Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible changes by wavesets group #9

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions HelpSource/Classes/WavesetsEvent.schelp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ METHOD:: setBuffer
argument:: argBuffer
argument:: onComplete
argument:: minLength
argument:: startFrame
argument:: endFrame

METHOD:: read
argument:: path
Expand All @@ -101,3 +103,9 @@ argument:: num
argument:: size
argument:: action

METHOD:: getDFT
argument:: index
argument:: num
argument:: method
argument:: action

Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified MrKov/Mr.Kov.pdf
100644 → 100755
Empty file.
Empty file modified MrKov/mrkov.scd
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WavesetsEvent
An updated wavesets implementation
# WavesetsEvent_lab
Personal fork for experiments with the WavesetsEvent SuperCollider class.

This combines the Wavesets Quark by Alberto de Campo and work by Till Bovermann.
It adds event support and loading selected channels of multichannel files.
Expand Down
Empty file modified Wavesets.quark
100644 → 100755
Empty file.
Empty file modified classes/Pwavesets.sc
100644 → 100755
Empty file.
66 changes: 42 additions & 24 deletions classes/Wavesets2.sc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,32 @@ Wavesets2 {
var <minSet, <maxSet, <avgLength, <sqrAvgLength;
var <minAmp, <maxAmp, <avgAmp, <sqrAvgAmp;

classvar <>defaultMinLength = 10; // minLength reasonable? => 4.4 kHz maxFreq.
classvar <>defaultMinLength = 10; // minLength reasonable? => 4.4 kHz maxfq.
classvar <>printStats = true; // minLength reasonable? => 4.4 kHz maxfq.

*fromBuffer { |buffer, onComplete, minLength|
^this.new.fromBuffer(buffer, onComplete, minLength)
*fromBuffer { |buffer, onComplete, minLength, startFrame, endFrame|
^this.new.fromBuffer(buffer, onComplete, minLength, startFrame, endFrame)
}

fromBuffer { |argBuffer, onComplete, minLength|
fromBuffer { |argBuffer, onComplete, minLength, startFrame, endFrame|
buffer = argBuffer;
buffer.loadToFloatArray(0, -1, { |array|
this.setSignal(array, minLength, buffer);
onComplete.value(this);
})
startFrame = (startFrame ? 0).wrap(0,argBuffer.numFrames);
endFrame = (endFrame ? argBuffer.numFrames-1).wrap(0,argBuffer.numFrames);

if(startFrame > endFrame){
buffer.loadToFloatArray(startFrame, buffer.numFrames - startFrame, { |array|
buffer.loadToFloatArray(0, endFrame, { |brray|
array = array ++ brray;
this.setSignal(array, minLength, buffer, startFrame, endFrame);
onComplete.value(this);
})
});
} {
buffer.loadToFloatArray(startFrame, endFrame - startFrame, { |array|
this.setSignal(array, minLength, buffer, startFrame, endFrame);
onComplete.value(this);
});
}
}

toBuffer { |buffer, onComplete|
Expand All @@ -36,10 +50,10 @@ Wavesets2 {
this.analyse;
}

setSignal { |sig, minLength, argBuffer|
setSignal { |sig, minLength, argBuffer, startFrame, endFrame|
signal = sig;
buffer = argBuffer;
this.analyse(minLength);
this.analyse(minLength,startFrame,endFrame);
}

numFrames { ^signal.size }
Expand Down Expand Up @@ -80,23 +94,26 @@ Wavesets2 {
)
}



// the interesting bit

analyse { |minLength|
analyse { |minLength, startFrame, endFrame|
// var chunkSize = 400, pause = 0.01; // not used yet
xings = Array.new;
amps = Array.new;
lengths = Array.new;
fracXings = Array.new;
maxima = Array.new; // indices of possible turnaround points
minima = Array.new; //
"%: Analysing ...".format(this.class).inform;

this.analyseFromTo(minLength: minLength);
if(printStats) {
"%: Analysing ...".format(this.class).inform;
"StartFrame: % EndFrame: %".format(*[startFrame,endFrame].asInteger).inform;
};
this.analyseFromTo(startFrame: startFrame, endFrame: endFrame, minLength: minLength);
this.calcAverages;
"\t ... done. (% xings)".format(xings.size).inform;
if(printStats) {
"\t ... done. (% xings)".format(xings.size).inform;
}
}

analyseFromTo { |startFrame = 0, endFrame, minLength|
Expand All @@ -109,13 +126,13 @@ Wavesets2 {

// find xings, store indices, lengths, and amps.

startFrame = max(0, startFrame);
endFrame = (endFrame ? signal.size - 1).min(signal.size - 1);
startFrame = max(0, startFrame).asInteger;
endFrame = (endFrame ? signal.size - 1).min(signal.size - 1).asInteger;

signal.size.do { |x,i|

(startFrame to: endFrame).do { |i|
var thisSample;
thisSample = signal.at(i);

// if Xing from non-positive to positive:
if(
(prevSample <= 0.0) and:
Expand All @@ -133,11 +150,11 @@ Wavesets2 {
minima = minima.add(minAmpIndex);
};

xings = xings.add(i);
xings = xings.add(i + startFrame);

// lin interpol for fractional crossings
frac = prevSample / (prevSample - thisSample);
fracXings = fracXings.add(i - 1 + frac);
fracXings = fracXings.add(i - 1 + frac + startFrame);

// reset vars for next waveset
maxSamp = 0.0;
Expand All @@ -146,10 +163,11 @@ Wavesets2 {
};

lengthCount = lengthCount + 1;
if(thisSample > maxSamp) { maxSamp = thisSample; maxAmpIndex = i };
if(thisSample < minSamp) { minSamp = thisSample; minAmpIndex = i };
if(thisSample > maxSamp) { maxSamp = thisSample; maxAmpIndex = i + startFrame };
if(thisSample < minSamp) { minSamp = thisSample; minAmpIndex = i + startFrame };
prevSample = thisSample;
}

}

// basic statistics
Expand Down
101 changes: 82 additions & 19 deletions classes/WavesetsEvent.sc
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

/*

todo: global cache like in the original Wavesets
todo: - global cache like in the original Wavesets
(mine)- add argument "wrap", that makes ~num wrap around the numXings
- if endTime < startTime; switch end and start and make ~rate = ~rate.neg

*/

Expand Down Expand Up @@ -63,7 +65,6 @@ AbstractWavesetsEvent {
^this.asEvent(event);
}


// backwards compatibility
eventFor { |startWs=0, numWs=5, repeats=3, rate=1, useFrac = true|
^this.asEvent((start: startWs, num: numWs, repeats: repeats, rate: rate, useFrac: useFrac))
Expand Down Expand Up @@ -94,23 +95,27 @@ WavesetsEvent : AbstractWavesetsEvent {
}

readChannel { |path, channel = 0, startFrame = 0, numFrames = -1, onComplete, server, minLength|
var finish, buffer;
var finish, buffer, endFrame;
endFrame = if(numFrames > 0) {
startFrame + numFrames;
} { nil };

server = server ? Server.default;
if(server.serverRunning.not) {
"Reading WavesetsBuffer failed. Server % not running".format(server).warn;
^this
};
finish = { this.setBuffer(buffer, onComplete, minLength) };
finish = { this.setBuffer(buffer, onComplete, minLength, startFrame, endFrame) };
buffer = Buffer.readChannel(server ? Server.default, path, startFrame, numFrames, channels: channel.asArray, action: finish);
}

setBuffer { |argBuffer, onComplete, minLength|
wavesets = Wavesets2.fromBuffer(argBuffer, onComplete, minLength);
setBuffer { |argBuffer, onComplete, minLength, startFrame, endFrame|
wavesets = Wavesets2.fromBuffer(argBuffer, onComplete, minLength, startFrame, endFrame);
buffer = argBuffer;
}

free {
buffer.free;
// buffer.free;
wavesets = nil;
}

Expand All @@ -133,28 +138,31 @@ WavesetsEvent : AbstractWavesetsEvent {
}

addWavesetsToEvent {
var theseXings, startWs, endWs, useFrac;
var theseXings, startWs, endWs, useFrac, frames, rotations;
useFrac = ~useFrac ? true;
theseXings = if (useFrac) { wavesets.fracXings } { wavesets.xings };

~startTime !? { ~start = wavesets.nextStartCrossingIndex(~startTime * ~sampleRate, useFrac) };
startWs = ~start ? 0;
~startFrame = theseXings.clipAt(startWs);

// ~startFrame = theseXings.wrapAt(startWs);

~endTime !? { ~end = wavesets.nextCrossingIndex(~endTime * ~sampleRate, useFrac) };

if(~wsustain.notNil) {
endWs = wavesets.nextCrossingIndex(~startFrame + (~sustain.value * ~sampleRate), ~useFrac);
endWs = wavesets.nextCrossingIndex(~startFrame + (~wsustain.value * ~sampleRate), useFrac);
} {
~num = if(~end.notNil) { max(~end - startWs, 1) } { ~num ? 1 };
endWs = startWs + ~num;
};

~endFrame = theseXings.clipAt(endWs);
~numFrames = ~endFrame - ~startFrame;

if(~fixsustain.notNil) {
~rate = ~numFrames / (~fixsustain * ~sampleRate)
~rate = ~numFrames / (~fixsustain * ~sampleRate);
~rate2 = ~rate;
// if(~rate2.notNil) { ~rate2 = ~rate2 * ~rate } { ~rate2 = ~rate };
};
if(~wsamp.notNil) { ~amp = ~wsamp / wavesets.maximumAmp(~start, ~num) };
}
Expand All @@ -170,27 +178,31 @@ WavesetsEvent : AbstractWavesetsEvent {
~rate = ~rate ? 1.0;
if(~rate2.notNil) {
averagePlaybackRate = ~rate + ~rate2 * 0.5;
~instrument = ~instrument ? \wvst1gl;

if(~envBuf.isNil) {
~instrument = ~instrument ? \wvst1gl;
} {
~instrument = ~instrument ? \wvst2glenv;
}
} {
averagePlaybackRate = ~rate;
~instrument = ~instrument ? \wvst0;
~rate2 = ~rate;
};
~rate2 = ~rate2 ? 1.0;

~sustain = ~sustain ?? {
abs(~numFrames * (~repeats ? 1).floor.max(1) / (~sampleRate * averagePlaybackRate.abs))
}; // todo: if sustain is given, find next crossings
};

~dur ?? {
~dur = if(~legato.isNil) { ~sustain } { ~sustain / ~legato };
if(~dur.isArray) { ~dur = ~dur[0] };
if(~dur < 0.0001) { ~type = \rest }; // this is ad hoc
}
}
};

}
}


plot { |index = 0, length = 1|
^wavesets.plot(index, length, buffer.sampleRate)
}
Expand Down Expand Up @@ -235,6 +247,34 @@ WavesetsEvent : AbstractWavesetsEvent {
};
}

getDFT { |index, num, method, action|

var real, imag, cosTable, complex;
var start, numFrames, size, func;
#start, numFrames = this.wavesets.frameFor(index, num, false);
size = numFrames;

method = method ? 'czt';

func = { |arr|

if(arr.size != size) { arr = arr.resamp1(size) };
real = arr.as(Signal);
imag = Signal.newClear(size);
cosTable = Signal.fftCosTable(size);

complex = dft(real, imag, method);

action.value(complex, real, imag);
};

if(buffer.server.isLocal) {
this.buffer.loadToFloatArray(start, numFrames, func)
} {
this.buffer.getToFloatArray(start, numFrames, 0.01, 3, func)
};
}


*prepareSynthDefs {

Expand All @@ -249,16 +289,39 @@ WavesetsEvent : AbstractWavesetsEvent {
SynthDef(\wvst1gl, { | out = 0, buf = 0, startFrame = 0, numFrames = 441, rate = 1, rate2 = 1, sustain = 1,
amp = 0.1, pan, interpolation = 2 |
var rateEnv = Line.ar(rate, rate2, sustain) * sign(numFrames);
var phasor = Phasor.ar(0, BufRateScale.ir(buf) * rateEnv, 0, abs(numFrames)) + startFrame;
// var phasor = Phasor.ar(0, BufRateScale.ir(buf) * rateEnv, 0, abs(numFrames)) + startFrame;
var sweep = Sweep.ar(0, BufRateScale.ir(buf) * rateEnv * sign(numFrames) * SampleRate.ir);
var phasor = sweep.wrap(0, abs(numFrames)) + startFrame;
var env = EnvGen.ar(Env([amp, amp, 0], [sustain, 0]), doneAction: 2);
var snd = BufRd.ar(1, buf, phasor, 1, interpolation) * env;

OffsetOut.ar(out, Pan2.ar(snd, pan));
}, \ir.dup(10)).add;

}
//
SynthDef(\wvst2, { | out = 0, buf = 0, startFrame = 0, numFrames = 441, rate = 1, rate2 = 1, sustain = 1, amp = 0.1, interpolation = 2, envBuf = 1, pos = 0|
var rateEnv = Line.ar(rate, rate2, sustain) * sign(numFrames);
//var phasor = Phasor.ar(0, BufRateScale.ir(buf) * rateEnv, 0, abs(numFrames)) + startFrame;
var sweep = Sweep.ar(0, BufRateScale.ir(buf) * rateEnv * sign(numFrames) * SampleRate.ir);
var phasor = sweep.wrap(0, abs(numFrames)) + startFrame;
var env = EnvGen.ar(Env([1, 1, 0], [sustain, 0]), doneAction: 2);
var snd = BufRd.ar(1, buf, phasor, 1, interpolation) * env * amp;

OffsetOut.ar(out, snd);
}, \ir.dup(11)).add;

SynthDef(\wvst2glenv, { | out = 0, pan = 0, buf = 0, startFrame = 0, numFrames = 441, rate = 1, rate2 = 1, sustain = 1, amp = 0.1, interpolation = 2, envBuf = 1|
var rateEnv = Line.ar(rate, rate2, sustain) * sign(numFrames);
// var phasor = Phasor.ar(0, BufRateScale.ir(buf) * rateEnv, 0, abs(numFrames)) + startFrame;
var sweep = Sweep.ar(0, BufRateScale.ir(buf) * rateEnv * sign(numFrames) * SampleRate.ir);
var phasor = sweep.wrap(0, abs(numFrames)) + startFrame;
var env = Osc1.ar(envBuf, sustain);
var snd = BufRd.ar(1, buf, phasor, 1, interpolation) * env * amp;
OffsetOut.ar(out, Pan2.ar(snd,pan));
}, \ir.dup(11)).add;


}

}

Expand Down
Empty file modified classes/WavesetsEventMultiChannel.sc
100644 → 100755
Empty file.
Empty file modified classes/extEnvironment.sc
100644 → 100755
Empty file.
Empty file modified classes/extTutorial.sc
100644 → 100755
Empty file.
Empty file modified intro.scd
100644 → 100755
Empty file.
Loading