Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

BaseAudioManager.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: BaseAudioManager.cpp,v 1.3 2002/03/12 10:46:06 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/TeddyConfig.h"
00026 #include "Teddy/Application/BaseAudioManager.h"
00027 #include "Teddy/Application/BaseRoot.h"
00028 #include "Teddy/SysSupport/Messages.h"
00029 #include "Teddy/SysSupport/StdIO.h"
00030 using namespace Teddy::SysSupport;
00031 
00032 
00033 #if defined( HAVE_LIB_SDL_MIXER ) && !defined( DISABLE_AUDIO )
00034 
00035 # include "SDL_mixer.h"
00036 # if defined( _MSC_VER )
00037 #  if defined( _DEBUG )
00038 #   pragma comment (lib, "SDL_mixerD.lib")
00039 #  else
00040 #   pragma comment (lib, "SDL_mixer.lib")
00041 #  endif
00042 # endif
00043 
00044 
00045 #else
00046 # include "Teddy/SysSupport/StdIO.h"
00047 #endif
00048 
00049 
00050 namespace Teddy       {
00051 namespace Application {
00052 
00053 
00054 const int BaseAudioManager::OPT_MASTER  = (1ul<<1ul);  //  unused
00055 const int BaseAudioManager::OPT_SAMPLES = (1ul<<2ul);
00056 const int BaseAudioManager::OPT_MIDI    = (1ul<<3ul);
00057 const int BaseAudioManager::OPT_CD      = (1ul<<4ul);  //  unused
00058 
00059 
00060 BaseAudioManager::BaseAudioManager( const Options &options )
00061 :
00062 options(options)
00063 {
00064 /*
00065 #   if defined( _WIN32 ) && !defined( DISABLE_AUDIO )
00066     if( this->options.isEnabled(OPT_MIDI) == true ){
00067         ::native_midi_init();
00068         msg( "native_midi_loadsong..." );
00069         char *mus_fname = "audio/adblue.mid";
00070         NativeMidiSong *music = ::native_midi_loadsong( mus_fname );
00071         if( music != NULL ){
00072             ::native_midi_start( music );
00073         }else{
00074             msg( M_AUDIO, "Could not load %s", mus_fname );
00075         }
00076     }
00077 #   endif
00078 */
00079 #   if defined( HAVE_LIB_SDL_MIXER ) && !defined( DISABLE_AUDIO )
00080 //  signal( SIGINT,  exit );
00081 //  signal( SIGTERM, exit );
00082 
00083     /* Open the audio device */
00084     if( Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) < 0 ){
00085         emsg( M_AUDIO, MSG_HEAD "Couldn't open audio: %s", SDL_GetError() );
00086         return;
00087     }else{
00088 //      Mix_QuerySpec( &audio_rate, &audio_format, &audio_channels );
00089 /*      printf(
00090             "Opened audio at %d Hz %d bit %s\n",
00091             audio_rate,
00092             (audio_format&0xFF),
00093             (audio_channels > 1) ? "stereo" : "mono"
00094         );*/
00095     }
00096 
00097 #   else
00098     dmsg( M_AUDIO, "SDL_mixer was not available when built - Audio disabled" );
00099 #   endif
00100 }
00101 
00102 
00103 void BaseAudioManager::playWav( void *chunk ){
00104 #   if defined( HAVE_LIB_SDL_MIXER ) && !defined( DISABLE_AUDIO )
00105     if( options.isEnabled(OPT_SAMPLES) == true ){
00106         Mix_PlayChannel( -1, (Mix_Chunk*)chunk, 0 );
00107     }else{
00108     }
00109 #   endif
00110 }
00111 
00112 
00113 Options &BaseAudioManager::getOptions(){
00114     return options;
00115 }
00116 
00117 
00118 };  //  namespace SpaceGame
00119 };  //  namespace Teddy
00120