Jump to content
  • Advertisement
Sign in to follow this  

DirectSound Sound-Synthesis, Streaming, best way?

This topic is 3689 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

hello, i have a question with streaming sounds by directsound. i'm coding an sound game and it is almost finish. you can have a look here:
all the sounds are generated in realtime (FM-Synthesis) and streamed via directSound. my problem/question is that my streamingbuffer is round about 100ms big and because there are so many oscillators to calculate, every 100ms the framerate of my game is breaking. that happens because i'm checking in every frame if the buffer is ready to fill. when the buffer is ready all the soundcalculations for the next 100ms are done and so this single frame will take much more time than the others. so the calculation of the framerate is going to be strange (i use the framerate for framerateundependent programming of the movements of all the graphical objects). usally the framrate is 60 (the rate of my monitor) but every half second the framerate is rising, which is strange because this rising of the framerate depends on the soundcalculations (when i disable the soundcalculations the framerate is stable). i think the framerate should fall when a frame is taken more time because of the soundcalculations. i wonder where my mistake is. when i use an external framecounter (fraps) it shows allways stable 60 frames even when the sound is on. so there must be an error in my code. but i cant find it.

void TicTimer(void) {
	double static FPS, tmpFPS;
	double static AvarageFPSStartTime;
	LONGLONG static lastFrame;
	LONGLONG CurrentFrame;
	double static AvarageFPSCounter;

	if (freq > 0) {
		elapsed = CurrentFrame - lastFrame;
		if(elapsed > 0) FPS = (double)((double)freq / (double)elapsed);
		else FPS = 1;
	} else {
		CurrentFrame = timeGetTime();
		elapsed = CurrentFrame - lastFrame;
		if(elapsed > 0) FPS = 1000.0/elapsed;
		else FPS = 1;
	if ((AvarageFPSStartTime + 500)>=(double)GetTickCount()) {
	} else {
		if(AvarageFPSCounter > 0.0) AverageFPS=tmpFPS/AvarageFPSCounter;
		else AverageFPS = 60.0;

		fFrameRate = AverageFPS;
		fFrameFactor = 60.0f/fFrameRate;

	lastFrame = CurrentFrame;
i hope this was comprehensible. and i would be very pleased if anybode could help me because the release of the game will be in two weeks. greets, andi general question: what is the best way for realtime sound synthesis. should i put the stremingbuffer-ready check and soundcalculations in a seperate thread?

Share this post

Link to post
Share on other sites
Sign in to follow this  


Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!