Ejemplo n.º 1
0
void Simulation::setOutputDevice(int index, int channels, float minLatency, float startLatency, float maxLatency) {
	if(index < -1) ERROR(Lav_ERROR_RANGE, "Index -1 is default; all other negative numbers are invalid.");
	if(output_device) {
		output_device->stop();
	}
	std::lock_guard<std::recursive_mutex> g(mutex);
	auto factory = getOutputDeviceFactory();
	if(factory == nullptr) ERROR(Lav_ERROR_CANNOT_INIT_AUDIO, "Failed to get output device factory.");
	auto sptr = std::static_pointer_cast<Simulation>(shared_from_this());
	std::weak_ptr<Simulation> wptr(sptr);
	int blockSize=getBlockSize();
	auto cb =[wptr, blockSize](float* buffer, int channels)->void {
		auto strong =wptr.lock();
		if(strong==nullptr) memset(buffer, 0, sizeof(float)*blockSize*channels);
		else {
			std::lock_guard<Simulation> guard(*strong);
			strong->getBlock(buffer, channels);
		}
	};
	std::shared_ptr<audio_io::OutputDevice> dev;
	try {
		dev =factory->createDevice(cb, index, channels, getSr(), getBlockSize(), minLatency, startLatency, maxLatency);
		if(dev == nullptr) ERROR(Lav_ERROR_CANNOT_INIT_AUDIO, "Device could not be created.");
	}
	catch(std::exception &e) {
		ERROR(Lav_ERROR_CANNOT_INIT_AUDIO, e.what());
	}
	output_device=dev;
}
Ejemplo n.º 2
0
void Simulation::setOutputDevice(int index, int channels, int mixahead) {
	if(index < -1) ERROR(Lav_ERROR_RANGE, "Index -1 is default; all other negative numbers are invalid.");
	auto factory = getOutputDeviceFactory();
	if(factory == nullptr) ERROR(Lav_ERROR_CANNOT_INIT_AUDIO, "Failed to get output device factory.");
	auto sptr = std::static_pointer_cast<Simulation>(shared_from_this());
	std::weak_ptr<Simulation> wptr(sptr);
	int blockSize=getBlockSize();
	auto cb =[wptr, blockSize](float* buffer, int channels)->void {
		auto strong =wptr.lock();
		if(strong==nullptr) memset(buffer, 0, sizeof(float)*blockSize*channels);
		else {
			std::lock_guard<Simulation> guard(*strong);
			strong->getBlock(buffer, channels);
		}
	};
	auto dev =factory->createDevice(cb, index, channels, getSr(), getBlockSize(), mixahead);
	if(dev == nullptr) ERROR(Lav_ERROR_CANNOT_INIT_AUDIO, "Device could not be created.");
	output_device=dev;
}