2016年5月2日 星期一

Week11-邱緯豪-課堂作業

音樂、音效

1.一行播音效

#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 - 非同步(不用等)
        cin>>a;
    }
    return 0;
}

下載WAV檔,放入與Project相同目錄

Build Option 加入 link : winmm


2.比較SND_ASYNC&SND_SYNC

#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_SYNC - 同步(自動播放)
        cin>>a;
    }
    return 0;
}

3.glut的keyboard函式

專案(左鍵) - Build Options 設定

(a)Search Directories 目錄
      1.Compiler Add  C:\freeglut\include
      2.Linker Add C:\freeglut\lib

(b)Linker Settings
      Add  1.winmm
              2.freeglut
              3.glu32
              4.gdi32
              5.opengl32

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




沒有留言:

張貼留言