LCOV - code coverage report
Current view: top level - Core - OOOpenALController.m (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 0 2 0.0 %
Date: 2025-05-28 07:50:54 Functions: 0 0 -

          Line data    Source code
       1           0 : /*
       2             : 
       3             : OOOpenALController.m
       4             : 
       5             : 
       6             : Oolite
       7             : Copyright (C) 2004-2013 Giles C Williams and contributors
       8             : 
       9             : This program is free software; you can redistribute it and/or
      10             : modify it under the terms of the GNU General Public License
      11             : as published by the Free Software Foundation; either version 2
      12             : of the License, or (at your option) any later version.
      13             : 
      14             : This program is distributed in the hope that it will be useful,
      15             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             : GNU General Public License for more details.
      18             : 
      19             : You should have received a copy of the GNU General Public License
      20             : along with this program; if not, write to the Free Software
      21             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
      22             : MA 02110-1301, USA.
      23             : 
      24             : */
      25             : 
      26             : #import "OOOpenALController.h"
      27             : #import "OOLogging.h"
      28             : #import "OOALSoundMixer.h"
      29             : 
      30           0 : static id sSingleton = nil;
      31             : 
      32             : @implementation OOOpenALController
      33             : 
      34             : + (OOOpenALController *) sharedController
      35             : {
      36             :         if (sSingleton == nil)
      37             :         {
      38             :                 sSingleton = [[self alloc] init];
      39             :         }
      40             :         
      41             :         return sSingleton;
      42             : }
      43             : 
      44             : 
      45             : - (id) init
      46             : {
      47             :         self = [super init];
      48             :         if (self != nil)
      49             :         {
      50             :                 NSArray                         *arguments = nil;
      51             :                 NSEnumerator            *argEnum = nil;
      52             :                 NSString                        *arg = nil;
      53             :         
      54             :                 arguments = [[NSProcessInfo processInfo] arguments];
      55             :                 for (argEnum = [arguments objectEnumerator]; (arg = [argEnum nextObject]); )
      56             :                 {
      57             :                         if ([arg isEqual:@"-nosound"] || [arg isEqual:@"--nosound"])  
      58             :                         {
      59             :                                 [self release];
      60             :                                 return nil;
      61             :                         }
      62             :                 }
      63             : 
      64             :                 ALuint error;
      65             :                 device = alcOpenDevice(NULL); // default device
      66             :                 if (!device)
      67             :                 {
      68             :                         OOLog(kOOLogSoundInitError, @"%@", @"Failed to open default sound device");
      69             :                         [self release];
      70             :                         return nil;
      71             :                 }
      72             :                 context = alcCreateContext(device,NULL); // default context
      73             :                 if (!alcMakeContextCurrent(context))
      74             :                 {
      75             :                         OOLog(kOOLogSoundInitError, @"%@", @"Failed to create default sound context");
      76             :                         [self release];
      77             :                         return nil;
      78             :                 }
      79             :                 if ((error = alGetError()) != AL_NO_ERROR)
      80             :                 {
      81             :                         OOLog(kOOLogSoundInitError,@"Error %d creating sound context",error);
      82             :                 }
      83             :                 OOAL(alDistanceModel(AL_NONE)); 
      84             :         }
      85             :         return self;
      86             : }
      87             : 
      88             : 
      89             : - (void) setMasterVolume:(ALfloat) fraction
      90             : {
      91             :         OOAL(alListenerf(AL_GAIN,fraction));
      92             : }
      93             : 
      94             : - (ALfloat) masterVolume
      95             : {
      96             :         ALfloat fraction = 0.0;
      97             :         OOAL(alGetListenerf(AL_GAIN,&fraction));
      98             :         return fraction;
      99             : }
     100             : 
     101             : // only to be called at app shutdown
     102             : // is there a better way to handle this?
     103             : - (void) shutdown
     104             : {
     105             :         [[OOSoundMixer sharedMixer] shutdown];
     106             :         OOAL(alcMakeContextCurrent(NULL));
     107             :         OOAL(alcDestroyContext(context));
     108             :         OOAL(alcCloseDevice(device));
     109             : }
     110             : 
     111             : @end

Generated by: LCOV version 1.14