Esempio n. 1
0
bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
{
    bool requestStop = false;

    // Acquire audio data
    Chunk data = {NULL, 0};
    if (!OnGetData(data))
    {
        // Mark the buffer as the last one (so that we know when to reset the playing position)
        myEndBuffers[bufferNum] = true;

        // Check if the stream must loop or stop
        if (myLoop)
        {
            // Return to the beginning of the stream source
            OnSeek(0);

            // If we previously had no data, try to fill the buffer once again
            if (!data.Samples || (data.SampleCount == 0))
            {
                return FillAndPushBuffer(bufferNum);
            }
        }
        else
        {
            // Not looping: request stop
            requestStop = true;
        }
    }

    // Fill the buffer if some data was returned
    if (data.Samples && data.SampleCount)
    {
        unsigned int buffer = myBuffers[bufferNum];

        // Fill the buffer
        ALsizei size = static_cast<ALsizei>(data.SampleCount) * sizeof(Int16);
        ALCheck(alBufferData(buffer, myFormat, data.Samples, size, mySampleRate));

        // Push it into the sound queue
        ALCheck(alSourceQueueBuffers(mySource, 1, &buffer));
    }

    return requestStop;
}
Esempio n. 2
0
////////////////////////////////////////////////////////////
/// Fill a new buffer with audio data, and push it to the
/// playing queue
////////////////////////////////////////////////////////////
bool SoundStream::FillAndPushBuffer(unsigned int BufferNum)
{
    bool RequestStop = false;

    // Acquire audio data
    Chunk Data = {NULL, 0};
    if (!OnGetData(Data))
    {
        // Mark the buffer as the last one (so that we know when to reset the playing position)
        myEndBuffers[BufferNum] = true;

        // Check if the stream must loop or stop
        if (myLoop && OnStart())
        {
            // If we succeeded to restart and we previously had no data, try to fill the buffer once again
            if (!Data.Samples || (Data.NbSamples == 0))
            {
                return FillAndPushBuffer(BufferNum);
            }
        }
        else
        {
            // Not looping or restart failed: request stop
            RequestStop = true;
        }
    }

    // Fill the buffer if some data was returned
    if (Data.Samples && Data.NbSamples)
    {
        unsigned int Buffer = myBuffers[BufferNum];

        // Fill the buffer
        ALsizei Size = static_cast<ALsizei>(Data.NbSamples) * sizeof(Int16);
        ALCheck(alBufferData(Buffer, myFormat, Data.Samples, Size, mySampleRate));

        // Push it into the sound queue
        ALCheck(alSourceQueueBuffers(Sound::mySource, 1, &Buffer));
    }

    return RequestStop;
}
Esempio n. 3
0
////////////////////////////////////////////////////////////
/// Fill a new buffer with audio data, and push it to the
/// playing queue
////////////////////////////////////////////////////////////
bool SoundStream::FillAndPushBuffer(unsigned int Buffer)
{
    bool RequestStop = false;

    // Acquire audio data
    Chunk Data = {NULL, 0};
    if (!OnGetData(Data))
        RequestStop = true;

    // Create and fill the buffer, and push it to the queue
    if (Data.Samples && Data.NbSamples)
    {
        // Fill the buffer
        ALsizei Size = static_cast<ALsizei>(Data.NbSamples) * sizeof(Int16);
        ALCheck(alBufferData(Buffer, myFormat, Data.Samples, Size, mySampleRate));

        // Push it into the sound queue
        ALCheck(alSourceQueueBuffers(Sound::mySource, 1, &Buffer));
    }

    return RequestStop;
}
Esempio n. 4
0
// Implementation of GetData
STDMETHODIMP CSimpleDataObjectImpl::GetData(FORMATETC* pformatetc, STGMEDIUM* pmedium)
{
	// Check format etc
	if (pformatetc->dwAspect!=DVASPECT_CONTENT)	return DV_E_DVASPECT;

#ifdef _DEBUG
	TCHAR szFormat[MAX_PATH];
	if (!GetClipboardFormatName(pformatetc->cfFormat, szFormat, MAX_PATH))
	{
		wsprintf(szFormat, _T("%i"), pformatetc->cfFormat);
	}
	ATLTRACE(_T("CSimpleDataObjectImpl::GetData - %s %i\n"), szFormat, pformatetc->tymed);
#endif

	// Get the format...
	CFormat* pFormat=FindFormat(pformatetc->cfFormat, (TYMED)pformatetc->tymed);
	if (!pFormat)
		return DATA_E_FORMATETC;

	// Init STGMEDIUM
	memset(pmedium, 0, sizeof(*pmedium));

	if (pformatetc->tymed & TYMED_HGLOBAL)
	{
		// Delayed data?
		if (!pFormat->m_hData)
		{
			if (SUCCEEDED(OnGetData(pformatetc->cfFormat, pformatetc->lindex, &pmedium->hGlobal)))
			{
				pmedium->tymed=TYMED_HGLOBAL;
				return S_OK;
			}
		}
		else if (pformatetc->lindex==-1)
		{
			// Allocate memory
			DWORD_PTR dwSize=GlobalSize(pFormat->m_hData);
			pmedium->hGlobal=GlobalAlloc(GHND, dwSize);
			if (!pmedium->hGlobal)
				return E_OUTOFMEMORY;

			// Copy it
			memcpy(GlobalLock(pmedium->hGlobal), GlobalLock(pFormat->m_hData), dwSize);

			// Unlock
			GlobalUnlock(pmedium->hGlobal);
			GlobalUnlock(pFormat->m_hData);

			pmedium->tymed=TYMED_HGLOBAL;
			return S_OK;
		}
	}

	if (pformatetc->tymed & TYMED_ISTREAM)
	{
		// Delayed data?
		if (!pFormat->m_spStream)
		{
			if (SUCCEEDED(OnGetData(pformatetc->cfFormat, pformatetc->lindex, &pmedium->pstm)))
			{
				pmedium->tymed=TYMED_ISTREAM;
				return S_OK;
			}
		}
		else if (pformatetc->lindex==-1)
		{
			pFormat->m_spStream.CopyTo(&pmedium->pstm);
			pmedium->tymed=TYMED_ISTREAM;
			return S_OK;
		}
	}

	// Unknown format
	return DATA_E_FORMATETC;
}