Skip to content

Instantly share code, notes, and snippets.

@ThomasLengeling
Last active December 9, 2015 03:51
Show Gist options
  • Save ThomasLengeling/dd0ec421898cf323afb2 to your computer and use it in GitHub Desktop.
Save ThomasLengeling/dd0ec421898cf323afb2 to your computer and use it in GitHub Desktop.
struct Track {
ci::audio::BufferPlayerNodeRef bufferPlayer;
ci::audio::GainNodeRef gain;
ci::audio::MonitorNodeRef monitor;
ci::audio::Pan2dNodeRef pan;
ci::audio::ChannelRouterNodeRef mChannelRouterNode;
ci::audio::OutputDeviceNodeRef multichannelOutputDeviceNode;
Track(ci::audio::BufferPlayerNodeRef bufferPlayer)
: bufferPlayer(bufferPlayer)
{
auto context = ci::audio::Context::master();
gain = context->makeNode(new ci::audio::GainNode(1.0));
monitor = context->makeNode(new ci::audio::MonitorNode);
pan = context->makeNode(new ci::audio::Pan2dNode());
mChannelRouterNode = context->makeNode( new ci::audio::ChannelRouterNode( ci::audio::Node::Format().channels( NUM_OUTPUS ) ) );
//pan->setStereoInputModeEnabled();
ci::audio::DeviceRef deviceWithMaxOutputs;
for( const auto &dev : ci::audio::Device::getDevices() ) {
if( ! deviceWithMaxOutputs || deviceWithMaxOutputs->getNumOutputChannels() < dev->getNumOutputChannels() )
deviceWithMaxOutputs = dev;
}
auto multichannelOutputDeviceNode = context->createOutputDeviceNode( deviceWithMaxOutputs, ci::audio::Node::Format().channels( NUM_OUTPUS ) );
context->setOutput(multichannelOutputDeviceNode);
}
bool isFinished(){
return (!bufferPlayer->isEnabled() && !bufferPlayer->isLoopEnabled());
}
void connect(ci::audio::GainNodeRef masterGain) {
auto context = ci::audio::Context::master();
bufferPlayer >> monitor >> gain >> pan >> masterGain >> mChannelRouterNode >>context->getOutput();
}
void disconnect() {
gain->disconnectAll();
monitor->disconnectAll();
pan->disconnectAll();
bufferPlayer->disconnectAll();
mChannelRouterNode->disconnectAll();
// multichannelOutputDeviceNode->disconnectAll();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment