week11
今天老師教我們把音檔放入程式碼中
先發出聲音,在跳出Hello
程式碼:
#include <stdio.h>#include <windows.h>///為了定義DWORD
#include <mmsystem.h>///為了 PlaySoundA()
int main()
{
PlaySoundA("laugh.wav",NULL,SND_SYNC);///輸入檔名
printf("Hello");
}
滑鼠點一下,發出聲音
放開也發出聲音
*用wav音檔*
程式碼:
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void mouse(int button ,int state,int x,int y)
{
if(state==GLUT_DOWN) PlaySoundA("laugh.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 sound");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"///雙引號,表示要再同一個專案目錄尋找
CMP3_MCI myMP3;///宣告一個物件變數 myMP3
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void mouse(int button ,int state,int x,int y)
{
if(state==GLUT_DOWN) PlaySoundA("laugh.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
myMP3.Load("bgm_01.mp3");///背景音樂,讀入檔案
myMP3.Play();///播放
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 sound");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
打開week11.cbp從裡面改變存檔的位置,還需要將音檔那些的全部拉到自己的資料夾,這樣就可以嘞
按數字1-5可發出鋼琴聲,滑鼠按下會有笑聲,原本有背景聲
程式碼:
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
CMP3_MCI Do,Re,Mi,Fa,So;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') Do.Play();///PlaySoundA("do.wav",NULL,SND_ASYNC);
if(key=='2') Re.Play();///PlaySoundA("re.wav",NULL,SND_ASYNC);
if(key=='3') Mi.Play();///PlaySoundA("mi.wav",NULL,SND_ASYNC);
if(key=='4') Fa.Play();///PlaySoundA("fa.wav",NULL,SND_ASYNC);
if(key=='5') So.Play();///PlaySoundA("so.wav",NULL,SND_ASYNC);
}
void mouse(int button ,int state,int x,int y)
{
if(state==GLUT_DOWN) PlaySoundA("laugh.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
Do.Load("do.wav"); Re.Load("re.wav"); Mi.Load("mi.wav");
Fa.Load("fa.wav"); So.Load("so.wav");
myMP3.Load("bgm_01.mp3");
myMP3.Play();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 sound");
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
}







沒有留言:
張貼留言