当前位置: 首页>>代码示例>>C++>>正文


C++ UdpSocket::isOk方法代码示例

本文整理汇总了C++中UdpSocket::isOk方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpSocket::isOk方法的具体用法?C++ UdpSocket::isOk怎么用?C++ UdpSocket::isOk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UdpSocket的用法示例。


在下文中一共展示了UdpSocket::isOk方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

/**
 * Fetches muse-io udp packets from port localhost:4545 and reads OSC paths:
 * /muse/elements/delta_relative
 * /muse/elements/theta_relative
 * /muse/elements/alpha_relative
 * /muse/elements/beta_relative
 * /muse/elements/gamma_relative
 *
 * Calculates mean delta, theta, alpha, beta and gamma values (and st.dev.)
 * from all channels and which /muse/elements/is_good value is >= 0.5.
 * If there are no good values at all, reports 0.5 value and maximum st.dev.
 * (of uniform distribution between [0,1])
 *
 * Also measures:
 * /muse/elements/experimental/concentration
 * /muse/elements/experimental/mellow
 */
int main(int argc, char** argv)
{
	const unsigned int port = 4545;

	std::cout << "MUSE TEST OSC (UDP PORT 4545) LISTENER" << std::endl;
	fflush(stdout);

	UdpSocket sock;
	sock.bindTo(port);

	if(!sock.isOk()) return -1; // failure [retry?]

	PacketReader pr;
	PacketWriter pw;

	std::vector<int> connectionQuality;
	bool hasConnection = false;
	float delta = 0.0f, theta = 0.0f, alpha = 0.0f, beta = 0.0f, gamma = 0.0f;

	while(sock.isOk()){

		if(hasConnection){
			float q = 0.0f;
			for(auto qi : connectionQuality)
				if(qi > 0) q++;
			q = q / connectionQuality.size();

			// printf("EEQ: D:%.2f T:%.2f A:%.2f B:%.2f G:%.2f [QUALITY: %.2f]\n", delta, theta, alpha, beta, gamma, q);
			printf("EEQ POWER: %.2f [QUALITY %.2f]\n",
					log(exp(delta)+exp(theta)+exp(alpha)+exp(beta)+exp(gamma)), q);

			fflush(stdout);
		}

		if(sock.receiveNextPacket(30)){
			pr.init(sock.packetData(), sock.packetSize());
			Message* msg;
			while(pr.isOk() && ((msg = pr.popMessage()) != 0)){
				Message::ArgReader r = msg->match("/muse/elements/is_good");

				if(r.isOk() == true){ // matched
					// there are 4 ints telling connection quality
					std::vector<int> quality;

					while(r.nbArgRemaining()){
						if(r.isInt32()){
							int32_t i;
							r = r.popInt32(i);
							quality.push_back((int)i);
						}
						else{
							r = r.pop();
						}
					}

					if(quality.size() > 0){
						connectionQuality = quality;
					}

					bool connection = false;

					for(auto q : quality)
						if(q > 0) connection = true;

					hasConnection = connection;
				}

				// gets relative frequency bands..

				r = msg->match("/muse/elements/delta_absolute");
				if(r.isOk()){
					float f1, f2, f3, f4;
					if(r.popFloat(f1).popFloat(f2).popFloat(f3).popFloat(f4).isOkNoMoreArgs()){
						std::vector<float> v;
						v.push_back(f1); v.push_back(f2); v.push_back(f3); v.push_back(f4);

						// calculates mean according to connection quality
						float mean = 0.0f;
						float samples = 0.0f;

						for(unsigned int i=0;i<connectionQuality.size() && i<v.size();i++){
							if(connectionQuality[i] > 0){
								mean += exp(v[i]);
//.........这里部分代码省略.........
开发者ID:cslr,项目名称:resonanz,代码行数:101,代码来源:muse-io-test.cpp


注:本文中的UdpSocket::isOk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。