DirectX Problem ( DirectSound)
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 !
This is the code of my old music system. Hope it helps anyway
Sorry about the german comments
Edited by - Melo on 3/14/00 10:02:44 AM
// sound.cppBOOL _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.htypedef 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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement