Buffer cueSoundFile acts strange?


#1

Hi list/forum,

Can anyone help me to see what is wrong in my code here:

(
s.waitForBoot{
	var playSoundFile;
	var sourceSynth;
	var sourceBuf;
	playSoundFile = {arg path;
		fork {
			var cond = Condition.new;
			var soundFile = SoundFile.openRead(path);
			if(soundFile.notNil, {
				if(sourceBuf.notNil, {
					"Freeing buffer: %".format(sourceBuf).postln;
					sourceBuf.free({arg buf;
						"Buffer freed: %".format(buf).postln;
						cond.test = true;
						cond.signal;
					});
					cond.wait;
				});

				cond.test = false;
				sourceBuf = Buffer.cueSoundFile(s, soundFile.path.asString,
					numChannels: soundFile.numChannels,
					completionMessage: {arg cueBuf;
						"Callback buffer: %".format(cueBuf).postln;
						cond.test = true;
						cond.signal;
					}
				);
				cond.wait;
				"After buffer: %".format(sourceBuf).postln;
			}, {
				"Sound file '%' not found!".format(path).warn;
			});
		};
	};
	Button(bounds: Rect(0, 0, 250, 50))
	.states_([["Load cue buffer"]])
	.action_({arg butt;
		playSoundFile.value(Platform.resourceDir +/+ "sounds/a11wlk01.wav");
	}).front;
};
)

Every time I press the button a buffer with the same buffer number is returned. This is the output:

Callback buffer: Buffer(0, 32768, 1, nil, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
After buffer: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Freeing buffer: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Buffer freed: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Callback buffer: Buffer(0, 32768, 1, nil, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
After buffer: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Freeing buffer: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Buffer freed: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Callback buffer: Buffer(0, 32768, 1, nil, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
After buffer: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Freeing buffer: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Buffer freed: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
Callback buffer: Buffer(0, 32768, 1, nil, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
After buffer: Buffer(0, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)

I was expecting that a new buffer number was generated eveytime, but this doesn’t happen in this code.

The code below shows the intended behaviour:

(
var soundFile = SoundFile.openRead(Platform.resourceDir +/+ "sounds/a11wlk01.wav");
Buffer.cueSoundFile(s, soundFile.path.asString,
	numChannels: soundFile.numChannels
);
)

This outputs:

-> Buffer(1, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
-> Buffer(2, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
-> Buffer(3, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)
-> Buffer(4, 32768, 1, 44100, /private/var/folders/s6/n0v633z10t9fcbd1c7255tj00000gn/T/AppTranslocation/781FBBCC-4189-412B-A0F9-99F71848CA30/d/SuperCollider.app/Contents/Resources/sounds/a11wlk01.wav)