Last active
February 13, 2019 21:36
-
-
Save earjuice/87b7bcb84d29a77971492a1deb388f9e to your computer and use it in GitHub Desktop.
Cinder NDI audio Sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//in header | |
CinderNDIaudioSenderRef ndiSendRef; | |
//in cpp | |
//use as regular cinder audio chain but set a name for devices to distinguish. Also works with multichannel. | |
ndiSendRef = ctx->makeNode(new CinderNDIaudioSender("ciNDIAudio", ci::audio::Node::Format().channels(2))); | |
ndiSendRef->setName("ci_NDI_Audio"); | |
console() << ndiSendRef->getName() << " has " << 2 << " channels and is initialized" << std::endl; | |
inNode >> ndiSendRef >> ctx->getOutput(); | |
ctx->enable(); | |
console() << "ndiSendRef " << ndiSendRef->getName() << " sampleRate " << ndiSendRef->getSampleRate() << " getFramesPerBlock " << ndiSendRef->getFramesPerBlock() << " numChan " << ndiSendRef->getNumChannels() << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "CinderNDIaudioSender.h" | |
#include <Processing.NDI.Recv.h> | |
CinderNDIaudioSender::CinderNDIaudioSender( const std::string name, const Format &format ) | |
: mName( name ) , Node(format) | |
{ | |
if( ! NDIlib_is_supported_CPU() ) { | |
ci::app::Platform::get()->console() << "Failed to initialize NDI because of unsupported CPU!" << std::endl; | |
} | |
if( ! NDIlib_initialize() ) { | |
ci::app::Platform::get()->console() << "Failed to initialize audoi NDI!" << std::endl; | |
} | |
else ci::app::Platform::get()->console() << "NDI Initialized" << std::endl; | |
mNdiInitialized = true; | |
setup(); | |
if (getChannelMode() != ChannelMode::SPECIFIED) | |
{ | |
setChannelMode(ChannelMode::SPECIFIED); | |
setNumChannels(format.getChannels());//defaults to 2 | |
//setSampleRate(128); | |
} | |
} | |
CinderNDIaudioSender::~CinderNDIaudioSender() | |
{ | |
if( mNdiSender ) { | |
NDIlib_send_destroy( mNdiSender ); | |
} | |
NDIlib_destroy(); | |
mNdiInitialized = false; | |
} | |
void CinderNDIaudioSender::setup() | |
{ | |
if( mNdiInitialized ) { | |
NDIlib_send_create_t NDI_send_create_desc = { mName.c_str(), nullptr, false, false }; | |
mNdiSender = NDIlib_send_create( &NDI_send_create_desc ); | |
} | |
} | |
void CinderNDIaudioSender::process(ci::audio::Buffer *buf) | |
{ | |
//if (buf!=nullptr) { | |
if (NDIlib_send_get_no_connections(mNdiSender, 0)) { | |
NDIlib_tally_t NDI_tally; | |
NDIlib_send_get_tally(mNdiSender, &NDI_tally, 0); | |
NDIlib_audio_frame_v2_t NDI_audio_frame; | |
NDI_audio_frame.sample_rate = getSampleRate(); | |
NDI_audio_frame.no_channels = buf->getNumChannels(); | |
NDI_audio_frame.no_samples =buf->getNumFrames(); | |
NDI_audio_frame.p_data = buf->getData(); | |
NDI_audio_frame.channel_stride_in_bytes = buf->getNumFrames() * sizeof(float); | |
const NDIlib_audio_frame_v2_t afNdi = NDI_audio_frame; | |
NDIlib_send_send_audio_v2 (mNdiSender, &afNdi); | |
} | |
//} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <memory> | |
#include <string> | |
#include "cinder/app/App.h" | |
#include "cinder/app/AppBase.h" | |
#include "cinder/audio/Node.h" | |
#include "cinder/audio/Context.h" | |
#include<Processing.NDI.Lib.h> | |
typedef std::shared_ptr<class CinderNDIaudioSender> CinderNDIaudioSenderRef; | |
class CinderNDIaudioSender : public ci::audio::Node { | |
public: | |
CinderNDIaudioSender( const std::string name , const Format &format = Format()); | |
~CinderNDIaudioSender(); | |
void setup(); | |
void process(ci::audio::Buffer *buf); | |
private: | |
bool mNdiInitialized = false; | |
NDIlib_send_instance_t mNdiSender; | |
std::string mName; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment