Exemplo n.º 1
0
bool	AREngine::initHardware(IOService* inProvider)
{
	bool theAnswer = false;
	
	if(IOAudioEngine::initHardware(inProvider))
	{
		IOAudioSampleRate theInitialSampleRate = { 0, 0 };
		UInt32 theNumberChannels = 0;
		
		//	create the streams
		if(CreateStreams(&theInitialSampleRate, &theNumberChannels) && (theInitialSampleRate.whole != 0))
		{
			CreateControls(theNumberChannels);
			
			//	figure out how long each block is in microseconds
			mBlockTimeoutMicroseconds = 1000000 * mBlockSize / theInitialSampleRate.whole;
			
			setSampleRate(&theInitialSampleRate);
			
			// Set the number of sample frames in each buffer
			setNumSampleFramesPerBuffer(mBlockSize * mNumberBlocks);
			
			//	set up the timer
			IOWorkLoop* theWorkLoop = getWorkLoop();
			if(theWorkLoop != NULL)
			{
				mTimerEventSource = IOTimerEventSource::timerEventSource(this, TimerFired);
				if(mTimerEventSource != NULL)
				{
					theWorkLoop->addEventSource(mTimerEventSource);
					theAnswer = true;
				}
			}
			
			//	set the safety offset
			//	note that due to cache issues, it probably isn't wise to leave the safety offset at 0,
			//	we set it to 4 here, just to be safe.
			setSampleOffset(4);
			
			//	set up the time stamp generator
			mTimeStampGenerator.SetSampleRate(theInitialSampleRate.whole);
			mTimeStampGenerator.SetFramesPerRingBuffer(mBlockSize * mNumberBlocks);
			
			//	nate that the rate scalar is a 4.28 fixed point number
			//	this means that each incremnt is 1/2^28
			mTimeStampGenerator.SetRateScalar(1UL << 28);
			
			//	set the maximum jitter
//			AbsoluteTime theMaximumJitter = { 0, 0 };
//			nanoseconds_to_absolutetime(5ULL * 1000ULL, &theMaximumJitter);
//			mTimeStampGenerator.SetMaximumJitter(theMaximumJitter.lo);
		}
	}
	
	return theAnswer;
}
Exemplo n.º 2
0
XnStatus XnDeviceBase::Init(const XnDeviceConfig* pDeviceConfig)
{
	XnStatus nRetVal = XN_STATUS_OK;

	// first init the device
	nRetVal = InitImpl(pDeviceConfig);
	XN_IS_STATUS_OK(nRetVal);

	// and now create streams
	if (pDeviceConfig->pInitialValues != NULL)
	{
		nRetVal = CreateStreams(pDeviceConfig->pInitialValues);
		XN_IS_STATUS_OK(nRetVal);
	}

	return (XN_STATUS_OK);
}
Exemplo n.º 3
0
XnStatus XnDeviceFileReader::Rewind()
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// go back to start of stream
	nRetVal = GetIOStream()->Seek(XN_DEVICE_FILE_MAGIC_LEN);
	XN_IS_STATUS_OK(nRetVal);

	// read initial state
	XN_PROPERTY_SET_CREATE_ON_STACK(state);
	nRetVal = ReadInitialState(&state);
	XN_IS_STATUS_OK(nRetVal);

	// first handle current streams. remove or reset them
	XnDeviceModuleHolderList streams;
	nRetVal = GetStreamsList(streams);
	XN_IS_STATUS_OK(nRetVal);

	for (XnDeviceModuleHolderList::Iterator it = streams.Begin(); it != streams.End(); ++it)
	{
		XnDeviceModuleHolder* pHolder = *it;

		if (m_bStreamsCollectionChanged)
		{
			// we need to destroy all streams, and recreate them later
			nRetVal = DestroyStream(pHolder->GetModule()->GetName());
			XN_IS_STATUS_OK(nRetVal);
		}
		else
		{
			// just reset frame ID
			XnStreamReaderStream* pStream = (XnStreamReaderStream*)pHolder->GetModule();
			pStream->Reset();
		}
	}

	// if we need, recreate streams
	if (m_bStreamsCollectionChanged)
	{
		nRetVal = CreateStreams(&state);
		XN_IS_STATUS_OK(nRetVal);
	}

	// now set state.
	for (XnPropertySetData::Iterator it = state.pData->Begin(); it != state.pData->End(); ++it)
	{
		const XnChar* strName = it->Key();
		XnActualPropertiesHash* pHash = it->Value();

		// fix it first
		if (strcmp(strName, XN_MODULE_NAME_DEVICE) == 0)
		{
			pHash->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE);
			pHash->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM);
		}

		XnDeviceModule* pModule;
		nRetVal = FindModule(strName, &pModule);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = pModule->UnsafeBatchConfig(*pHash);
		XN_IS_STATUS_OK(nRetVal);
	}

	ResetLastTimestampAndFrame();
	m_nReferenceTimestamp = 0;
	m_nReferenceTime = 0;
	m_bStreamsCollectionChanged = FALSE;

	return (XN_STATUS_OK);
}