Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1.  
  2. /*****************************************************************************\
  3. | Sample Class |
  4. | Plays sound effects in the form of WAV files. |
  5. | |
  6. | Author: Cameron Schmidt (Cheesy) |
  7. | Created: 09/05/2011 |
  8. | Updated: 09/05/2011 |
  9. \*****************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <iostream>
  13. #include <allegro5/allegro.h>
  14. #include <allegro5/allegro_audio.h>
  15. #include <allegro5/allegro_acodec.h>
  16.  
  17. class Sample
  18. {
  19. public:
  20. Sample(const char * filename);
  21. private:
  22. ALLEGRO_SAMPLE_INSTANCE *currentSample;
  23. };
  24.  
  25. Sample::Sample(const char * filename)
  26. {
  27. al_init_acodec_addon();
  28. al_reserve_samples(16);
  29. //install a digital sound driver
  30. if (al_is_audio_installed() != 0)
  31. {
  32. al_install_audio();
  33. std::cout << "Audio initialized." << std::endl;
  34. }
  35. else
  36. {
  37. std::cout << "Audio initialized." << std::endl;
  38. }
  39.  
  40.  
  41. ALLEGRO_SAMPLE *sample_data = NULL;
  42. sample_data = al_load_sample(filename);
  43.  
  44.  
  45. if (al_play_sample(sample_data, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL) )
  46. {
  47. std::cout << "SUCCESS!" << std::endl;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement