2016年5月2日 星期一

野比大雄的翻花繩教室week11

課堂作業1:

下載paino do re mi WAV檔
打開CodeBlocks 空專案


新增咒語 winmm 多媒體


將Do.WAV檔放入資料夾

寫入程式

-------------------------今日程式-------------------------

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

--------------------------------------------------------------

完成即可聽到DO DO DO DO DO DO DO~~~~~~


課堂作業2:

開新專案
寫入程式

-----------------------------今日程式--------------------------------

#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可以有do re mi fa so la si~~~~~~



課堂作業3:

載一個MP3檔 丟入專案資料夾
將老師給的"CMP3_MCI"標頭檔也放入資料夾



改寫程式

---------------------------今日程式-----------------------------

#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");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    myMP3.Load("music.mp3");
    myMP3.Play();
    glutMainLoop();
}

-------------------------------------------------------------------------

視窗跳出即有音樂播放且可伴隨鍵盤彈鋼琴

沒有留言:

張貼留言