2016年5月2日 星期一

ModeR_Week11_GLUT教學_鍵盤、聲音

WEEK11

Work01-將聲音檔加入於程式中


第一步:先將DO、RE、MI的聲音檔案下載起來準備



第二步:將聲音檔下載完後,開啟codeblock新增專案Console application


請選擇C++作為撰寫程式的背景


第三步:當專案新增後,先於左方的總檔案按右鍵選擇Build Options


當選擇Link settings,將winmm加入於Link libraries


第四步:當新增window的多媒體應用(winmm)進入於程式中後,將
include <windows.h>
include <mmsystem.h>
加入於程式碼中


第五步:接下來,將聲音檔案加入於程式碼
利用PlaySoundA("Do.wav",NULL,SND_ASYNC);
//Do.wav為聲音檔//
 //NULL讓音檔不掛在任何事件下面//
//SND_ASYNC非同步//

cin>>a;//將按鍵盤的回傳值放到"a"


Do.wav的聲音檔放置到專案資料夾下方





Work02-製作簡易虛擬鋼琴



第一步:開啟新專案Console application

選擇C++作為撰寫背景


在專案總檔案按右鍵,選擇Build Options


選擇Link settings,將
freeglut
opengl32
glu32
gdi32
winmm
加入於Link libraries


選擇Search directories中的Compiler
將freeglut中的include資料夾位置加入


選擇Search directories中的Linker
將freeglut中的lib資料夾位置加入

\

接下來寫入程式碼

-------------------------------------------程式碼-------------------------------------------------------

#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();
}
-------------------------------------------程式碼-------------------------------------------------------



當程式碼寫完後,將聲音檔拉至專案檔中的資料夾下方


同樣將freeglut.dll拉至專案檔中的資料夾下方


最後,執行檔案,按1~7的數字鍵,程式會回傳聲音檔的內容





Work03-將音樂檔放入程式中








沒有留言:

張貼留言