std::tuple<PlatformRef, DeviceRef> getFirstPlatformAndDeviceFor(uint32_t device_type) { std::vector<PlatformRef> platformList = CL::Platform::get(); for(auto pf : platformList) { for(auto dev : pf->getDevices()) { if(dev->getType() == device_type) { return std::make_tuple(pf, dev); } } } PlatformRef platform = platformList.front(); DeviceRef device = platform->getDevices().front(); WARN("Could not find platform and device for the given device type: " + Util::StringUtils::toString(device_type) + "\nFallback to " + platform->getName() + "/" + device->getName()); return std::make_tuple(platform, device); }
InputDeviceNodeWebAudio::InputDeviceNodeWebAudio( const DeviceRef &device, const Format &format, const std::shared_ptr<ContextWebAudio> &context ): InputDeviceNode( device, format ), mStreamRef( emscripten::val::undefined() ), mInputStreamAquired( false ), mMediaStream( emscripten::val::undefined() ), mAudioContext( context ) { // initialize stream auto utils = ci::em::helpers::getAudioHelpers(); std::function<void(emscripten::val e)> cb = [this]( emscripten::val e )->void { // save stream reference mStreamRef = e; auto ctx = mAudioContext->getRawContext(); // turn stream we aquired into something consumable by the output. mMediaStream = ctx.call<emscripten::val>( "createMediaStreamSource",mStreamRef ); // signal that we have an input stream. mInputStreamAquired = true; }; // get and check device id / name - if it matches default then pass in blank string. std::string name = device->getName(); if( name == "WebAudioInputDevice" ) { name = ""; } // indicate that this is a native node and thus, needs slightly different processing. //mIsNativeWebNode = true; // initialize stream - returns emscripten::val object mStreamRef = utils.call<emscripten::val>( "loadAudioInput",ci::em::helpers::generateCallback( cb ),val( name ) ); }