Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Crypthor

DirectX Problem ( DirectSound)

This topic is 6732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Couple weeks ago, i''ve asking for explanation of DirectSound streaming buffer. But all that i get, it''s a Microsoft DirectX SDK. WELL, it''s example doesn''t work !!! Can some body explane me Streaming Buffer, but, better it''s to show me some source codes of it ! And i''ll glad if there will be no classes! "I hate classes" Thank you !

Share this post


Link to post
Share on other sites
Advertisement
This is the code of my old music system. Hope it helps anyway


// sound.cpp

BOOL _MoonWars_MusicSystem::SetUp (char* File)
{
DSBUFFERDESC dsbdesc;
WAVEFORMATEX *pwfx;

// Offene Datei schließen und Puffer abbauen, falls vorhanden
WaveCloseReadFile (&hmmio, &pwfx);

// Datei öffnen, Datenformat lesen und weiter bis zum data-Chunk
if (WaveOpenFile (File, &hmmio, &pwfx, &mmckinfoParent) != 0)
return FALSE;
if (WaveStartDataRead (&hmmio, &mmckinfo, &mmckinfoParent) != 0)
return FALSE;

// Sekundären Puffer mit 4 Sekunden Spieldauer anlegen
ZeroMemory (&dsbdesc, sizeof (dsbdesc));
dsbdesc.dwSize = sizeof (dsbdesc);
dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2
/ DSBCAPS_GLOBALFOCUS / DSBCAPS_CTRLVOLUME;
dsbdesc.dwBufferBytes = pwfx->nAvgBytesPerSec * 2;
dsbdesc.lpwfxFormat = pwfx;

if (FAILED(lpDS->CreateSoundBuffer (&dsbdesc, &lpDSBMusic, NULL)))
{
WaveCloseReadFile (&hmmio, &pwfx);
return FALSE;
}

FillBufferWithSilence (lpDSBMusic);
lpDSBMusic->Play (0, 0, DSBPLAY_LOOPING);

MidBuffer = dsbdesc.dwBufferBytes / 2;

return TRUE;
}

BOOL _MoonWars_MusicSystem:ollSoundData (void)
{
DWORD dwPlay;
DWORD dwStartOfs;
static DWORD dwLastPlayPos;
VOID *lpvData;
DWORD dwBytesLocked;
UINT cbBytesRead;

if (lpDSBMusic == NULL) return FALSE;

if (FAILED(lpDSBMusic->GetCurrentPosition (&dwPlay, NULL)))
return FALSE;

// Wenn der Abspielcursor gerade von der ersten in die zweite Hälfte
// des Puffers gewechselt hat oder umgekehrt, dann können wir die jeweils
// andere Hälfte des Puffers mit neuen Daten füllen

if (((dwPlay >= MidBuffer) && (dwLastPlayPos < MidBuffer))
// (dwPlay < dwLastPlayPos))
{
dwStartOfs = (dwPlay >= MidBuffer) ? 0 : MidBuffer;

lpDSBMusic->Lock (dwStartOfs, // Start = 0 oder Mitte des Puffers
MidBuffer, // Größe = halber Puffer
&lpvData, // Zeiger auf den Puffer, wird gesetzt
&dwBytesLocked, // Anzahl gesperrter Bytes, dito
NULL, // kein zweiter Bereichsstart
NULL, // keine zweite Bereichsgröße
0); // keine speziellen Flags

WaveReadFile (hmmio, // Handle der WAV-Datei
dwBytesLocked, // zu lesen = Größe d. Sperrbereichs
(BYTE*)lpvData, // Zieladresse
&mmckinfo, // data-Chunk
&cbBytesRead); // Anzahl gelesener Bytes

if (cbBytesRead < dwBytesLocked) // Dateiende erreicht?
{
if (WaveStartDataRead (&hmmio, &mmckinfo, &mmckinfoParent) != 0)
{
OutputDebugString ("Fehler bei Repositionierung " "auf Dateianfang.\n");

}
else
{ // die noch fehlenden Bytes einlesen
WaveReadFile (hmmio,
dwBytesLocked - cbBytesRead,
(BYTE*)lpvData + cbBytesRead,
&mmckinfo,
&cbBytesRead);
}
}

lpDSBMusic->Unlock (lpvData, dwBytesLocked, NULL, 0);
}

dwLastPlayPos = dwPlay;
return TRUE;
}

void _MoonWars_MusicSystem::ShutDown (void)
{
WAVEFORMATEX* pwfx;
// Offene Datei schließen und Puffer abbauen, falls vorhanden
WaveCloseReadFile (&hmmio, &pwfx);
lpDSBMusic->Release ();
}


// sound.h

typedef struct _MoonWars_MusicSystem
{
LPDIRECTSOUNDBUFFER lpDSBMusic;
HMMIO hmmio;
MMCKINFO mmckinfo;
MMCKINFO mmckinfoParent;
DWORD MidBuffer;

BOOL SetUp (char* File);
BOOL PollSoundData (void);
void ShutDown (void);
void NextTune (void);
void PrevTune (void);
void ChangeTune (BYTE NewTune);
} MWMUSICSYSTEM;


Sorry about the german comments

Edited by - Melo on 3/14/00 10:02:44 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!