STEP1: 開個貝殼專案
#include <iostream>
#include<windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
int a;
for(int i=0;i<111;i++)
{
if(a=1)
{
cin>> a;
PlaySoundA("Do.wav",NULL,SND_ASYNC);//(檔名,handle,非同步)
}
if(a=2)
{
cin>> a;
PlaySoundA("Re.wav",NULL,SND_ASYNC);
}
if(a=3)
{
cin>> a;
PlaySoundA("Mi.wav",NULL,SND_ASYNC);
}
if(a=4)
{
cin>> a;
PlaySoundA("Fa.wav",NULL,SND_ASYNC);
}
if(a=5)
{
cin>> a;
PlaySoundA("Sol.wav",NULL,SND_ASYNC);
}
if(a=6)
{
cin>> a;
PlaySoundA("La.wav",NULL,SND_ASYNC);
}if(a=7)
{
cin>> a;
PlaySoundA("Si.wav",NULL,SND_ASYNC);
}
}
return 0;
}
最後你可以得到一台鋼琴(按數字鍵會有聲音)
HW2:
STEP1: 開新的專案
然後key 程式碼
#include <GL/glut.h>
#include <iostream>
#include<windows.h>
#include <mmsystem.h>
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);
glutMainLoop();
}
Step2:
在Build option裡面念咒語
STEP3:
設定路徑為Freeglut裡的 include &lib
最後按數字1~7可以有怪鋼琴的聲音
注意!! 要把freeglut資料夾裡的 bin 裡的glut.dll檔複製貼上到專案裡
HW3:
#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");
myMP3.Load("yukai.mp3");//你要的MP3檔名
myMP3.Play();//新加的程式碼
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
編譯後可以得到妖怪手表的音樂





沒有留言:
張貼留言