Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

output.cpp

Go to the documentation of this file.
00001 // *sigh*, looking forward to VS.NET...
00002 #ifdef _MSC_VER
00003 #pragma warning(disable : 4786)
00004 #endif
00005 
00006 
00007 #include <string.h>
00008 #include "debug.hpp"
00009 #include "output_null.hpp"
00010 
00011 #ifdef _WIN32
00012 
00013   // include this before DS8, because it includes <dsound.h>, which defines
00014   // DIRECTSOUND_VERSION
00015   #include "output_ds3.hpp"
00016 
00017   #if DIRECTSOUND_VERSION >= 0x0800
00018     #include "output_ds8.hpp"
00019   #endif
00020 
00021 #endif
00022 
00023 #ifdef WITH_OSS
00024   #include "output_oss.hpp"
00025 #endif
00026 
00027 #ifdef WITH_OPENAL
00028   #include "output_al.hpp"
00029 #endif
00030 
00031 
00033 
00034 template<typename T>
00035 static T* TryOutputContext(const char* parameters)
00036 {
00037   T* context = new T();
00038   if (context->Initialize(parameters)) {
00039     return context;
00040   } else {
00041     delete context;
00042     return 0;
00043   }
00044 }
00045 
00047 
00048 IOutputContext* OpenContext(const char* device, const char* parameters)
00049 {
00050   ADR_GUARD("OpenContext");
00051 
00052   IOutputContext* context;
00053 
00054   #define TRY_CONTEXT(context_type)                         \
00055     context = TryOutputContext<context_type>(parameters);   \
00056     if (context) {                                          \
00057       return context;                                       \
00058     }
00059 
00060 #ifdef _WIN32
00061 
00062   // autodetect
00063   if (strcmp(device, "") == 0 ||
00064       strcmp(device, "autodetect") == 0) {
00065 
00066     #if DIRECTSOUND_VERSION >= 0x0800
00067       TRY_CONTEXT(DS8OutputContext)
00068     #endif
00069     TRY_CONTEXT(DS3OutputContext)
00070 
00071   // DirectSound
00072   } else if (strcmp(device, "directsound") == 0) {
00073 
00074     #if DIRECTSOUND_VERSION >= 0x0800
00075     TRY_CONTEXT(DS8OutputContext)
00076     #endif
00077     TRY_CONTEXT(DS3OutputContext)
00078 
00079 #ifdef WITH_OPENAL
00080 
00081   // OpenAL
00082   } else if (strcmp(device, "openal") == 0) {
00083   
00084     TRY_CONTEXT(ALOutputContext)
00085 
00086 #endif
00087 
00088   // null
00089   } else if (strcmp(device, "null") == 0) {
00090 
00091     TRY_CONTEXT(NullOutputContext);
00092 
00093   }
00094 
00095 #else  // Not WIN32
00096 
00097   if (strcmp(device, "") == 0 ||
00098       strcmp(device, "autodetect") == 0) {
00099 
00100 #ifdef WITH_OSS
00101     TRY_CONTEXT(OSSOutputContext);
00102 #endif
00103 
00104 #ifdef WITH_OPENAL
00105     TRY_CONTEXT(ALOutputContext);
00106 #endif
00107 
00108 #ifdef WITH_OSS
00109   } else if (strcmp(device, "oss") == 0) {
00110     TRY_CONTEXT(OSSOutputContext);
00111 #endif
00112 
00113 #ifdef WITH_OPENAL
00114   } else if (strcmp(device, "openal") == 0) {
00115     TRY_CONTEXT(ALOutputContext);
00116 #endif
00117   } else if (strcmp(device, "null") == 0) {
00118     TRY_CONTEXT(NullOutputContext);
00119   }
00120 
00121 #endif
00122 
00123   // otherwise, just fail
00124   return 0;
00125 }
00126 
00128 
00129 void ParseParameters(const char* parameter_string, ParameterList& parameters)
00130 {
00131   std::string key;
00132   std::string value;
00133 
00134   std::string* current_string = &key;
00135 
00136   // walk the string and generate the parameter list
00137   const char* p = parameter_string;
00138   while (*p) {
00139 
00140     if (*p == '=') {
00141 
00142       current_string = &value;
00143 
00144     } else if (*p == ',') {
00145 
00146       if (key.length() && value.length()) {
00147         parameters.push_back(Parameter(key, value));
00148       }
00149       key   = "";
00150       value = "";
00151       current_string = &key;
00152 
00153     } else {
00154       *current_string += *p;
00155     }
00156 
00157     ++p;
00158   }
00159 
00160   // is there one more parameter without a trailing comma?
00161   if (key.length() && value.length()) {
00162     parameters.push_back(Parameter(key, value));
00163   }
00164 }
00165 

Generated at Mon Jun 10 02:55:12 2002 for audiere by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001