// play a wave file sound using the winmm library
// For DevCpp add the library libwinmm.a to linker via
// Project/Project Options/Parameters/Add Library
// remember this is a console program!

#include <iostream>
#include <windows.h> // for PlaySound()

#define SND_FILENAME 0x20000
#define SND_LOOP 8
#define SND_ASYNC 1

using namespace std;

int main()
{
// play sound as loop (remove SND_LOOP for one time play)
// file boing.wav has be in the working directory
PlaySound("boing.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);

cin.get(); // wait
return 0;
}

i cant get this to work for an midi i have... can sumone code this to work for it? or possibly a while nnew code that works... heres the 1 i am using..

#include <iostream> 
#include <windows.h>   // for PlaySound() 
#define SND_FILENAME 0x20000 
#define SND_LOOP 8 
#define SND_ASYNC 1 
using namespace std; 
int main() 
{ 
  // play sound as loop (remove SND_LOOP for one time play) 
  // file boing.wav has be in the working directory 
  PlaySound("ff7vict.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC); 
   
  cin.get(); // wait 
  return 0; 
}

Recommended Answers

All 4 Replies

Why not try to use an open source external library for your needs. It will provide all the kind of control you need over playing your sound. One eg. of it is Audiere.

i cant get this to work for an midi i have... can sumone code this to work for it? or possibly a while nnew code that works... heres the 1 i am using..

#include <iostream> 
#include <windows.h>   // for PlaySound() 
#define SND_FILENAME 0x20000 
#define SND_LOOP 8 
#define SND_ASYNC 1 
using namespace std; 
int main() 
{ 
  // play sound as loop (remove SND_LOOP for one time play) 
  // file boing.wav has be in the working directory 
  PlaySound("ff7vict.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC); 
   
  cin.get(); // wait 
  return 0; 
}

I asume that the qoute is your task. Did U noticed that U have to play wav file, and U say U want to play midi. Just for your information midi dont have samples inside the mid file. It contains midi messagess. The midi decoder generates PCM samples from tables (the largest table is wav table which consist raw PCM samples) according to these midi messages. Thats why midi files are much much smaler than mp3, wma files and offcourse wav files. So dude forgett the midi files becouse than U need to implement a midi decoder which is not your task.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.