2016年5月2日 星期一

week11

先上網找wav do re mi
打開這個網頁
點選Download



打開貝殼專案



程式如下:
 #include <iostream>
#include<windows.h>
#include <mmsystem.h>
using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    int a;
    for(int i=0;i<111;i++)
    {
    if(a=1)
    {
    cin>> a;
    PlaySoundA("Do.wav",NULL,SND_ASYNC);
    }
    if(a=2)
    {
    cin>> a;
    PlaySoundA("Re.wav",NULL,SND_ASYNC);
    }
    if(a=3)
    {
    cin>> a;
    PlaySoundA("Mi.wav",NULL,SND_ASYNC);
    }
    if(a=4)
    {
    cin>> a;
    PlaySoundA("Fa.wav",NULL,SND_ASYNC);
    }
    if(a=5)
    {
    cin>> a;
    PlaySoundA("Sol.wav",NULL,SND_ASYNC);
    }
    if(a=6)
    {
      cin>> a;
    PlaySoundA("La.wav",NULL,SND_ASYNC);
    }if(a=7)
    {
    cin>> a;

    PlaySoundA("Si.wav",NULL,SND_ASYNC);
    }
    }

    return 0;
}
按下build:
就會跑出一台鋼琴 可以彈奏音樂(按數字鍵操作)
 

 2.課堂作業二:

程式碼如下:
#include <GL/glut.h>
#include <iostream>
#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();
}

在build option 裡面加咒語

五個咒語如下圖:

編譯器 要選freeglut資料夾裡的Include 
 

linker 要選freeglut資料夾裡的 lib
 

 注意!! 要把freeglut資料夾裡的 bin 裡的glut.dll檔複製貼上到專案裡
不然會跑不出來!!

按下build:

這樣之後只要按下1~7就會有鋼琴的聲音了!!

3.課堂作業三:

#include <GL/glut.h>
#include<windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;  //新加的程式碼
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");
    myMP3.Load("yukai.mp3");//自己的MP3檔名
    myMP3.Play();//新加的程式碼
      glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}





沒有留言:

張貼留言