Week12
到網路上收尋wave download就可以選擇想要下載的聲音
記得要把檔案存到bin裡
程式碼
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>//為PlaySoundA()
int main()
{
PlaySound("forest.wav",NULL, SND_SYNC );
printf("Hello World\n");
}
程式碼2 (變成滑鼠點擊會發生聲響)
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.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("forest.wav",NULL, SND_SYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12 sound");
glutDisplayFunc(display);
glutMouseFunc(mouse);
PlaySound("forest.wav",NULL, SND_SYNC );
glutMainLoop();
}
程式碼2 (變成滑鼠點擊會發生聲響)
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.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("forest.wav",NULL, SND_SYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12 sound");
glutDisplayFunc(display);
glutMouseFunc(mouse);
PlaySound("forest.wav",NULL, SND_SYNC );
glutMainLoop();
}
include雙引號會在專案裡尋找
所以要把CMP3_MCI.h丟到專案的資料夾裡
上網收尋bgm download,就會有一堆MP3檔
MP3檔案一樣要丟在Freeglut的Bin裡面才讀取的到
程式碼
#include <stdio.h>
#include <GL/glut.h>
#include <windows.h>///定義DWORD
#include <mmsystem.h>///為了PlaySoundA
#include "CMP3_MCI.h" ///TODO3 : 雙引號,要在同一個專案目錄找
CMP3_MCI myMP3; ///TODO3:宣告一個物件變數myMP3
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void mouse(int button , int state, int x, int y) ///todo2 用滑鼠發出聲音
{
if(state==GLUT_DOWN) PlaySoundA("forest.wav",NULL,SND_SYNC);
}
int main(int argc , char**argv)
{
myMP3.Load("bgm_01.mp3");///TODO3:讀入檔案 要放在執行目錄(bin)
myMP3.Play(); ///TODO3:播放
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week12Sound");
glutMouseFunc(mouse); ///todo2 用滑鼠發出聲音
glutDisplayFunc(display);
glutMainLoop();
}
氣氣氣氣~這是人民的法槌,今天他不打倒資本主義的高牆,決不放下。
SYNC > 等它播完 , 會同步
ASYNC > 不等他播完 , 不同步
記得把freeglut\bin裡面的freeglut.dll
和原本的MP3和Wave檔改成放在你的專案資料夾裡
這樣專案檔就會認識你的東西
程式碼( Do Re Mi Fa So)
#include <stdio.h>
#include <GL/glut.h>
#include <windows.h>///定義DWORD
#include <mmsystem.h>///為了PlaySoundA
#include "CMP3_MCI.h" ///TODO3 : 雙引號,要在同一個專案目錄找
CMP3_MCI myMP3; ///TODO3:宣告一個物件變數myMP3
CMP3_MCI Do, Re, Mi, Fa, So; ///TODO5
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void keyboard(unsigned char key, int x ,int y)
{ ///TODO5
if(key=='1') Do.Play();
if(key=='2') Re.Play();
if(key=='3') Mi.Play();
if(key=='4') Fa.Play();
if(key=='5') So.Play();
}
void mouse(int button , int state, int x, int y)
{
if(state==GLUT_DOWN) PlaySoundA("hi.wav",NULL,SND_ASYNC);
}
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") ///TODO5
myMP3.Load("bgm.mp3");///TODO3:讀入檔案 要放在執行目錄(bin)
myMP3.Play(); ///TODO3:播放
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week11Sound");
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
}









沒有留言:
張貼留言