Re: How to send magnitude data from FFT to buffer to client?

[email protected] Fri, 4 Jun 2021 21:56:57 +0200
Newsgroups gmane.comp.audio.supercollider.user
Message-ID <[email protected]>
iirc writing to busses with Out.kr was more efficient than having many many SendReply.

but do you need the Routine/SendReply at all?  can't you just use the busses directly on the server?

here's a trimmed down example of what i mean...
(
var buffersize= 2048;
var buffersize2= buffersize.div(2);
s.options.memSize= 8192*2;
s.waitForBoot{
	c= Bus.control(s, buffersize2);
	SynthDef(\avTrk, {|in= 0, t_trig= 0, amp= 1, bus|
		var z= Mix(In.ar(in, 2)*amp);
		var chain= FFT(LocalBuf(buffersize), z);
		Array.fill(buffersize2, {|i|
			var a= Unpack1FFT(chain, buffersize, i);
			var d= Demand.kr(chain>=0, 0, a);
			Out.kr(bus+i, d.min(1));
		});
	}).load;
	s.sync;
	Synth(\avTrk, [\in, 20, \amp, 0.3, \bus, c]);
	CmdPeriod.doOnce({c.free});
};
)

//some source sound (here freq sweep)
a= {SinOsc.ar(LFSaw.kr(0.05).exprange(200, 2000), 0, 0.5)}.play(outbus:20);

//listen to magnitudes from bin 1 and bin 50
b= {SinOsc.ar([400,600],0,[In.kr(c.index+1), In.kr(c.index+50)])*0.5}.play;

//the loud click is when the source sweep jumps back

//visualise the first 50 bins
s.scope(50, c.index, rate:\control)


note that there are more efficient ways to do this if you don't need all the bins.
_f


> 4 juni 2021 kl. 21:26 skrev [email protected]:
> 
> Yes, it is probably what I needs.
> 
> How do you think, is it possible to use SendReply instead of routine?
> 
> On 04.06.2021 20:44, [email protected] wrote:
>> here's an example using UnpackFFT1 and Demand to extract magnitudes from a spectra and put that on a multichannel (1024) control rate buss.  maybe that's something you can adapt for your needs.
>> http://sccode.org/1-4Ty
>> see UnpackFFT1 helpfile on how to get the phases too.
>> _f
>>> 4 juni 2021 kl. 19:21 skrev [email protected]:
>>> 
>>> Data comes from FFT.
>>> 
>>> So only way is make a routine that will turn buffer into array and write data to bus?
>>> 
>>> This way I will need to update busses 48000 times a second to be accurate.
>>> 
>>> On 04.06.2021 17:39, [email protected] wrote:
>>>> Since fft uses a buffer, you can use loadToFloatArray:
>>>> b.loadToFloatArray(action:{|array| a = array})
>>>> Is this from FFT or PV_RecordBuf?
>>>> Sam
>>>>> On Jun 4, 2021, at 4:22 PM, [email protected] wrote:
>>>>> 
>>>>> Hello!
>>>>> 
>>>>> I want to use magnitudes and phases data I got after using FFT on microphone input to modulate synth instances.
>>>>> 
>>>>> At first, I want to sort FFT bins by magnitude power, take first N
>>>>> bins, normalize data, and then send it to N * 2 Busses (N for magnitudes and N for phases) these Busses I want to use for modulating synths with .asMap() method.
>>>>> 
>>>>> I tried to write this data to control rate Bus inside .pvcollect,
>>>>> but it is not possible because Out.kr() needs a control rate signal.
>>>>> 
>>>>> Is there any possibility to this or some workaround how can I use FFT
>>>>> data for synths modulation?
>>>>> 


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/