Microsoft DirectX 9.0

CStreamingSound Sample Class

The CStreamingSound sample class represents a streaming buffer. The class inherits from CSound. An object of this class is usually created through a call to the CreateStreaming method of the CSoundManager Sample Class.

A CStreaming object has only one buffer. When calling methods inherited from CSound that take a buffer index, pass 0.

class CStreamingSound : public CSound
{
protected:
    DWORD m_dwLastPlayPos;
    DWORD m_dwPlayProgress;
    DWORD m_dwNotifySize;
    DWORD m_dwNextWriteOffset;
    BOOL  m_bFillNextNotificationWithSilence;

public:
    CStreamingSound(LPDIRECTSOUNDBUFFER pDSBuffer, DWORD dwDSBufferSize,
        CWaveFile* pWaveFile, DWORD dwNotifySize);
    ~CStreamingSound();

    HRESULT HandleWaveStreamNotification(BOOL bLoopedPlay);
    HRESULT Reset();
};

Constructor

The constructor calls the CSound constructor to fill the buffer with data from the beginning of the WAV file, and initializes private data members.

Public Methods

In addition to the methods inherited from CSound, the class contains the following public methods, in alphabetical order.

Method Description
HandleWaveStreamNotification Restores the buffer if necessary, then reads data from the file and writes it to the part of the buffer that has just been played. If the end of data is reached, the rest of the buffer is filled with silence, and the buffer is stopped after all data has been played. Call this method in response to notifications received in the message loop. Pass in TRUE as the parameter to repeat the sound when it reaches the end.
Reset Restores the buffer if necessary, then resets the play position and the file so that the sound can begin playing again from the beginning.

The class is implemented in (SDK root)\samples\C++\Common\Src\Dsutil.cpp.

See Also