Streaming resources causing stuttering

Started by
3 comments, last by Kuro 16 years ago
I'm trying to play streaming music in my game, but it's causing stuttering in the frame rate. I was wondering if anyone knows some good technique to deal with this. I tried reducing the buffer size from 512k to 64k, but it still stutters. Part of the problem is that my game has "dynamic music" where it plays several tracks at the same time and mixes them at different volumes. I read an article on gamasutra about streaming resources which mentioned threading, but I don't think that would help on a single core cpu so threading is out of the question. I could try reducing the buffer size more, but it seems like if I set it too low, the music doesn't play correctly. Another possibility would be to read a tiny tiny bit off the disk *every frame*, but if I did that, I imagine seek times would kill me. Any insights would really be appreciated! Thanks Kuro
Advertisement
Code please.
Quote:Original post by Kuro
I read an article on gamasutra about streaming resources which mentioned threading, but I don't think that would help on a single core cpu so threading is out of the question.


I know very little about threading, but I'm pretty sure that you're wrong.

Your purpose is to make the music stream "simultaneously" with the game. To do this, you have to spend a small amount of time processing the game, then a small amount of time loading the music, and so on. If you switch between the two quickly enough, it will seem like the two are happening at the same time.

This is exactly what threading gives you, only with threads your code will be cleaner (because the task switching is done behind the scenes by the thread scheduler), and as an added benefit, your code will run faster on a multi-core CPU.

Like I said, though, I don't know much about threading so I could be wrong.
Unless you've previously planned for streaming resources from a different thread I'd recommend not doing it. It can get a little complex to add in after the fact.

As for the music streaming, I know a tutorial on devmaster.net says to use something like 8k per load, it might be as simple as you trying to load too much memory in one frame.
-----------------------------------Indium Studios, Inc.
Cool, I'll look into reducing the amount loaded each frame, maybe it will do the trick.

As for threading, hmm maybe it could work if it is done asynchronously. I was looking at reading from the hard drive as a blocking operation but I think there are functions like ReadFileEx or something.

Thanks for the suggestions!

This topic is closed to new replies.

Advertisement