AudioOutputAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
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         /*pa = "PAUSE_ALL";
00041         sa = "STOP_ALL";
00042         ra = "RESUME_ALL";*/
00043         //"^OUT SND : name=(.*);type=(.*);vol=(.*);$"
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                 //cout<<"PAUSE_ALL"<<endl;
00059         }
00060 
00061         else if(strcmp(STOP_ALL,argv[0])==0){
00062                 device->Stop();
00063                 stopped = true;
00064                 //cout<<"STOP_ALL"<<endl;
00065         }
00066 
00067         else if(strcmp(RESUME_ALL,argv[0])==0){
00068                 device->Start();
00069                 //cout<<"RESUME_ALL"<<endl;
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 /*      MicoleStringStream st;
00094         for(int i=0; i<argc; i++){
00095                 st<<"argv["<<i<<"] = "<<argv[i];
00096                 sendMessage(st.str());
00097                 st.flush();
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                 //Stop playing a file given in argv[0]
00176                 case STOP:
00177 
00178                         device->GetStream(argv[0])->Stop();
00179                         device->RemoveStream(argv[0]);
00180                         break;
00181         
00182                 //Resume playing a file given in argv[0]
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 }

Generated on Tue Oct 16 17:10:42 2007 for Micole by  doxygen 1.4.7