Multichannel onset detection?

hi all

I have 8 objects with contact mics and I want to find out when two of them collide with each other. Eg, object in channel 2 and object in channel 6 hit each other.

I thought I could use multichannel expansion with SoundIn.ar([0,1,2,3,4,5,6,7]) and that Onsets would report sometime like [0,0,0,1,0,0,1,0] with the onset situation of each channel but instead I am getting [1,1,1,1,1,1,1,1] being sent when any onset is detected. I am using sendReply to send the data back to the lang.

This is the code

o = Server.default.options;
o.numInputBusChannels = 8;
o.numOutputBusChannels = 8;

s.boot;

s.meter(8,8);

SynthDef(\onsets, {|gain=1, threshold=0.1, relaxtime=0.05|
	var onsets, signals, levels;
	signals = SoundIn.ar([0,1,2,3,4,5,6,7]) * gain;
	levels = WAmp.kr(signals, 0.04);
	onsets = Onsets.kr(FFT(LocalBuf(2048), signals, wintype:1), threshold, \rcomplex,
		relaxtime:relaxtime, floor:0.1, mingap:1, medianspan:11, whtype:1, rawodf:0);
	SendReply.kr(onsets, '/onset', [Sweep.ar.asArray++onsets++levels] );
}).add;

p.free;
p = Synth(\onsets);

OSCdef(\txalaonsetOSCdef).free;
OSCdef(\txalaonsetOSCdef, {|msg, time, addr, recvPort|
	msg.postln;
}, '/onset');

thanks

enrike

Hello, I believe that you need an array of buffers, but currently all 8 channels are being saved into the same one. I can’t test this because I don’t have anything handy to feed signal into my soundcard with, but I do know that FFT doesn’t support multichannel buffers.

SynthDef(\onsets, {|gain=1, threshold=0.1, relaxtime=0.05|
	var onsets, signals, levels;
	signals = SoundIn.ar([0,1,2,3,4,5,6,7]) * gain;
	levels = WAmp.kr(signals, 0.04);
	onsets = Onsets.kr(FFT(Array.fill(signals.size, { LocalBuf(2048) }), signals, wintype:1), threshold, \rcomplex,
		relaxtime:relaxtime, floor:0.1, mingap:1, medianspan:11, whtype:1, rawodf:0);
	SendReply.kr(onsets, '/onset', [Sweep.ar.asArray++onsets++levels] );
}).add;

hi. I just quickly tested it a your solution works perfectly as far as I can se. Now I get

0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0

when channels 5 and 7 are activated.

thanks!