123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #include <iostream>
- #include <SDL/SDL.h>
- #include "Sounderer.h"
- int main ( int argc, char** argv )
- {
- /// [1] Démarrage
- // [1.1] Démarrages SDL
- if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
- {
- std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
- return 1;
- }
- // [1.2] Préparation de fermeture
- atexit(SDL_Quit);
- bool done = false;
- // [1.3] Para-fenêtre
- SDL_WM_SetCaption("Tests du son", 0);
- /// [2] Préparation des composants
- // [2.1] Préparation de la fenêtre
- SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32,
- SDL_HWSURFACE|SDL_DOUBLEBUF);
- if ( !screen )
- {
- std::cout << "Impossible de crée la fenêtre : " << SDL_GetError() << std::endl;
- return 1;
- }
- // [2.2] Préparation du son
- Sounderer soundPlayer("Sons/");
- if (soundPlayer.init() == false) done = true;
- else
- {
- soundPlayer.preLoad("growl1", EXT_OGG);
- soundPlayer.preLoad("breathe1", EXT_OGG);
- soundPlayer.preLoad("fire", EXT_OGG);
- soundPlayer.preLoad("metal1", EXT_OGG);
- }
- // [2.3] Mesures de performance
- /*Uint32 tempsDepart, difference, moyenne, nbTests(100000);
- tempsDepart = SDL_GetTicks();
- for (unsigned int i(0); i<nbTests; i++)
- {
- //quelque chose à mesurer
- }
- difference = SDL_GetTicks() - tempsDepart;
- moyenne = difference / nbTests;
- std::cout << "L'appel de play() a duré " <<difference<<" / "<<nbTests<<" soit "<<moyenne<<"ms en moyenne."<<std::endl;*/
- /// [3] Boucle principale
- while (!done)
- {
- // [3.1] Gestion évènements
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_QUIT:
- done = true;
- break;
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- done = true;
- break;
- case SDLK_b:
- soundPlayer.play("breathe1");
- break;
- case SDLK_e:
- soundPlayer.fadePlay("effect", 3692, INFINITY_LOOP);
- break;
- case SDLK_f:
- soundPlayer.play("fire");
- break;
- case SDLK_g:
- soundPlayer.play("growl1");
- break;
- case SDLK_h:
- soundPlayer.play("hou", 2);
- break;
- default:
- soundPlayer.play("metal1", INFINITY_LOOP);
- break;
- }
- break;
- case SDL_KEYUP:
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- done = true;
- break;
- case SDLK_b:
- soundPlayer.stop("breathe1");
- break;
- case SDLK_e:
- soundPlayer.stop("effect");
- break;
- case SDLK_f:
- soundPlayer.stop("fire");
- break;
- case SDLK_g:
- soundPlayer.stop("growl1");
- break;
- case SDLK_h:
- soundPlayer.stop("hou");
- break;
- default:
- soundPlayer.stop("metal1");
- break;
- }
- break;
- } // end switch event type
- } // end of message processing
- // [3.2] Calculs
- // [3.3] Dessin des composants
- SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 150, 55, 12));
- //
- SDL_Flip(screen);
- } //fin bcl principale
- ///[4] Destruction des composants
- SDL_FreeSurface(screen);
- std::cout << "Aucune erreur détectée." << std::endl;
- return 0;
- }
|