Load and Play a Buffer in one step?

Hi there-

I had a question about best practices in loading and playing a buffer.

Essentially, I’ve made a single DragSink GUI element that I’d like to load an audio file into and have it start playing. I understand that it takes a few seconds, on average, between loading a buffer and starting a Synth.

Is the best approach to have the DragSink reference a function with a built-in Routine that executes the steps with some gap time between them? Or is there a better approach?

Just use the action function in methods like Buffer.read.

1 Like

As @Spacechild1 says, use Buffer.read but you also need to put this in a routine with s.sync to wait for the buffer to load. On my machine it takes about 4ms to load a buffer of a couple of seconds.

(
{
	var t = Main.elapsedTime;
	b = Buffer.read(s,  ...path to your buffer ....);
	s.sync;
	(Main.elapsedTime - t).postln;
	b.play
}.fork
)
1 Like

I think he is actually saying to use the action inside Buffer.read:

b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav", action: {|buf|
	buf.play
});

which executes when the buffer is done loading. Both approaches have their perks.

Sam

@Sam_Pluta Yes. I was too lazy to type it out :slight_smile:

Yes, that is shorter and better:)