I am working on a Ndef and I would like to store the spectral flatness values in a ring buffer. Then I would like to extract the max and min values from that buffer:
(
Ndef(\bassFeedback, {
var fb=LocalIn.ar(2).tanh;
var chain=FFT(LocalBuf(1024), fb);
var flat=SpecFlatness.kr(chain);
var sampNum=1000;
var ringBuf=LocalBuf(sampNum,2);
var writeBuf=BufWr.kr(flat, ringBuf, Phasor.kr(0,ControlRate.ir/1000,0,sampNum));
var x=SinOsc.ar(
LFNoise0.kr(1/4).exprange(50,80),
fb.abs*SinOsc.ar(
1/8,
[fb[0].abs, fb[1].abs*pi],
1,
fb).range(1,8),
1,
fb
);
LocalOut.ar(x);
// buf.maxSubclassIndex.poll;
x
} * -32.dbamp
).fadeTime_(1).play
)
1st question: is the control rate ring buffer correctly implemented?
2nd question: how to get the max and min values from the ring buffer?
At 44.1 kHz and a 64-sample control block, ControlRate is 689.0625 – divide by 1000 means that it will advance 0.6890625 buffer positions per control block… I’m guessing that’s not what you want?
Thanks, BufMin and BufMax is exactly what I need! I have an issue with the left and right channels though. As far as I understand, FFT doesn’t support multichannel expansion right?
So I can use two chains:
(
Ndef(\bassFeedback, {
var fb=LocalIn.ar(2).tanh;
var chainL=FFT(LocalBuf(1024), fb[0]);
var chainR=FFT(LocalBuf(1024), fb[1]);
var flat=SpecFlatness.kr([chainL,chainR]);
var sampNum=1000;
var ringBuf=LocalBuf(sampNum, 2);
var writeBufL=BufWr.kr(flat, ringBuf, Phasor.kr(0,1,0,sampNum));
var x=SinOsc.ar(
LFNoise0.kr(1/4).exprange(50,80),
fb.abs*SinOsc.ar(
1/8,
[fb[0].abs, fb[1].abs*pi],
1,
fb).range(1,8),
1,
fb
);
LocalOut.ar(x);
BufMin.kr(ringBuf).poll;
x
} * -32.dbamp
).fadeTime_(1).play
)
The values on the second channel don’t seem correct, I wonder why is this the case…
Here, it would be helpful to read the help files for BufMin and BufMax – they explain that these UGens don’t split out the channels. You should use two mono buffers instead of a single stereo buffer.