Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************\
- | Sample Class |
- | Plays sound effects in the form of WAV files. |
- | |
- | Author: Cameron Schmidt (Cheesy) |
- | Created: 09/05/2011 |
- | Updated: 09/05/2011 |
- \*****************************************************************************/
- #include <stdio.h>
- #include <iostream>
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_audio.h>
- #include <allegro5/allegro_acodec.h>
- class Sample
- {
- public:
- Sample(const char * filename);
- private:
- ALLEGRO_SAMPLE_INSTANCE *currentSample;
- };
- Sample::Sample(const char * filename)
- {
- al_init_acodec_addon();
- al_reserve_samples(16);
- //install a digital sound driver
- if (al_is_audio_installed() != 0)
- {
- al_install_audio();
- std::cout << "Audio initialized." << std::endl;
- }
- else
- {
- std::cout << "Audio initialized." << std::endl;
- }
- ALLEGRO_SAMPLE *sample_data = NULL;
- sample_data = al_load_sample(filename);
- if (al_play_sample(sample_data, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL) )
- {
- std::cout << "SUCCESS!" << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement