?
Solved

Easy, i think, sound seprate loop?

Posted on 2003-03-14
6
Medium Priority
?
282 Views
Last Modified: 2010-04-01
Basically i want music to loop during my game, background music if you will. Its for a game i made. Now when i say music i mean something like this:

for(int i=0; i<10; i++)
   { sound(261);
     delay(200);
     sound(356);
     delay(200);
     sound(279);
     delay(200);
     //...and so on
   }
nosound();

I just don't know how make it play in the background while my main game parts goes about its merry business. (filled with loops and delays and getchs) Also could this same tequnique be aplied to simple sound effects made just like the music i made up above? Please help! THANKS!!
     
     
0
Comment
Question by:Punkman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8141510
This type of parallel code execution could be done with multi-threading. Borland C++ Builder has some good support for this, but I doubt the libraries included with Turbo C++ has anything to support it. There are other classes available out there that provide implementations for multi-threading, though. Try doing a Google search for "C++ multi threading" or something similar and see if anything useful comes up.

I've read a few of them, and noticed that Windows NT will support true multithreading, while most of the Windows 9x thread classes have to alternate processor usage, and they sound really complicated to implement. I'll get back to you if I find one that sounds like it'll work for this kind of application.
0
 

Expert Comment

by:Riham
ID: 8141797
You'll need to use a function called
BOOL PlaySound(
  LPCSTR pszSound,  
  HMODULE hmod,    
  DWORD fdwSound    
);

at the beginning u can use the first parameter as your filename.
the second parameter NULL.

the third parameter:
SND_LOOP|SND_FILENAME
this way the sound will keep playing till u stop it.
at any time when u want to stop the call the same function and sett all your parameters to NULL. to play it again call the same function.

if my answer does not answer your question perfectly please check the playsound SDK function. u'll find many useful flags like SND_ASYNC and SND_SYNC
0
 

Author Comment

by:Punkman
ID: 8143428
a file name? That means the music would be an external thing, like a wave. I just want to use sound() and delay() to make the music, not import a music file-i think that is what you are saying. If there is really no way to do this, then could someone tell me how to make a song play untill the user hits a key? remember music is like this for me:
sound(261);
    delay(200);
    sound(356);
    delay(200);
    sound(279);
    delay(200);
    //...and so on
  Thanks!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Accepted Solution

by:
DarthNemesis earned 240 total points
ID: 8143706
I don't know the actual function you can use to play sound, because that's platform-specific. This example uses a low version of borland, you might give it a try:

http://bdn.borland.com/article/0,1410,16928,00.html

As for stopping the sound, that will also change depending on your implementation. If you were able to use the above example, then you could replace WaitSoundState(S_QUEUEEMPTY); with while(!kbhit()); (a conio.h function).
0
 

Author Comment

by:Punkman
ID: 8143825
You have just given me an idea...ill check back later and tell you if it works...
0
 

Author Comment

by:Punkman
ID: 8594607
Thanks again Darth Nemesis! :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question