AudioManager.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 #pragma warning(disable:4786)
00024 
00025 #include "stdafx.h"
00026 #include <windows.h>
00027 
00028 #include "AudioManager.h"
00029 #include "util.h"
00030 
00032 
00033 AudioDeviceMap AudioManager::audioDeviceMap;
00034 ErrorCodeMap AudioManager::errorCodeMap;
00035 
00037 
00038 void AudioManager::FillUpErrorCodeMap (void)
00039 {
00040         errorCodeMap[0] = "OK";
00041         errorCodeMap[1] = "Error_MEM";
00042         errorCodeMap[2] = "Error_FILEOPEN";
00043         errorCodeMap[3] = "Error_DRIVER";
00044         errorCodeMap[4] = "Error_BUFLOST";
00045         errorCodeMap[5] = "Error_HANDLE";
00046         errorCodeMap[6] = "Error_FORMAT";
00047         errorCodeMap[7] = "Error_POSITION";
00048         errorCodeMap[8] = "Error_INIT";
00049         errorCodeMap[9] = "Error_START";
00050         errorCodeMap[14] = "Error_ALREADY";
00051         errorCodeMap[16] = "Error_NOPAUSE";
00052         errorCodeMap[18] = "Error_NOCHAN";
00053         errorCodeMap[19] = "Error_ILLTYPE";
00054         errorCodeMap[20] = "Error_ILLPARAM";
00055         errorCodeMap[21] = "Error_NO3D";
00056         errorCodeMap[22] = "Error_NOEAX";
00057         errorCodeMap[23] = "Error_DEVICE";
00058         errorCodeMap[24] = "Error_NOPLAY";
00059         errorCodeMap[25] = "Error_FREQ";
00060         errorCodeMap[27] = "Error_NOTFILE";
00061         errorCodeMap[29] = "Error_NOHW";
00062         errorCodeMap[31] = "Error_EMPTY";
00063         errorCodeMap[32] = "Error_NONET";
00064         errorCodeMap[33] = "Error_CREATE";
00065         errorCodeMap[34] = "Error_NOFX";
00066         errorCodeMap[35] = "Error_PLAYING";
00067         errorCodeMap[37] = "Error_NOTAVAIL";
00068         errorCodeMap[38] = "Error_DECODE";
00069         errorCodeMap[39] = "Error_DX";
00070         errorCodeMap[40] = "Error_TIMEOUT";
00071         errorCodeMap[41] = "Error_FILEFORM";
00072         errorCodeMap[42] = "Error_SPEAKER";
00073         errorCodeMap[43] = "Error_VERSION";
00074         errorCodeMap[44] = "Error_CODEC";
00075         errorCodeMap[-1] = "Error_UNKNOWN";
00076 }
00077 
00079 
00080 void AudioManager::CheckError (void)
00081 {
00082         char message[128];
00083         uint8 error;
00084 
00085         if(error = BASS_ErrorGetCode())
00086                 sprintf_s(message, "%s", errorCodeMap[error]);
00087 }
00088 
00090 
00091 void AudioManager::Initialise (void)
00092 {
00093         FillUpErrorCodeMap();
00094 }
00095 
00097 
00098 void AudioManager::CleanUp (void)
00099 {
00100         AudioDeviceMap::const_iterator iter;
00101 
00102         for(iter = audioDeviceMap.begin(); iter != audioDeviceMap.end(); ++iter)
00103                 delete (*iter).second;
00104 
00105         audioDeviceMap.clear();
00106 }
00107 
00109 
00110 bool AudioManager::SetActiveDevice (std::string id)
00111 {
00112         AudioDevice* audioDevice;
00113 
00114         if((audioDevice = audioDeviceMap[id]) == (AudioDevice*)(0))
00115                 return false;
00116         else
00117                 return !!BASS_SetDevice(audioDevice->GetDeviceID());
00118 }
00119 
00121 
00122 AudioDevice* AudioManager::InitialiseNextDevice (std::string id)
00123 {
00124         AudioDevice* audioDevice;
00125         AudioDeviceMap::const_iterator iter;
00126 
00127         if(!(audioDevice = new AudioDevice(id)))
00128                 return (AudioDevice*)0;
00129 
00130         if((iter = audioDeviceMap.find(id)) == audioDeviceMap.end())
00131                 audioDeviceMap[id] = audioDevice;
00132         else {
00133                 delete (*iter).second;
00134                 audioDeviceMap[id] = audioDevice;
00135         }
00136         return audioDevice;
00137 }
00138 
00140 
00141 bool AudioManager::CloseDevice (std::string id)
00142 {
00143         AudioDeviceMap::iterator iter;
00144 
00145         if((iter = audioDeviceMap.find(id)) == audioDeviceMap.end())
00146                 return false;
00147         else
00148         {
00149                 delete (*iter).second;
00150                 audioDeviceMap.erase(iter);
00151                 return true;
00152         }
00153 }
00154 
00156 
00157 AudioDevice* AudioManager::GetAudioDevice (std::string id)
00158 {
00159         AudioDeviceMap::const_iterator iter;
00160 
00161         if((iter = audioDeviceMap.find(id)) == audioDeviceMap.end())
00162                 return (AudioDevice*)(0);
00163         else
00164                 return (*iter).second;
00165 }
00166 
00168 
00169 uint8 AudioManager::GetAudioDeviceNum (void)
00170 {
00171         return uint8(audioDeviceMap.size());
00172 }
00173 

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