Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
AudioSample.cpp
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#include "KatanaEngine.h"
16
17namespace KatanaEngine
18{
19 bool AudioSample::s_alAddonInitialized = false;
20
22 {
23 if (!s_alAddonInitialized)
24 {
25 al_install_audio();
26 al_init_acodec_addon();
27 s_alAddonInitialized = true;
28 }
29 }
30
32 {
33 al_destroy_sample(m_pSample);
34
35 m_pSample = nullptr;
36 }
37
38
39 bool AudioSample::Load(const std::string& path, ResourceManager* pManager)
40 {
41 ALLEGRO_SAMPLE* pTemp = al_load_sample(path.c_str());
42
43 SetSample(pTemp);
44
45 return m_pSample;
46 }
47
49 {
50 return al_play_sample(m_pSample, m_volume, 0, 1, m_playMode, NULL);
51 }
52
53 void AudioSample::SetLooping(const bool loop)
54 {
55 m_playMode = loop ? ALLEGRO_PLAYMODE_LOOP : ALLEGRO_PLAYMODE_ONCE;
56 }
57
58 void AudioSample::SetVolume(const float volume)
59 {
60 m_volume = Math::Clamp(0, 1, volume);
61 }
62
63
64 void AudioSample::SetSample(ALLEGRO_SAMPLE* pSample)
65 {
66 if (pSample)
67 {
68 m_pSample = pSample;
69 }
70 }
71}
virtual bool Load(const std::string &path, ResourceManager *pManager)
Load the desired font into memory.
virtual void SetSample(ALLEGRO_SAMPLE *pSample)
virtual void SetVolume(const float volume)
virtual void SetLooping(const bool loop=true)
static T Clamp(const T min, const T max, const T value)
Restricts a value to be within a specified range.
Definition MathUtil.h:83
Loads and manages the lifespan of objects from external files.
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18