2016年5月2日 星期一

Week 11

1. 音效、音樂
    (1) 下載 Do Re Mi 的 wav檔  => piano - OpenProcessing
    (2) 打開code blocks 貝殼空專案
          加入#include<windows.h>
                  #include <mmsystem.h>
          輸入程式碼,可以發出聲音
          #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, SNDASYNC);
                      cin >> a;
                }
                return 0;
          }
          設定build options-linker settings加入 winmm
          
    (3)  把Do Re Mi 的wav檔加入在專案資料夾中
           就可以執行程式,聽見Do Re Mi
           
2. 鍵盤
   (1) 設定build options/search directors/compiler  加入 C:\Users\USER\Desktop\freeglut\include
                 build options/search directors/linker  加入  C:\Users\USER\Desktop\freeglut\lib
                 build options/linker settings  加入  freeglut, opengl32, glu32, gdi32, winmm
         
       
   (2) 將Do~Si的wav檔放入專案資料夾中
   (3) 輸入程式碼
        #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);
        glutMainLoop();
    }
   可以按1~7有鋼琴的聲音
   
   但發現沒有聲音,原來是沒有輸入keyboard的指令
   醬就可以用鍵盤控制聲音
   
3.與產業接軌
4. (1) CMP3_MCI.h 放入專案資料夾
    (2) 再將音檔放入music.mp3
          myMP3.Load("music.mp3");
          myMP3.Play();
    (3) #include "CMP3_MCI.h"
          CMP3_MCI myMP3;
          
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
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();
}

沒有留言:

張貼留言