   DirectX Audio CRAZINESS!
  Perhaps someone else had this problem before, so they can tell me what's happening. Basically, I have DirectX Audio wrapped into classes that I use to play sounds with segments and such.When I initialize music and sound to play in the initialize function, they get off to a good start. When I stop the sounds and then start them up again in the main game loop, they stutter for about 0.5 seconds and then play fine afterwards. I'd like to know why this happens, and what I can to to stop it from happening. Here's the code:One of the play functions (CMusic and CAudio functions run very similarly): BOOL CSound::Play(BOOL Loop){if (m_Audio == NULL) return FALSE;if (m_Audio->GetPerformanceCOM() == NULL) return FALSE;if (m_DMSegment == NULL) return FALSE;Stop();if (Loop){m_DMSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE);if (FAILED(m_Audio->GetPerformanceCOM()->PlaySegmentEx(m_DMSegment, NULL, NULL, DMUS_SEGF_SECONDARY, 0, NULL, m_DMAudioPath, m_DMAudioPath))) return FALSE;}else{m_DMSegment->SetRepeats(0);if (FAILED(m_Audio->GetPerformanceCOM()->PlaySegmentEx(m_DMSegment, NULL, NULL, DMUS_SEGF_SECONDARY, 0, NULL, m_DMAudioPath, m_DMAudioPath))) return FALSE;}return TRUE;}Application initialize function:   BOOL CApplication::Initialize(){Input.Initialize(GetWindowHandle(), GetInstance());Audio.Initialize(GetWindowHandle());Keyboard.Create(&Input, KEYBOARD);Music.Create(&Audio, "tengu.mid");Music.Play(TRUE); // TRUE makes the sound loopSound.Create(&Audio, "test.wav");Sound.Play(TRUE);return TRUE;}The frame (main loop) function. This is called repeatedly with no time restrictions, so it will be called more often on a faster processor:   BOOL CApplication::Frame(){Keyboard.Read();if (Keyboard.GetKeyState(DIK_ESCAPE)) return FALSE;if (Keyboard.GetKeyState(DIK_S)){if (Music.IsPlaying()){Music.Stop();Sound.Stop();}}if (Keyboard.GetKeyState(DIK_P)){if (!Music.IsPlaying()){Music.Play(TRUE);Sound.Play(TRUE);}}return TRUE;}Just need some suggestions. I was thinking that it has something to do with DirectX Audio not getting a large enough time slice when it's multithreading.---n00bHaTeR: i got fired todaygamer2000: lol!noobHaTeR: [edited by - Weston on February 15, 2004 1:21:44 AM]
  I can''t really answer your question because I have only used the Direct Sound and Direct Sound Capture interfaces.  If I had the same problem as you are describing with these interfaces I would look at two items:(1) That the playback buffer was initialized with silence or the data you wish to play and that the current play index was located in the correct position in the buffer.(2) That the updates of the playback buffer are sufficiently far ahead of the current play position that you are not playing data from the same position you are writing.It could be that when you start something that your play cursor and where you are writing data to be played are in the same place or too close to each other.  In the DirectSound and Capture interfaces the ->GetCurrentPosition(&a, &b) method gives you the current position and the safe position where you may read or write (depending upon capture or playback). Brian ;  Although that would probably produce the same problems, DirectMusic doesn''t work with read and write cursors like DirectSound does, so I can''t set the position of them. Thanks though.   ---n00bHaTeR: i got fired todaygamer2000: lol!noobHaTeR: ;  Problem solved. IsPlaying() doesn''t kick in immediately, but waits a few milliseconds before is can give accurate information on the segment state. Odd. I know how to fix it, but does anyone know why this happens?   ---n00bHaTeR: i got fired todaygamer2000: lol!noobHaTeR: 