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

audiere.cpp

Go to the documentation of this file.
00001 #include <string>
00002 #include <string.h>
00003 #include <ctype.h>
00004 #include "audiere.h"
00005 #include "context.hpp"
00006 #include "default_file.hpp"
00007 #include "stream.hpp"
00008 #include "file.hpp"
00009 
00010 
00011 inline Context* ImportContext(ADR_CONTEXT c) { return reinterpret_cast<Context*>(c); }
00012 inline Stream*  ImportStream(ADR_STREAM s)   { return reinterpret_cast<Stream*>(s);  }
00013 inline ADR_CONTEXT ExportContext(Context* c) { return reinterpret_cast<ADR_CONTEXT>(c); }
00014 inline ADR_STREAM  ExportStream(Stream* s)   { return reinterpret_cast<ADR_STREAM>(s);  }
00015 
00016 
00018 
00019 const char* ADR_CALL AdrGetVersion()
00020 {
00021   return "1.0.4";
00022 }
00023 
00025 
00026 ADR_CONTEXT_ATTR ADR_CALL AdrCreateContextAttr()
00027 {
00028   ADR_CONTEXT_ATTR attr = new ADR_CONTEXT_ATTRimp;
00029   attr->output_device = "";
00030   attr->parameters    = "";
00031   attr->opaque        = 0;
00032   attr->open          = DefaultFileOpen;
00033   attr->close         = DefaultFileClose;
00034   attr->read          = DefaultFileRead;
00035   attr->seek          = DefaultFileSeek;
00036   attr->tell          = DefaultFileTell;
00037   return attr;
00038 }
00039 
00041 
00042 void ADR_CALL AdrDestroyContextAttr(
00043   ADR_CONTEXT_ATTR attr)
00044 {
00045   delete attr;
00046 }
00047 
00049 
00050 void ADR_CALL AdrContextAttrSetOutputDevice(
00051   ADR_CONTEXT_ATTR attr,
00052   const char* output_device)
00053 {
00054   attr->output_device = output_device;
00055 }
00056 
00058 
00059 void ADR_CALL AdrContextAttrSetParameters(
00060   ADR_CONTEXT_ATTR attr,
00061   const char* parameters)
00062 {
00063   attr->parameters = parameters;
00064 }
00065 
00067 
00068 void ADR_CALL AdrContextAttrSetOpaque(
00069   ADR_CONTEXT_ATTR attr,
00070   void* opaque)
00071 {
00072   attr->opaque = opaque;
00073 }
00074 
00076 
00077 void ADR_CALL AdrContextAttrSetFileCallbacks(
00078   ADR_CONTEXT_ATTR attr,
00079   ADR_FILE_OPEN  open,
00080   ADR_FILE_CLOSE close,
00081   ADR_FILE_READ  read,
00082   ADR_FILE_SEEK  seek,
00083   ADR_FILE_TELL  tell)
00084 {
00085   if (!open || !close || !read || !seek || !tell) {
00086     attr->open  = DefaultFileOpen;
00087     attr->close = DefaultFileClose;
00088     attr->read  = DefaultFileRead;
00089     attr->seek  = DefaultFileSeek;
00090     attr->tell  = DefaultFileTell;
00091   } else {
00092     attr->open  = open;
00093     attr->close = close;
00094     attr->read  = read;
00095     attr->seek  = seek;
00096     attr->tell  = tell;
00097   }
00098 }
00099 
00101 
00102 ADR_CONTEXT ADR_CALL AdrCreateContext(ADR_CONTEXT_ATTR attr)
00103 {
00104   ADR_GUARD("AdrCreateContext");
00105 
00106   ADR_CONTEXT_ATTR delete_attr = 0;
00107   if (!attr) {
00108     delete_attr = AdrCreateContextAttr();
00109     attr = delete_attr;
00110   }
00111 
00112   // the context always consumes the filesystem in some way or another,
00113   // so we don't have to worry about cleaning it up
00114   IFileSystem* fs = new ADRFileSystem(
00115     attr->opaque,
00116     attr->open,
00117     attr->close,
00118     attr->read,
00119     attr->seek,
00120     attr->tell);
00121 
00122   Context* context = Context::Create(
00123     attr->output_device.c_str(),
00124     attr->parameters.c_str(),
00125     fs);
00126 
00127   delete delete_attr;
00128   return ExportContext(context);
00129 }
00130 
00132 
00133 void ADR_CALL AdrDestroyContext(ADR_CONTEXT context)
00134 {
00135   ADR_GUARD("AdrDestroyContext");
00136 
00137   ImportContext(context)->Release();
00138   ADR_LOG("done releasing context");
00139 }
00140 
00142 
00143 ADR_STREAM ADR_CALL AdrOpenStream(ADR_CONTEXT context, const char* filename)
00144 {
00145   ADR_GUARD("AdrOpenStream");
00146 
00147   return ExportStream(ImportContext(context)->OpenStream(filename));
00148 }
00149 
00151 
00152 void ADR_CALL AdrCloseStream(ADR_STREAM stream)
00153 {
00154   ADR_GUARD("AdrCloseStream");
00155 
00156   delete ImportStream(stream);
00157 }
00158 
00160 
00161 void ADR_CALL AdrPlayStream(ADR_STREAM stream)
00162 {
00163   ADR_GUARD("AdrPlayStream");
00164 
00165   ImportStream(stream)->Play();
00166 }
00167 
00169 
00170 void ADR_CALL AdrPauseStream(ADR_STREAM stream)
00171 {
00172   ADR_GUARD("AdrPauseStream");
00173   
00174   ImportStream(stream)->Pause();
00175 }
00176 
00178 
00179 void ADR_CALL AdrResetStream(ADR_STREAM stream)
00180 {
00181   ADR_GUARD("AdrResetStream");
00182 
00183   ImportStream(stream)->Reset();
00184 }
00185 
00187 
00188 ADR_BOOL ADR_CALL AdrIsStreamPlaying(ADR_STREAM stream)
00189 {
00190   ADR_GUARD("AdrIsStreamPlaying");
00191 
00192   return ImportStream(stream)->IsPlaying() ? ADR_TRUE : ADR_FALSE;
00193 }
00194 
00196 
00197 void ADR_CALL AdrSetStreamRepeat(ADR_STREAM stream, ADR_BOOL repeat)
00198 {
00199   ADR_GUARD("AdrSetStreamRepeat");
00200 
00201   ImportStream(stream)->SetRepeat(repeat == ADR_TRUE);
00202 }
00203 
00205 
00206 ADR_BOOL ADR_CALL AdrGetStreamRepeat(ADR_STREAM stream)
00207 {
00208   ADR_GUARD("AdrGetStreamRepeat");
00209 
00210   return ImportStream(stream)->IsRepeating() ? ADR_TRUE : ADR_FALSE;
00211 }
00212 
00214 
00215 void ADR_CALL AdrSetStreamVolume(ADR_STREAM stream, int volume)
00216 {
00217   ADR_GUARD("AdrSetStreamVolume");
00218 
00219   // make sure the volume is within a valid range
00220   if (volume < ADR_VOLUME_MIN) {
00221     volume = ADR_VOLUME_MIN;
00222   } else if (volume > ADR_VOLUME_MAX) {
00223     volume = ADR_VOLUME_MAX;
00224   }
00225 
00226   ImportStream(stream)->SetVolume(volume);
00227 }
00228 
00230 
00231 int ADR_CALL AdrGetStreamVolume(ADR_STREAM stream)
00232 {
00233   ADR_GUARD("AdrGetStreamVolume");
00234 
00235   return ImportStream(stream)->GetVolume();
00236 }
00237 

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