建一個貝殼console的專案
下載 wav 檔 將音效資料放在同專案資料夾中
在Buld Option 中的 Link 加上 "winmm"
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
int a;
for(int i=0;i<10;i++)
{
cout << "Hello world!" << endl;
PlaySoundA("Do.wav",NULL,SND_ASYNC);
//非同步(不用等,每個wav不用跑完所有時間就可跑下一個)
// SYNC 同步
cin>>a;
}
return 0;
}

2. Piano音效 (全)
加 free檔 中 include 跟 lib 的位置


咒語要照順序打

將freeglut.dll 跟音檔 放入專案資料夾


#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
void display()
{
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') PlaySoundA("Do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySoundA("Re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySoundA("Mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySoundA("Fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySoundA("Sol.wav",NULL,SND_ASYNC);
if(key=='6') PlaySoundA("La.wav",NULL,SND_ASYNC);
if(key=='7') PlaySoundA("Si.wav",NULL,SND_ASYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("3D sound version");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}

3. 放MP3
中間步驟一樣
要自己去載個音樂檔 在丟到同資料夾中
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
void display()
{
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') PlaySoundA("Do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySoundA("Re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySoundA("Mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySoundA("Fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySoundA("Sol.wav",NULL,SND_ASYNC);
if(key=='6') PlaySoundA("La.wav",NULL,SND_ASYNC);
if(key=='7') PlaySoundA("Si.wav",NULL,SND_ASYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("3D sound version");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myMP3.Load("yukai.mp3");
myMP3.Play();
glutMainLoop();
}

沒有留言:
張貼留言