00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "stdafx.h"
00024 #include <AudioOutputAgent.h>
00025 #include <MicoleStringStream.h>
00026 #include <string.h>
00027
00028 AudioOutputAgent::AudioOutputAgent(const string baseDir):MicoleAgent("SoundOutput","Sound Output"),soundBase(baseDir)
00029 {
00030 AudioManager::Initialise();
00031 AudioManager::InitialiseNextDevice("default");
00032 device = AudioManager::GetAudioDevice("default");
00033 assert(device);
00034
00035 bindMessage( "^OUT SND : name=(.+);type=([0-9]+);vol=([0-9]+);spk=(.+);pan=(\-?[0-9]+);$", BUS_CALLBACK_OF(AudioOutputAgent,
00036 handleAudioMessage));
00037 bindMessage("^OUT SND : (STOP_ALL|PAUSE_ALL|RESUME_ALL);$", BUS_CALLBACK_OF(AudioOutputAgent,
00038 handleStopPauseAllMessage));
00039 stopped = false;
00040
00041
00042
00043
00044 }
00045
00046 AudioOutputAgent::~AudioOutputAgent()
00047 {
00048 AudioManager::CleanUp();
00049
00050 }
00051
00052 void AudioOutputAgent::handleStopPauseAllMessage(MicoleBus *app, int argc, const char **argv){
00053
00054
00055
00056 if(strcmp(PAUSE_ALL,argv[0])==0){
00057 device->Pause();
00058
00059 }
00060
00061 else if(strcmp(STOP_ALL,argv[0])==0){
00062 device->Stop();
00063 stopped = true;
00064
00065 }
00066
00067 else if(strcmp(RESUME_ALL,argv[0])==0){
00068 device->Start();
00069
00070 }
00071
00072 }
00073
00074
00075 void AudioOutputAgent::handleAudioMessage(MicoleBus *app, int argc, const char **argv)
00076 {
00077
00078 MicoleStringStream fileName;
00079 fileName<<soundBase<<"\\"<<argv[0];
00080 int type = atoi(argv[1]);
00081 int vol = atoi(argv[2]);
00082 string spk = argv[3];
00083 int pan = atoi(argv[4]);
00084
00085 uint32 speakers = FRONT_SPEAKERS;
00086 if(spk.compare("REAR") == 0)
00087 speakers = REAR_SPEAKERS;
00088 else if(spk.compare("REAR2") == 0)
00089 speakers = SPEAKER_REAR2;
00090 else if(spk.compare("CENSUB") == 0)
00091 speakers = SPEAKER_CENLFE;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 int n=0;
00102 MicoleStringStream id;
00103 switch(type){
00104
00105 case PLAY:
00106 id<<argv[0];
00107 while(device->GetStream(id.str())){
00108 id<<++n;
00109 }
00110 device->CreateStream(id.str(), fileName.str().data(), speakers, false, false);
00111 device->GetStream(id.str())->SetVolume(vol);
00112 device->GetStream(id.str())->SetPanning(pan);
00113 if(stopped){
00114 device->Start();
00115 stopped = false;
00116 }
00117 device->GetStream(id.str())->Play(true);
00118 break;
00119
00120 case PLAY_INTERRUPT:
00121 device->CreateStream(argv[0], fileName.str().data(), speakers, false, false);
00122 device->GetStream(argv[0])->SetVolume(vol);
00123 device->GetStream(argv[0])->SetPanning(pan);
00124 if(stopped){
00125 device->Start();
00126 stopped = false;
00127 }
00128 device->GetStream(argv[0])->Play(true);
00129 break;
00130
00131 case PLAY_INTERRUPT_ALL:
00132 device->Stop();
00133 device->CreateStream(argv[0], fileName.str().data(), speakers, false, false);
00134 device->Start();
00135 device->GetStream(argv[0])->SetVolume(vol);
00136 device->GetStream(argv[0])->SetPanning(pan);
00137 device->GetStream(argv[0])->Play(true);
00138 break;
00139
00140 case LOOP:
00141 device->CreateStream(argv[0], fileName.str().data(), speakers, false, true);
00142 device->GetStream(argv[0])->SetVolume(vol);
00143 device->GetStream(argv[0])->SetPanning(pan);
00144 if(stopped){
00145 device->Start();
00146 stopped = false;
00147 }
00148 device->GetStream(argv[0])->Play(true);
00149 break;
00150
00151 case LOOP_INTERRUPT:
00152 device->CreateStream(argv[0], fileName.str().data(), speakers, false, true);
00153 device->GetStream(argv[0])->SetVolume(vol);
00154 device->GetStream(argv[0])->SetPanning(pan);
00155 if(stopped){
00156 device->Start();
00157 stopped = false;
00158 }
00159 device->GetStream(argv[0])->Play(true);
00160 break;
00161
00162 case LOOP_INTERRUPT_ALL:
00163 device->Stop();
00164 device->CreateStream(argv[0], fileName.str().data(), speakers, false, true);
00165 device->GetStream(argv[0])->SetVolume(vol);
00166 device->GetStream(argv[0])->SetPanning(pan);
00167 device->Start();
00168 device->GetStream(argv[0])->Play(true);
00169 break;
00170
00171 case PAUSE:
00172 device->GetStream(argv[0])->Pause();
00173 break;
00174
00175
00176 case STOP:
00177
00178 device->GetStream(argv[0])->Stop();
00179 device->RemoveStream(argv[0]);
00180 break;
00181
00182
00183 case RESUME:
00184 device->Start();
00185 if(device->GetStream(argv[0]))
00186 device->GetStream(argv[0])->Play(true);
00187 break;
00188
00189
00190 default:
00191
00192 break;
00193 }
00194
00195
00196
00197 }