Exemplo n.º 1
0
static void DirectSoundThread(void* Arg)
{
	DRV_DSND* drv = (DRV_DSND*)Arg;
	UINT32 wrtBytes;
	UINT32 didBuffers;	// number of processed buffers
	
	OSSignal_Wait(drv->hSignal);	// wait until the initialization is done
	
	while(drv->devState == 1)
	{
		didBuffers = 0;
		
		OSMutex_Lock(drv->hMutex);
		while(GetFreeBytes(drv) >= drv->bufSegSize && drv->FillBuffer != NULL)
		{
			wrtBytes = drv->FillBuffer(drv->audDrvPtr, drv->userParam, drv->bufSegSize, drv->bufSpace);
			WriteBuffer(drv, wrtBytes, drv->bufSpace);
			didBuffers ++;
		}
		OSMutex_Unlock(drv->hMutex);
		if (! didBuffers)
			Sleep(1);
		
		while(drv->FillBuffer == NULL && drv->devState == 1)
			Sleep(1);
		//while(drv->PauseThread && drv->devState == 1)
		//	Sleep(1);
	}
	
	return;
}
Exemplo n.º 2
0
//-------------------------------------------------------------------------------------------
//! 
//-------------------------------------------------------------------------------------------
bool tScreenShot::EnoughFreeSpace()
{
    qint64 freeBytes = GetFreeBytes( tDataSourceSettings::Instance().InternalDrivePath() );
    if ( freeBytes < 1048576 ) //1MB
    {
        return false;
    }

    return true;
}
Exemplo n.º 3
0
void SjRingbuffer::PushToEnd(const unsigned char* src, long bytesToCopy)
{
	// Function adds the given data to the end of the ringbuffer.
	// If you use this function in different threads, don't forget
	// to call Lock()/Unlock().

	long i, destPos;

	// check param
    if( !m_buffer || !src || bytesToCopy <= 0 || m_validPos >= m_totalBytes ) {
		return;
    }

	// are there enough free bytes in the buffer?
	if( bytesToCopy > GetFreeBytes() )
	{
		bytesToCopy = GetFreeBytes();

		if( bytesToCopy <= 0 )
		{
			return; // buffer is full
		}
	}

	// add data to buffer
    destPos = (m_validPos + m_validBytes) % m_totalBytes;

    if( destPos + bytesToCopy > m_totalBytes )
    {
        i = m_totalBytes - destPos;

        memcpy(m_buffer + destPos,  src,       i);
        memcpy(m_buffer,            src + i,   bytesToCopy - i);
    }
    else
    {
        memcpy(m_buffer + destPos,  src,       bytesToCopy);
    }

	// correct ringbuffer pointers
    m_validBytes += bytesToCopy;
}
Exemplo n.º 4
0
UINT8 DSound_IsBusy(void* drvObj)
{
	DRV_DSND* drv = (DRV_DSND*)drvObj;
	UINT32 freeBytes;
	
	if (drv->FillBuffer != NULL)
		return AERR_BAD_MODE;
	
	freeBytes = GetFreeBytes(drv);
	return (freeBytes >= drv->bufSegSize) ? AERR_OK : AERR_BUSY;
}
Exemplo n.º 5
0
UINT8 DSound_WriteData(void* drvObj, UINT32 dataSize, void* data)
{
	DRV_DSND* drv = (DRV_DSND*)drvObj;
	UINT32 freeBytes;
	
	if (dataSize > drv->bufSegSize)
		return AERR_TOO_MUCH_DATA;
	
	freeBytes = GetFreeBytes(drv);
	while(freeBytes < dataSize)
		Sleep(1);
	
	WriteBuffer(drv, dataSize, data);
	return AERR_OK;
}
Exemplo n.º 6
0
UINT32 DSound_GetLatency(void* drvObj)
{
	DRV_DSND* drv = (DRV_DSND*)drvObj;
	UINT32 bytesBehind;
#if 0
	DWORD readPos;
	HRESULT retVal;
	
	retVal = drv->dSndBuf->GetCurrentPosition(&readPos, NULL);
	if (retVal != DS_OK)
		return 0;
	
	if (drv->writePos >= readPos)
		bytesBehind = drv->writePos - readPos;
	else
		bytesBehind = (drv->bufSize - readPos) + drv->writePos;
#else
	bytesBehind = drv->bufSize - GetFreeBytes(drv);
#endif
	return bytesBehind * 1000 / drv->waveFmt.nAvgBytesPerSec;
}