0

Hi everyone.
I'm making a simple text rpg and battle system with C and I was just wondering if it was possible to add sounds to it. I've heard that it's possible with C++ but I'm not sure if it's possible with C as well.
Any help is greatly appreciated :)

4
Contributors
9
Replies
12
Views
8 Years
Discussion Span
Last Post by jantazone
0

You can use the Beep() function from the Win32 API.
Beep(82, 600);
That will sound at 82Hz for 600ms.
You can use the PlaySound() function also from Win32 to play a wave file.
You need to include the header windows.h.

0

I'm not quite sure of how to include the sound file because I've never attempted to include another file in my program. Here's my attampt so far:

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <C:\Users\Imad.Imad-PC\Documents\Computer Programming\Target.wav>      //includes sound file?

int main()
{
    system("PAUSE");                                                            
    
    PlaySound(C:\Users\Imad.Imad-PC\Documents\Computer Programming\Target.wav); //.wav file
    
    system("PAUSE");
    return 0;
}
0
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#pragma comment(lib, "winmm.lib")

int main()
{
    
	PlaySound( TEXT("C:\\WINDOWS\\.file_store_32\\sound0.wav"), NULL, SND_FILENAME | SND_ASYNC);
    getchar();
    return 0;
}

This compiles in Visual C++ 2008

0

Actually, you don't need mmsystem.h and that pragma. You can add winmm.lib as an additional dependency.

0

Thanks for your help Colin Mac. But I found that what I really wanted was to use mciSendString.
And to answer apurvkolte's question, you can play mp3 files by using the mciSendString command. Here's an example code: mciSendString("play C:\\TheTarget.mp3", NULL, 0, NULL);

0

hi....
yes it is possible in c as well c++.
you need set frequency of sound to particular character then it will produce sound what you type.for reference-package of yashwant kanetkar is suitable.
take care........bye

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.