How to record sound produced using Pbind?

Dear users,

I have recorded sound as in code 1. Now I am trying to record sound as in code 2 using Pbind. However, the result of code 2 does not contain any audio data. Also, when I record sound from code 2 using the record function in the server menu and using the record button in the server window evoked using ```s.makeGui``, no data is recorded. What are my mistakes? I appreciate your feedback and help.

// code 1:

(
s.waitForBoot{
	var title, file;
	title = "configured";
	file = thisProcess.nowExecutingPath.dirname +/+ title ++ ".wav";
	SynthDef(\alarm, { |freq = 440|
		var signal, filter, env;
		env = Env.perc(0.01, 0.25).kr;
		signal = BrownNoise.ar * env;
		filter = { |source, freq = 440, bwr = 0.001, amp = 1|
			Resonz.ar(source, freq, bwr, amp)
		};
		signal = filter.(signal, freq, 0.001, 9);
		FreeSelf.kr(TDelay.kr(env, 3));
		signal = filter.(signal, freq, 0.5);
		OffsetOut.ar(0, signal)
	}
	).add;
	s.recHeaderFormat = "wav";
	s.prepareForRecord(file, numChannels: 1);
	s.sync; // without this line, an error occurs.
	s.record;
	[2, 5, 10].do{
		|i, idx|
		var freq = (i + 60 + (12 * 2) - 1).midicps,
		rls = [0.2, 0.2, 3];
		s.sendBundle(0.2, ["/s_new", "alarm", -1, 0, 1, "freq", freq]);
		rls[idx].wait;
	};
	s.stopRecording;
	file.openOS;
	Platform.case(
		\osx,       { ("open -a Audacity" + file.quote).unixCmd; },
		\windows,   { ("start" + "".quote
			+ "C:/Program Files (x86)/audacity/Audacity.exe".quote
			+ file.quote).unixCmd;}
	);
}
)
code 2:
//
(
s.waitForBoot{
	var title, file, duration;
	title = "configured";
	file = thisProcess.nowExecutingPath.dirname +/+ title ++ ".wav";
	duration = 5;
	SynthDef(\alarm, { |freq = 440|
		var signal, filter, env;
		env = Env.perc(0.01, 0.25).kr;
		signal = BrownNoise.ar * env;
		filter = { |source, freq = 440, bwr = 0.001, amp = 1|
			Resonz.ar(source, freq, bwr, amp)
		};
		signal = filter.(signal, freq, 0.001, 9);
		FreeSelf.kr(TDelay.kr(env, 3));
		signal = filter.(signal, freq, 0.5);
		OffsetOut.ar(0, signal)
	}
	).add;
	s.sync; ; // without this line, an error occurs.
	Pbind(
		\instrument, \alarm,
		\freq, Pseq([2, 5, 10] + 83).midicps,
		\dur, Pseq([0.2, 0.2, 3])
	).record(file, "wav", "float", 1, duration);
	duration.wait;
	file.openOS;
	Platform.case(
		\osx,       { ("open -a Audacity" + file.quote).unixCmd; },
		\windows,   { ("start" + "".quote
			+ "C:/Program Files (x86)/audacity/Audacity.exe".quote
			+ file.quote).unixCmd;}
	);
}
)

How recent is your SC?

Pattern:record omitted the bufnum parameter when launching the recording synth. This was fixed in June 2022: pbind: fix pbind not recording by madredeuz · Pull Request #5793 · supercollider/supercollider · GitHub So you should use a version after this date.

hjh

Thanks for your quick reply. I have tested it using SuperCollider 3.13.0 under MacOS (my machine is M1, but the build is for intel), using SuperCollider 3.13.0 under Windows in a parallel desktop virtual machine on the same machine.

Actually it’s not that though.

Pattern:record requires an “out” argument – you cannot hardcode bus 0 if you want to use Pattern:record.

Look at the OSC commands:

// preparing the buffer
[ "/b_alloc", 0, 32768, 1, 0 ]
[ "/b_write", 0, "/home/dlm/configured.wav", "wav", "float", 0, 0, 1, 0 ]

// monitor the recording private bus
[ "#bundle", 16711830826008128031, 
  [ 21, 1010, 1, 1009 ],
  [ 9, "system_link_audio_1", 1011, 1, 1010, "out", 0, "in", 4, "level", 1, "fadeTime", 0.02, "vol", 1 ]
]

// recording synth: note -- reading bus 4! (Or other allocated bus number)
[ "#bundle", 16711830826194161120, 
  [ 9, "temp__3", 1012, 3, 1009, "bufnum", 0, "bus", 4 ]
]

// but audio synths don't refer to `"out", 4`, so there's the problem
[ "#bundle", 16711830826194161120, 
  [ 9, "alarm", 1013, 0, 1, "freq", 1108.73 ]
]

hjh

1 Like

Thank you! I resolved the problem!

(
s.waitForBoot{
	var title, file, duration;
	title = "configured";
	file = thisProcess.nowExecutingPath.dirname +/+ title ++ ".wav";
	duration = 5;
	SynthDef(\alarm, { |out=0, freq = 440| // changed
		var signal, filter, env;
		env = Env.perc(0.01, 0.25).kr;
		signal = BrownNoise.ar * env;
		filter = { |source, freq = 440, bwr = 0.001, amp = 1|
			Resonz.ar(source, freq, bwr, amp)
		};
		signal = filter.(signal, freq, 0.001, 9);
		FreeSelf.kr(TDelay.kr(env, 3));
		signal = filter.(signal, freq, 0.5);
		OffsetOut.ar(out, signal)
	}
	).add;
	s.sync;
	Pbind(
		\instrument, \alarm,
		\freq, Pseq([2, 5, 10] + 83).midicps,
		\dur, Pseq([0.2, 0.2, 3])
	).record(file, "wav", "float", 1, duration);
	duration.wait;
	file.openOS;
	Platform.case(
		\osx,       { ("open -a Audacity" + file.quote).unixCmd; },
		\windows,   { ("start" + "".quote
			+ "C:/Program Files (x86)/audacity/Audacity.exe".quote
			+ file.quote).unixCmd;}
	);
}
)