2016年5月2日 星期一

廖婕珊hw11

(1)音效、音樂

Build Option 加Link咒語:winmm


下載wav檔(http://www.openprocessing.org/sketch/132652)


放在同目錄


執行結果

#include <iostream>
#include <windows.h>  ///windows下
#include <mmsystem.h> ///可以播出聲音(多媒體)

using namespace std;

int main()
{
    int a;

    cout << "Hello world!" << endl;
    PlaySoundA("Do.wav",NULL,SND_ASYNC);///非同步(不用等)  SND_SYNC(同步)
    cin>>a;
    cout << "Hello world!" << endl;
    PlaySoundA("Re.wav",NULL,SND_ASYNC);
    cin>>a;
    cout << "Hello world!" << endl;
    PlaySoundA("Mi.wav",NULL,SND_ASYNC);
    cin>>a;
    cout << "Hello world!" << endl;
    PlaySoundA("Fa.wav",NULL,SND_ASYNC);
    cin>>a;
    cout << "Hello world!" << endl;
    PlaySoundA("Sol.wav",NULL,SND_ASYNC);
    cin>>a;
    cout << "Hello world!" << endl;
    PlaySoundA("La.wav",NULL,SND_ASYNC);
    cin>>a;
    cout << "Hello world!" << endl;
    PlaySoundA("Si.wav",NULL,SND_ASYNC);
    cin>>a;
    return 0;
 
}

(2)鍵盤
    glut的keyboard函式



Search Directory目錄 加  C:\Users\USER\Desktop\freeglut\include


 Linker 加 C:\Users\USER\Desktop\freeglut\lib


加咒語freeglut / opengl32 / glu32 / gdi32 / winmm


freeglut.dll(freeglut/bin)檔要記得放到目錄中


結果

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

(3)執行mp3等音檔

CMP3_MCI.h  和mp3檔  放在同目錄


執行結果


加下列四行
#include "CMP3_MCI.h"
CMP3_MCI myMP3;

myMP3.Load("mp3檔名");
myMP3.Play();


沒有留言:

張貼留言