Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CSoundItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "CSoundItem.h"
21 
22 #if CONFIG2_AUDIO
23 
26 
27 #include <iostream>
28 
30 {
31  ResetVars();
32 }
33 
35 {
36  ResetVars();
37  if (InitOpenAL())
38  Attach(sndData);
39 }
40 
42 {
43  Stop();
44  ReleaseOpenAL();
45 }
46 
48 {
49  if ( m_ALSource == 0 )
50  return false;
51 
52  HandleFade();
53 
54  if (m_LastPlay && m_ALSource)
55  {
56  CScopeLock lock(m_ItemMutex);
57  int proc_state;
58  alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
59  AL_CHECK
60  m_ShouldBePlaying = (proc_state != AL_STOPPED);
61  return (proc_state != AL_STOPPED);
62  }
63  return true;
64 }
65 
67 {
68  if (m_SoundData != NULL)
69  {
71  m_SoundData = 0;
72  }
73 
74  if (itemData != NULL)
75  {
76  AL_CHECK
77  alSourcei(m_ALSource, AL_BUFFER, 0);
78  AL_CHECK
79  m_SoundData = itemData->IncrementCount();
80  alSourcei(m_ALSource, AL_BUFFER, m_SoundData->GetBuffer());
81 
82  AL_CHECK
83  }
84 }
85 
86 #endif // CONFIG2_AUDIO
87 
#define AL_CHECK
Definition: SoundManager.h:40
ALuint m_ALSource
Definition: CSoundBase.h:34
Locks a CMutex over this object&#39;s lifetime.
Definition: ThreadUtil.h:73
bool m_ShouldBePlaying
Definition: CSoundBase.h:39
void ReleaseOpenAL()
Definition: CSoundBase.cpp:42
bool m_LastPlay
Definition: CSoundBase.h:37
void Stop()
Definition: CSoundBase.cpp:349
CSoundData * IncrementCount()
Definition: SoundData.cpp:134
virtual ~CSoundItem()
Definition: CSoundItem.cpp:41
bool HandleFade()
Definition: CSoundBase.cpp:222
void ResetVars()
Definition: CSoundBase.cpp:67
CMutex m_ItemMutex
Definition: CSoundBase.h:48
void Attach(CSoundData *itemData)
Definition: CSoundItem.cpp:66
bool IdleTask()
Definition: CSoundItem.cpp:47
bool InitOpenAL()
Definition: CSoundBase.cpp:96
CSoundData * m_SoundData
Definition: CSoundBase.h:35
static void ReleaseSoundData(CSoundData *theData)
Definition: SoundData.cpp:54