一、
開Console application專案
下載do re mi的wav檔
http://www.openprocessing.org/sketch/132652

將wav檔複製到自己的程式檔的資料夾內

檔案右鍵選擇Build options
Linker settings→ Linker libraries→ Add
增加winmm

#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);//播放聲音
cin>>a;
}
return 0;
}

二,三、
開新檔
選擇Search drectiones→ Compiler→ Add→增加freeglut裡include資料夾路徑

Search drectiones→Linkerr→ Add→增加freeglut裡lib資料夾路徑

Linker settings→ Linker libraries→ Add
新增freeglut
新增opengl32
新增gl32
新增gdi32
新增winmm

freeglut的bin資料夾裡的freeglut.dll複製到外面

#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);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
按1、2、3、4、5、6、7就會出現聲音
四、
找一個mp3檔
youtube的影片可用此網頁轉mp3檔
http://www.youtube-mp3.org/

將CMP3_MCI移入資料夾

#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("screenmode.mp3");//呼叫下載的音樂檔
myMP3.Play();//播放
glutMainLoop();
}

打開後音樂就會自動播放了
四、
找一個mp3檔
youtube的影片可用此網頁轉mp3檔
http://www.youtube-mp3.org/

將CMP3_MCI移入資料夾

#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("screenmode.mp3");//呼叫下載的音樂檔
myMP3.Play();//播放
glutMainLoop();
}

打開後音樂就會自動播放了

沒有留言:
張貼留言