2016年5月2日 星期一

WEEK11

-課堂作業1-
音檔

開新的貝殼專案
->選擇C++
->打咒語 winmm多媒體


->加路徑
->把原本的程式碼都3掉
->程式碼

-程式碼-
#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); 
//SND_ASYNC "A"代表非 "SYNC"代表同步->非同步
//PlaySound"A"代表窄字元 W則代表寬字元
        cin>>a;
    }
    return 0;
}

->下載Do.WAV檔放入這個專案的資料夾
->完成後執行就可聽到聲音


-課堂作業2-
鍵盤音樂

開新的貝殼專案
->選擇C++
->打咒語



->加路徑
->把原本的程式碼都3掉
->程式碼

-程式碼-

#include <iostream>
#include <GL/glut.h>
#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();

}

->將所有音檔還有freeglut.dll放入這個專案的資料夾
->完成後執行 按數字1-7會發出doremi....


-課堂作業3-
自動播放

下載一個mp3檔
將mp3跟CMP3_MCI標頭檔放入專案的資料夾

-程式碼-

#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
void display()
{

}

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();
}

->完成後執行就會自動播放音樂並可彈鋼琴

沒有留言:

張貼留言