本周利用程式碼的撰寫,將音樂播放出來
程式碼:
#include <windows.h>
int main()
{
PlaySound("pig.wav",NULL,SND_SYNC);
}
#include <windows.h>
#include <stdio.h>
int main()
{
char c;
while(1){
c=getchar();
PlaySound("do.wav",NULL,SND_ASYNC);
}
}
程式碼:
#include <windows.h>
#include <stdio.h>
int main()
{
char c;
while(1){
c=getchar();
if(c=='1')PlaySound("do.wav",NULL,SND_ASYNC);
if(c=='2')PlaySound("re.wav",NULL,SND_ASYNC);
if(c=='3')PlaySound("mi.wav",NULL,SND_ASYNC);
if(c=='4')PlaySound("fa.wav",NULL,SND_ASYNC);
if(c=='5')PlaySound("so.wav",NULL,SND_ASYNC);
}
}
(以上程式碼便可以利用數字的呈現而播放出想要的音階)
程式碼:
#include <windows.h>
#include <stdio.h>
void display
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1')PlaySound("do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySound("re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySound("mi.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week10 sound");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
#include <windows.h>
#include <stdio.h>
void display
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1')PlaySound("do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySound("re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySound("mi.wav",NULL,SND_ASYNC);
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)PlaySound("shot.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week10 sound");
glutDisplayFunc(display);
glutMouseFunc(mouse);
#include <stdio.h>
void display
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1')PlaySound("do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySound("re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySound("mi.wav",NULL,SND_ASYNC);
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)PlaySound("shot.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week10 sound");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
}
程式碼:(將所有程式碼集合起來並播放)
#include <windows.h>
#include <GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI mp3;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') PlaySound("do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySound("fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySound("so.wav",NULL,SND_ASYNC);
}
void mouse(int button ,int state,int x,int y)
{
if(state==GLUT_DOWN)PlaySound("shot.wav",NULL,SND_ASYNC);
}
int main(int argc,char**argv)
{
mp3.Load("music.mp3");
mp3.Play();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10 sound");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop();
}






沒有留言:
張貼留言