1.建立貝殼專案

2.下載音效檔

撰寫程式:
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
PlaySoundA("Do.wav",NULL,SND_SYNC);
PlaySoundA("Re.wav",NULL,SND_SYNC);
PlaySoundA("Mi.wav",NULL,SND_SYNC);
return 0;
}

執行程式

作業二
鍵盤
把專案添加新的Linker setting search direction
將剛才自動撥放 改為按鍵盤撥放
執行結果按下數字鍵 就有音樂
作業三
載一個MP3檔 丟入專案資料夾
將老師給的"CMP3_MCI"標頭檔也放入資料夾
將老師給的"CMP3_MCI"標頭檔也放入資料夾
改寫程式#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
using namespace std;
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("music.mp3");
myMP3.Play();
glutMainLoop();
}
視窗跳出即有音樂播放且可伴隨鍵盤彈鋼琴
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
using namespace std;
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("music.mp3");
myMP3.Play();
glutMainLoop();
}







沒有留言:
張貼留言