PlayerSocket
a voice that is able to host and switch between different players.
Players can be loaded, prepared and spawned without stopping the PlayerSocket.
Players are played using an EnvelopedPlayer so that when the socket releases the voice (to end it or to switch to the next incoming player being played in the socket) the outgoing player is released cleanly. The EnvelopedPlayer also protects against NaN, inf and de-normalized floats, so if anything blows up in the channel it will not propgate up the mixer chain.
the default releaseTime is 0.0 which will stop immediately.
*new(rate,numChannels,round)
rate - all players should be the same rate
numChannels - all players should have the same numChannels
round - for qspawnPlayer
preparePlayer(aPlayer)
prepareAndSpawn(aPlayer,releaseTime)
spawnPlayer(aPlayer)
if you have already prepared the player
qspawnPlayer(aPlayer,releaseTime)
spawn at the next clock division
releaseVoice(releaseTime)
source = aPlayer
(
q = Patch({ Saw.ar(40.midicps) * 0.05 });
r = Patch({ Saw.ar(52.midicps) * 0.05 });
p = PlayerSocket.new(\audio,1);
p.play;
)
// then get the socked to alternately spawn q and r
p.prepareAndQSpawn(q,0.1);
p.prepareAndQSpawn(r,0.1);
p.prepareAndQSpawn(q,0.1);
p.prepareAndQSpawn(r,0.1);
(
p.prepareAndSpawn(
Patch({ arg freq=400,gate=1.0;
Saw.ar(freq) * EnvGen.kr(Env.adsr(0.1,2.0,0.3,2.0),gate) * 0.1
},[
rrand(38,70).midicps,
KrNumberEditor(1.0,\gate)
]),
1.0
)
)
// the current player in the socket is set to : p.source
p.releaseVoice(1.0);
//we are asleep now
p.isSleeping;
p.isPlaying;
p.free;
p.isSleeping;
p.isPlaying;
p.insp
Testing short time intervals
(
q = Patch({ Saw.ar(600) * 0.2 });
r = Patch({ Saw.ar(800) * 0.2 });
p = PlayerSocket.new(\audio,1);
p.play;
Routine({
2.0.wait;
32.do({
rrand(0.01,0.2).wait;
p.prepareAndSpawn([r,q].choose,rrand(0.01,1.0));
});
2.0.wait;
p.release;
4.0.wait;
p.stop;
1.0.wait;
p.free;
}).play(AppClock)
)
see also PlayerPool which is a subclass of this
As an input to a Patch
(
q = Patch({ Saw.ar * 0.2 });
r = Patch({ Saw.ar(800) * 0.2 });
p = PlayerSocket.new(numChannels: 1);
e = Patch({ arg audio; RLPF.ar(audio,200) },[ p ]);
e.play;
)
p.prepareAndSpawn(q);
p.prepareAndSpawn(r);
p.prepareAndSpawn(q);
p.prepareAndSpawn(r);
// if you know that you have prepared it
p.spawnPlayer(q);
q.readyForPlay
p.spawnPlayer(r);
p.releaseVoice
p.insp
e.insp
p.synthArg
e.free;