第一節課->
1.上網下載do re mi fa sol la si的WAV檔案
2.建立一個新的貝殼console專案並將音檔放入
3.在Build Option 中的 Link 加上 "winmm"
4.輸入程式碼
#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); //非同步(不用等)
cin>>a;
}
return 0;
}
#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); //非同步(不用等)
cin>>a;
}
return 0;
}
就可以按1執行Do.wav的音喔!!
第二節課->
刪掉第一節的程式重新開始!!
一樣建立一個新的貝殼專案
在Build option中的Compiler位置設為老師給的freeglut中的includ
且Build option中的Linker位置設為老師給的freeglut中的lib
還有要在Linker settings中Add五個密語
freeglut
opendl32
glu32
gdi32
winmm
萬事俱備後打入程式碼
#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();
}
//即可執行按1~7播放音檔
//void display裡面可做出3D sound version的影像

第三節課->
在檔案中加入老師給的CMP3_MCI檔案 且選擇自己要的音檔下載下來 一樣放到檔案裡
增加程式碼
宣告增加:#include "CMP3_MCI.h"
CMP3_MCI myMP3;
主函式增加:myMP3.Load("蝶.mp3");//蝶為要播放的檔案名
myMP3.Play();

最後程式碼:
#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("dai.mp3");
myMP3.Play();
glutMainLoop();
}



沒有留言:
張貼留言