View Full Version : bad performance while playing ogg music
ehbgamer
08-30-2003, 05:28 PM
I'm using .ogg music files in my game, every thing just worked fine (loading and playing). except one thing, when I play a loop I need to decode ogg data into PCM data so that it can be played in a direct sound buffer, so every second I have to load about 4K from ogg data (from memory) and tell the program to decode it ... the problem is that it is affecting my game performance (stops every second for about 0.1 second or so).
I'm using a thread to decode ogg data.
any help ??:confused:
You could decode the whole ogg during level loading.
Switch to wav playback if you want to see now, how the performance would be then.
Without knowing your code, it's hard to say. It's probably that you're trying to lock the part of the buffer that is currently playing. I use a much larger buffer, and check each frame which half of the buffer I'm in. If I switch from one half to the other, I fill the other half (320K) and there's no hesitation (I'm not using threads, either). I think there's a sample in the DX SDK that shows this streaming method, but for WAVs.
Anyway, you shouldn't update the buffer based on time, that could get out of synch very easily, you should check the current position (in DX it's DirectSoundBuffer::GetCurrentPosition). Just changing that might fix your problem.
Good luck!
Hercule
08-31-2003, 12:17 AM
Do you use the thread for everything for sound ?
Do you check its priority ?
4 k can be charge without any hesitation.
patrox
08-31-2003, 02:53 AM
A common mistake is forgetting to call :
Sleep( 0 ) ;
(msdn "A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run" )
in your thread.
Also if that doesn't do, put this at the beginning of your thread :
SetThreadPriority( GetCurrentThread() , THREAD_PRIORITY_BELOW_NORMAL ) ;
to reduce the priority of the music thread. ( you shouldn't hear the difference really )
Hope that helps.
pat.
programmer_ted
09-01-2003, 06:55 PM
Nooope. Chances are, you're all wrong :D
I made a huge 900-line class for decoding/playing Oggs with DirectSound (lots of other features took up the 900 lines, by the way - I'm not that wasteful ;)), used a separate thread, etc. Had the same problem. SOLUTION! Decode much less information at a time. Decode every 5-or-so milliseconds and you'll be ok, rather than decoding every second.
I'm not sure about the Sleep(0) thing though. That may work. I tried the thread priority thing, but that didn't work well.
Hope this helps.
ehbgamer
09-02-2003, 01:37 PM
Stop(0) and setthreadpriority just made it better but still there are some stopping period ... I think ted is right but did not try it because I tried to decrease the music kbps which seems to solve the problem as it decodes less data (it also decreases file size) ... :D
Note: it worked perfectly on My new 2.4 GHZ machine but suffered with the old 500 MHZ