2020年5月12日 星期二

第十二週


SOUND


#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
int main()
{
   PlaySoundA("bomb.wav",NULL,SND_SYNC);
    printf("HELLO WORD\n");
    PlaySoundA("bomb.wav",NULL,SND_SYNC);
    PlaySoundA("bomb.wav",NULL,SND_SYNC);
}

滑鼠點擊發出聲音


#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("bomb.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week12 sound");

    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
}

播放MP3


#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI 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("bomb.wav",NULL,SND_SYNC);
}
int main(int argc,char**argv)
{
    myMP3.Load("rain.mp3");
    myMP3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week12 sound");

    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
}

音樂與滑鼠點擊不同步


按鍵播放音樂


#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;
    if(key=='2')Re.Play;
    if(key=='3')Me.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("bomb.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");
    myMP3.Load("rain.mp3");
    myMP3.Play();
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week12 sound");

    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
}

沒有留言:

張貼留言