Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SoundData.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 "SoundData.h"
22 
23 #if CONFIG2_AUDIO
24 
25 #include "OggData.h"
26 #include "ps/CLogger.h"
27 
28 #include <iostream>
29 
31 
33 {
35 }
36 
38 {
39  AL_CHECK
40  if (m_ALBuffer != 0)
41  alDeleteBuffers(1, &m_ALBuffer);
42  m_ALBuffer = 0;
43  AL_CHECK
44  delete m_FileName;
45 }
46 
48 {
49  m_ALBuffer = 0;
50  m_RetentionCount = 0;
51  m_FileName = NULL;
52 }
53 
55 {
56  DataMap::iterator itemFind;
57 
58  if (theData->DecrementCount())
59  {
60  if ((itemFind = CSoundData::sSoundData.find( theData->GetFileName()->string() )) != sSoundData.end())
61  {
62  CSoundData::sSoundData.erase(itemFind);
63  }
64  delete theData;
65  }
66 }
67 
69 {
70  Path fExt = itemPath.Extension();
71  DataMap::iterator itemFind;
72  CSoundData* answer = NULL;
73 
74  if ((itemFind = CSoundData::sSoundData.find(itemPath.string())) != sSoundData.end())
75  {
76  answer = itemFind->second;
77  }
78  else
79  {
80  if (fExt == ".ogg")
81  answer = SoundDataFromOgg(itemPath);
82 
83  if (answer && answer->IsOneShot())
84  {
85  CSoundData::sSoundData[itemPath.string()] = answer;
86  }
87 
88  }
89 
90  return answer;
91 }
92 
94 {
95  return true;
96 }
97 
98 
100 {
101  CSoundData* answer = NULL;
102  COggData* oggAnswer = new COggData();
103 
104  if ( oggAnswer->InitOggFile(itemPath) )
105  {
106  answer = oggAnswer;
107  }
108  else
109  {
110  LOGERROR(L"could not initialize ogg data at %ls", itemPath.string().c_str());
111  delete oggAnswer;
112  }
113 
114  return answer;
115 }
116 
118 {
119  return 1;
120 }
121 
123 {
124  return m_FileName;
125 }
126 
127 void CSoundData::SetFileName(const Path& aName)
128 {
129  delete m_FileName;
130 
131  m_FileName = new Path( aName );
132 }
133 
135 {
137  return this;
138 }
139 
141 {
143 
144  return (m_RetentionCount <= 0);
145 }
146 
147 unsigned int CSoundData::GetBuffer()
148 {
149  return m_ALBuffer;
150 }
151 
153 {
154  return &m_ALBuffer;
155 }
156 
158 {
159  return false;
160 }
161 
162 #endif // CONFIG2_AUDIO
163 
#define AL_CHECK
Definition: SoundManager.h:40
#define LOGERROR
Definition: CLogger.h:35
std::map< std::wstring, CSoundData * > DataMap
Definition: SoundData.h:30
int m_RetentionCount
Definition: SoundData.h:63
virtual bool IsStereo()
Definition: SoundData.cpp:157
static CSoundData * SoundDataFromFile(const VfsPath &itemPath)
Definition: SoundData.cpp:68
virtual Path * GetFileName()
Definition: SoundData.cpp:122
unsigned int m_ALBuffer
Definition: SoundData.h:62
CSoundData * IncrementCount()
Definition: SoundData.cpp:134
Definition: path.h:75
Path * m_FileName
Definition: SoundData.h:64
const String & string() const
Definition: path.h:123
virtual int GetBufferCount()
Definition: SoundData.cpp:117
virtual void SetFileName(const Path &aName)
Definition: SoundData.cpp:127
virtual unsigned int * GetBufferPtr()
Definition: SoundData.cpp:152
virtual bool InitOggFile(const VfsPath &itemPath)
Definition: OggData.cpp:62
Path Extension() const
Definition: path.h:176
virtual unsigned int GetBuffer()
Definition: SoundData.cpp:147
virtual bool IsOneShot()
Definition: SoundData.cpp:93
bool DecrementCount()
Definition: SoundData.cpp:140
void InitProperties()
Definition: SoundData.cpp:47
virtual ~CSoundData()
Definition: SoundData.cpp:37
static DataMap sSoundData
Definition: SoundData.h:60
static void ReleaseSoundData(CSoundData *theData)
Definition: SoundData.cpp:54
static CSoundData * SoundDataFromOgg(const VfsPath &itemPath)
Definition: SoundData.cpp:99