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: 0 56 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 15 0.0 %

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

Generated by: LCOV version 1.16