00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "config.h"
00026 #include "Teddy/SysSupport/Messages.h"
00027 #include "Teddy/SpaceGame/AudioManager.h"
00028 #include "Teddy/SpaceGame/Root.h"
00029 #include <cstdio>
00030 using namespace Teddy::SysSupport;
00031
00032
00033 #if defined( WIN32 )
00034 extern "C" {
00035 #include "arch/win32/native_midi.h"
00036 }
00037 #endif
00038
00039 #if defined (HAVE_LIB_SDL_MIXER)
00040
00041 # include "SDL_mixer.h"
00042 # if defined( _MSC_VER)
00043 # if defined( _DEBUG )
00044 # pragma comment (lib, "SDLD_mixer.lib")
00045 # else
00046 # pragma comment (lib, "SDL_mixer.lib")
00047 # endif
00048 # endif
00049
00050 static Mix_Chunk *crash;
00051 static Mix_Chunk *explode;
00052 static Mix_Chunk *hit_em;
00053 static Mix_Chunk *hyper;
00054 static Mix_Chunk *pulse;
00055
00056 #else
00057 # include <cstdio>
00058 static void *crash;
00059 static void *explode;
00060 static void *hit_em;
00061 static void *hyper;
00062 static void *pulse;
00063 #endif
00064
00065
00066 namespace Teddy {
00067 namespace SpaceGame {
00068
00069
00070 AudioManager::AudioManager( Root *root ){
00071 this->root = root;
00072 # if defined( WIN32 )
00073 if( root->isEnabled(RO_AUDIO) == true ){
00074 ::native_midi_init();
00075 init_msg( "native_midi_loadsong..." );
00076 char *mus_fname = "audio/adblue.mid";
00077 NativeMidiSong *music = ::native_midi_loadsong( mus_fname );
00078 if( music != NULL ){
00079 ::native_midi_start( music );
00080 }else{
00081 warn_msg( "Could not load %s", mus_fname );
00082 }
00083 }
00084 # endif
00085
00086 # ifdef HAVE_LIB_SDL_MIXER
00087
00088
00089
00090
00091 if( Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048) < 0 ){
00092 error_msg( MSG_HEAD "Couldn't open audio: %s", SDL_GetError() );
00093 return;
00094 }else{
00095
00096
00097
00098
00099
00100
00101
00102 }
00103
00104 crash = Mix_LoadWAV( "audio/crash.wav" );
00105 explode = Mix_LoadWAV( "audio/explode.wav" );
00106 hit_em = Mix_LoadWAV( "audio/hitem.wav" );
00107 hyper = Mix_LoadWAV( "audio/hyper.wav" );
00108 pulse = Mix_LoadWAV( "audio/pulse.wav" );
00109 if( crash == NULL ) warn_msg( "Could not load audio/crash.wav" );
00110 if( explode == NULL ) warn_msg( "Could not load audio/explode.wav" );
00111 if( hit_em == NULL ) warn_msg( "Could not load audio/hit_em.wav" );
00112 if( hyper == NULL ) warn_msg( "Could not load audio/hyper.wav" );
00113 if( pulse == NULL ) warn_msg( "Could not load audio/pulse.wav" );
00114
00115
00116 # else
00117 warn_msg( "SDL_mixer was not available when built - Audio disabled" );
00118 # endif
00119 }
00120
00121
00122 void AudioManager::playCrash (){ playWav( crash ); }
00123 void AudioManager::playExplode(){ playWav( explode ); }
00124 void AudioManager::playHitEm (){ playWav( hit_em ); }
00125 void AudioManager::playHyper (){ playWav( hyper ); }
00126 void AudioManager::playPulse (){ playWav( pulse ); }
00127
00128
00129 void AudioManager::playWav( void *chunk ){
00130 # ifdef HAVE_LIB_SDL_MIXER
00131 if( root->isEnabled(RO_AUDIO) == true ){
00132 Mix_PlayChannel( -1, (Mix_Chunk*)chunk, 0 );
00133
00134 }else{
00135
00136 }
00137 # endif
00138 }
00139
00140
00141 };
00142 };
00143