Example #1
0
void Event::wait(double timeout) {
  start();
  _stream.impl->update(std::string("\x00", 1), nullptr);
  while (!_stream()) {
    bool origValue = _stream();
    _stream.wait(timeout);
    if (timeout >= 0 && _stream() == origValue)
      // Value did not change, must have timed out
      return;
  }
}
	//-----------------------------------------------------------------------
	void ParticleScriptSerializer::writeLine(
		const String& s0,
		short indentation0)
	{
		String base = StringUtil::BLANK;
		_appendTabbedString(0, base, s0, indentation0);
		base += "\n";
		_stream(base);
	}
Example #3
0
/*/////////////////////////////////////////////////////////////////*/
void OgreOggStreamSound::_prebuffer() {
  if(mSource == AL_NONE) return;

  int i = 0;
  while(i < NUM_BUFFERS) {
    if(_stream(mBuffers[i]))
      alSourceQueueBuffers(mSource, 1, &mBuffers[i++]);
    else
      break;
  }
}
Example #4
0
    void ZMQtClient_P::request( const QString &type, const QByteArray &data )
    {
        QByteArray _data;
        QDataStream _stream(&_data, QIODevice::WriteOnly);
        _stream.writeBytes(type.toUtf8().data(), type.toUtf8().size());
        _stream.writeBytes(data.data(), data.size());

        QByteArray _zipData = qCompress(_data);

        send(_zipData);
    }
Example #5
0
static bool _playback(music_context_t* context) {

    if (_playing(context)) return true;

    for (int i = 0; i < NUM_BUFFERS; i++) {
        if (!_stream(context, context->buffers[i])) return false;
    }

    alSourceQueueBuffers(context->source, NUM_BUFFERS, context->buffers);
    alSourcePlay(context->source);

    return true;

}
GestureHandler::GestureHandler()
: _streaming(false), _init_error(false),
_last_gesture(PXCGesture::Gesture::LABEL_ANY)
{
    QObject::connect(&_fps_timer, SIGNAL(timeout()), this, SLOT(_stream()));

    _pipeline.EnableImage(PXCImage::COLOR_FORMAT_RGB24);
    _pipeline.EnableGesture();

    if (!_pipeline.Init())
    {
        std::cout << "GestureHandler::GestureHandler !!! Failed initializing pipeline." << std::endl;
        _init_error = true;
    }
}
Example #7
0
static bool _update(music_context_t* context) {

    int processed;
    bool active = true;
    alGetSourcei(context->source, AL_BUFFERS_PROCESSED, &processed);

    if (processed >= 0)
        while (processed--) {
            sound_buffer_t buffer;
            alSourceUnqueueBuffers(context->source, 1, &buffer);
            active = _stream(context, buffer);
            alSourceQueueBuffers(context->source, 1, &buffer);
        }

    return active;

}
	//-----------------------------------------------------------------------
	void ParticleScriptSerializer::writeLine(
		const String& s0, 
		const String& s1, 
		const String& s2,
		const String& s3,
		short indentation0,
		short indentation1,
		short indentation2,
		short indentation3)
	{
		String base = StringUtil::BLANK;
		_appendTabbedString(0, base, s0, indentation0);
		_appendTabbedString(1, base, s1, indentation1);
		_appendTabbedString(2, base, s2, indentation2);
		_appendTabbedString(3, base, s3, indentation3);
		base += "\n";
		_stream(base);
	}
Example #9
0
	/*/////////////////////////////////////////////////////////////////*/
	void OgreOggStreamSound::_updateAudioBuffers()
	{
		if (!isPlaying()) return;

		ALenum state;
		alGetSourcei(mSource, AL_SOURCE_STATE, &state);

		if (state == AL_PAUSED) return;

		// Ran out of buffer data?
		if (state == AL_STOPPED)
		{
			if(mStreamEOF)
			{
				stop();
				
				// Finished callback
				if ( mSoundListener ) 
					mSoundListener->soundFinished(this);
				
				return;
			}
			else
			{
				// Clear audio data already played...
				_dequeue();

				// Fill with next chunk of audio...
				_prebuffer();

				// Play...
				alSourcePlay(mSource);
			}
		}

		int processed;

		alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);

		while(processed--)
		{
			ALuint buffer;
			ALint size, bits, channels, freq;

			alSourceUnqueueBuffers(mSource, 1, &buffer);

			// Get buffer details
			alGetBufferi(buffer, AL_SIZE, &size);
			alGetBufferi(buffer, AL_BITS, &bits);
			alGetBufferi(buffer, AL_CHANNELS, &channels);
			alGetBufferi(buffer, AL_FREQUENCY, &freq);    

			// Update offset (in seconds)
			mLastOffset += ((ALuint)size/channels/(bits/8)) / (ALfloat)freq;
			if ( mLastOffset>=mPlayTime )
			{
				mLastOffset = mLastOffset-mPlayTime;
				
				/**	This is the closest we can get to a loop trigger.
				@remarks 
					If played data size exceeds audio data size trigger callback.
				*/
				if ( mSoundListener ) mSoundListener->soundLooping(this);
			}

			if ( _stream(buffer) ) alSourceQueueBuffers(mSource, 1, &buffer);
		}

		// handle play position change 
		if ( mPlayPosChanged ) 
		{
			_updatePlayPosition();
		}
	}
Example #10
0
bool xXMLLoader::_loadResource(const std::ds_wstring& strResName,xXmlDocument* & pRes , int& ResSize, unsigned int arg)
{
	
	ResSize = 0;
	bool needDeletePRes = false;
	if(pRes == NULL)
	{
		needDeletePRes = true;
		pRes = new xXmlDocument;
	}

	if(XEvol_IsAbsPath(strResName))
	{
		if(pRes->load(strResName.c_str() , arg != 0 ) )
		{
			ResSize = 1;
			return true;
		}
		else
		{
			pRes->unload();
		}			
	}
	else
	{
		ds_wstring full_name;
		int nResItem = (int)this->m_Packages.size();
		for(int i = 0 ; i < nResItem ; i++)
		{
			xResPkgPathItem& item = this->m_Packages[i];
			if(item.m_Package.failed())
			{
				full_name = ds_wstring(item.m_ResDir) + strResName;
				if(pRes->load(full_name.c_str() , arg != 0) )
				{
					ResSize = 1;
					return true;
				}
			}
			else
			{
				full_name = item.m_ResDir + strResName;
				xcomdocstream* pstream = item.m_Package.open_stream(full_name.c_str());
				if(pstream)
				{
					xcdstream _stream(pstream);
					if(pRes->load(_stream , arg != 0 ) )
					{
						ResSize = 1;
						//XEVOL_LOG(eXL_DEBUG_TIPS, L"Load from package, search index = %d name = %s\n",i,strResName.c_str() );
						pstream->Release();
						return true;
					}
				}

			}

		}
	}


	//如果是创建出来的就删除掉
	if(needDeletePRes)
	{
		delete pRes;
		pRes = NULL;
	}

	return false;
}
Example #11
0
int main(int argc, char * const argv[])
{
  
  char *host = (char*)"127.0.0.1";
  int port = 3001;
  int device = -1; // for default device
  int c;
  
  opterr = 0;
  
  /* options descriptor */
  static struct option longopts[] = {
    { "help",      no_argument      ,      NULL,           '?' },
    { "list",      no_argument      ,      NULL,           'l' },
    { "host",      required_argument,      NULL,           'h' },
    { "port",      required_argument,      &port,          'p' },
    { "device",    required_argument,      &device,        'd' },
    { "time-out",  required_argument,      NULL,           't' },
    { "osc-path",  required_argument,      NULL,           'o' },
    { NULL,        0,                      NULL,            0  }
  };
  
  while ((c = getopt_long (argc, argv, ":h:p:t:d:l",longopts,NULL)) != -1)
    switch (c)
  {
    case 'h':
      host = optarg;
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'd':
      device = atoi(optarg);
      break;
    case 't':
      timeOut = atoi(optarg)/1000.f;
      break;
    case 'o':
      osc_path = optarg;
      break;
    case 'l':
      listDevices();
      return 0;
    case '?':
      usage();
      return 0;
    case ':':
      switch (optopt) {
        case 'h':
        case 'p':
          fprintf (stderr, "Please specify an ip and port to send to.\n");
          break;
          
        case 't':
          fprintf (stderr, "Please specify a time out value in milliseconds.\n");
          break;
          
        case 'd':
          fprintf (stderr, "-d takes a device index. Use -l to list all available devices.\n");
          break;
          
        default:
          if (isprint (optopt))
            fprintf (stderr, "Unknown option `-%c'.\n", optopt);
          else
            fprintf (stderr,
                   "Unknown option character `\\x%x'.\n",
                   optopt);
          break;
      }
      return 1;
    default:
      usage();
      return 1;
  }
  
  // attach signal handlers
  signal(SIGINT, catch_int);

  
  // Set up OSC
  const int osc_buffer_size = 512;
  char buffer[osc_buffer_size];
  UdpTransmitSocket _sock(IpEndpointName(host,port));
  osc::OutboundPacketStream _stream(buffer,osc_buffer_size);
  OSCSender osc_sender(&_sock,_stream);
  _sock.SetEnableBroadcast(true);
  
  std::clog << "Sending OSC to " << host << " on port " << port << " with path '" << osc_path << "'" << std::endl;
  
  std::clog << "Time for repeated detection is set to " << ((int)(timeOut*1000)) << " milliseconds." << std::endl;
  std::clog << "Samplerate is set to " << SAMPLING_RATE << "Hz" << std::endl;
  
  
  // try to open audio:
  PaError err;
  err = Pa_Initialize();
  if( err != paNoError ) goto error;
  
  DTMFSetup(SAMPLING_RATE, BUFFER_SIZE);
  
  deviceInfo = Pa_GetDeviceInfo((device == -1) ? Pa_GetDefaultInputDevice() : device);
  
  
  /* Open an audio I/O stream. */
  PaStream *stream;
  err = Pa_OpenDefaultStream( &stream, 1, 0,
                             paInt16,
                             SAMPLING_RATE,
                             BUFFER_SIZE,
                             audioCallback,
                             &osc_sender ); // send a pointer to the OSCSender with it
  
  if( err != paNoError ) goto error;
  
  err = Pa_StartStream( stream );
  if( err != paNoError ) goto error;
  
  info = Pa_GetStreamInfo(stream);
  
  std::clog
  << "Audio initialized with:" << std::endl
  << "  Device       " << deviceInfo->name << std::endl
  << "  Latency      " << info->inputLatency << "ms" << std::endl
  << "  Samplerate   " << info->sampleRate << "kHz" << std::endl
  << "  Buffer Size  " << BUFFER_SIZE << "samples" << std::endl;
  
  std::clog << "Read for detection!" << std::endl;
  
  // pause and let the audio thread to the work
  while(running) pause();
  
  // end program
  err = Pa_StopStream( stream );
  if( err != paNoError ) goto error;
  
  err = Pa_CloseStream( stream );
  if( err != paNoError ) goto error;
  
  // Close Audio:
  err = Pa_Terminate();
  
  if( err != paNoError ) {
  error:
    std::cerr <<  "PortAudio error: " <<  Pa_GetErrorText( err ) << std::endl;
    return -1;
  }
  
  return 0;
}
Example #12
0
 static void log(std::ostream* os)  // 0 turns of logging
 {
   _stream() = os;
 }
Example #13
0
 static std::ostream* log()
 {
   return _stream();
 }