1

I need C++ code to play sound at particular decibels that are choose by user dynamically.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
krishna
  • 3,148
  • 5
  • 19
  • 24

1 Answers1

3

This was answered Here

You need to use the absolute path, make sure that you're sending a filename (use SND_FILENAME flag), and pause the program long enough to play the sound file (e.g., use getchar()). You need to link the winmm.lib library in your project settings, and #include windows.h and mmsystem.h in the header.

#include <windows.h>
#include <mmsystem.h>

int main() {
    PlaySound((LPCSTR) "C:\\kenny g.WAV", NULL, SND_FILENAME | SND_ASYNC);
    getchar();
}
Community
  • 1
  • 1