LCOV - code coverage report
Current view: top level - source/soundmanager/data - SoundData.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 2 58 3.4 %
Date: 2023-01-19 00:18:29 Functions: 2 17 11.8 %

          Line data    Source code
       1             : /* Copyright (C) 2015 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"
      21             : #include "soundmanager/SoundManager.h"
      22             : 
      23             : #if CONFIG2_AUDIO
      24             : 
      25             : #include "OggData.h"
      26             : #include "ps/CLogger.h"
      27             : 
      28           1 : DataMap CSoundData::sSoundData;
      29             : 
      30           0 : CSoundData::CSoundData()
      31           0 :     : m_ALBuffer(0), m_RetentionCount(0)
      32             : {
      33           0 : }
      34             : 
      35           0 : CSoundData::~CSoundData()
      36             : {
      37           0 :     AL_CHECK;
      38           0 :     if (m_ALBuffer != 0)
      39           0 :         alDeleteBuffers(1, &m_ALBuffer);
      40           0 :     m_ALBuffer = 0;
      41           0 :     AL_CHECK;
      42           0 : }
      43             : 
      44           0 : void CSoundData::ReleaseSoundData(CSoundData* theData)
      45             : {
      46           0 :     DataMap::iterator itemFind;
      47             : 
      48           0 :     if (theData->DecrementCount())
      49             :     {
      50           0 :         if ((itemFind = CSoundData::sSoundData.find( theData->GetFileName().string() )) != sSoundData.end())
      51             :         {
      52           0 :             CSoundData::sSoundData.erase(itemFind);
      53             :         }
      54           0 :         delete theData;
      55             :     }
      56           0 : }
      57             : 
      58           0 : CSoundData* CSoundData::SoundDataFromFile(const VfsPath& itemPath)
      59             : {
      60           0 :     Path fExt = itemPath.Extension();
      61           0 :     DataMap::iterator itemFind;
      62           0 :     CSoundData* answer = NULL;
      63             : 
      64           0 :     if ((itemFind = CSoundData::sSoundData.find(itemPath.string())) != sSoundData.end())
      65             :     {
      66           0 :         answer = itemFind->second;
      67             :     }
      68             :     else
      69             :     {
      70           0 :       if (fExt == ".ogg")
      71           0 :             answer = SoundDataFromOgg(itemPath);
      72             : 
      73           0 :         if (answer && answer->IsOneShot())
      74             :         {
      75           0 :             CSoundData::sSoundData[itemPath.string()] = answer;
      76             :         }
      77             : 
      78             :     }
      79             : 
      80           0 :     return answer;
      81             : }
      82             : 
      83           0 : bool CSoundData::IsOneShot()
      84             : {
      85           0 :     return true;
      86             : }
      87             : 
      88             : 
      89           0 : CSoundData* CSoundData::SoundDataFromOgg(const VfsPath& itemPath)
      90             : {
      91           0 :     COggData* oggAnswer = new COggData();
      92             : 
      93           0 :     if (!oggAnswer->InitOggFile(itemPath))
      94             :     {
      95           0 :         LOGERROR("could not initialize ogg data at %s", itemPath.string8());
      96           0 :         delete oggAnswer;
      97           0 :         return NULL;
      98             :     }
      99             : 
     100           0 :     return oggAnswer;
     101             : }
     102             : 
     103           0 : int CSoundData::GetBufferCount()
     104             : {
     105           0 :     return 1;
     106             : }
     107             : 
     108           0 : const Path& CSoundData::GetFileName()
     109             : {
     110           0 :     return m_FileName;
     111             : }
     112             : 
     113           0 : void CSoundData::SetFileName(const Path& aName)
     114             : {
     115           0 :     m_FileName = aName;
     116           0 : }
     117             : 
     118           0 : CSoundData* CSoundData::IncrementCount()
     119             : {
     120           0 :     m_RetentionCount++;
     121           0 :     return this;
     122             : }
     123             : 
     124           0 : bool CSoundData::DecrementCount()
     125             : {
     126           0 :     m_RetentionCount--;
     127             : 
     128           0 :     return (m_RetentionCount <= 0);
     129             : }
     130             : 
     131           0 : unsigned int CSoundData::GetBuffer()
     132             : {
     133           0 :     return m_ALBuffer;
     134             : }
     135             : 
     136           0 : unsigned int* CSoundData::GetBufferPtr()
     137             : {
     138           0 :     return &m_ALBuffer;
     139             : }
     140             : 
     141           0 : bool CSoundData::IsStereo()
     142             : {
     143           0 :     return false;
     144           3 : }
     145             : 
     146             : #endif // CONFIG2_AUDIO
     147             : 

Generated by: LCOV version 1.13