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

audiere.h

Go to the documentation of this file.
00001 #ifndef AUDIERE_H
00002 #define AUDIERE_H
00003 
00004 
00005 /* extern C */
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 
00011 /* calling convention */
00012 #ifdef _WIN32
00013 #  define ADR_CALL __stdcall
00014 #else
00015 #  define ADR_CALL
00016 #endif
00017 
00018 
00019 /* boolean */
00020 typedef int ADR_BOOL;
00021 #define ADR_TRUE  1
00022 #define ADR_FALSE 0
00023 
00024 
00025 /* file callback types */
00026 struct ADR_FileHandle;
00027 typedef ADR_FileHandle* ADR_FILE;
00028 
00029 typedef enum {
00030   ADR_BEGIN,   // stdio SEEK_SET
00031   ADR_CURRENT, // stdio SEEK_CUR
00032   ADR_END,     // stdio SEEK_END
00033 } ADR_SEEK_TYPE;
00034 
00035 typedef ADR_FILE (ADR_CALL *ADR_FILE_OPEN)(
00036   void* opaque,
00037   const char* filename);
00038 
00039 typedef void (ADR_CALL *ADR_FILE_CLOSE)(
00040   ADR_FILE file);
00041 
00042 typedef int (ADR_CALL *ADR_FILE_READ)(
00043   ADR_FILE file,
00044   void* buffer,
00045   int size);
00046 
00047 typedef ADR_BOOL (ADR_CALL *ADR_FILE_SEEK)(
00048   ADR_FILE file,
00049   int offset,
00050   ADR_SEEK_TYPE type);
00051 
00052 typedef int (ADR_CALL *ADR_FILE_TELL)(
00053   ADR_FILE file);
00054 
00055 
00056 /* constants */
00057 #define ADR_VOLUME_MIN (0)
00058 #define ADR_VOLUME_MAX (255)
00059 
00060 
00061 /* audiere opaque types */
00062 typedef struct ADR_CONTEXT_ATTRimp* ADR_CONTEXT_ATTR;
00063 typedef struct ADR_CONTEXTimp*      ADR_CONTEXT;
00064 typedef struct ADR_STREAMimp*       ADR_STREAM;
00065 
00066 
00067 /*
00068  * AdrGetVersion()
00069  *
00070  * Returns Audiere version string.
00071  *
00072  */
00073 const char* ADR_CALL AdrGetVersion(void);
00074 
00075 
00076 /*
00077  * AdrCreateContextAttr()
00078  *
00079  * Returns context attributes object with values set to defaults.
00080  *
00081  * output_device = ""
00082  * parameters    = ""
00083  * opaque        = 0
00084  * open          = default open
00085  * close         = default close
00086  * read          = default read
00087  * seek          = default seek
00088  * tell          = default tell
00089  *
00090  */
00091 ADR_CONTEXT_ATTR ADR_CALL AdrCreateContextAttr(void);
00092 
00093 
00094 /*
00095  * AdrDestroyContextAttr(attr)
00096  *
00097  * Destroys a context attributes object.
00098  *
00099  */
00100 void ADR_CALL AdrDestroyContextAttr(
00101   ADR_CONTEXT_ATTR attr);
00102 
00103 
00104 /*
00105  * output_device -- 
00106  *   string that represents the output device you want to use
00107  *   "" or "autodetect" will search for a good default device
00108  *   "null" is no sound
00109  *
00110  */
00111 void ADR_CALL AdrContextAttrSetOutputDevice(
00112   ADR_CONTEXT_ATTR attr,
00113   const char* output_device);
00114 
00115 /*
00116  * parameters --
00117  *   comma-delimited list of output device-specific parameters
00118  *   for example, "buffer=100,rate=44100"
00119  *
00120  */
00121 void ADR_CALL AdrContextAttrSetParameters(
00122   ADR_CONTEXT_ATTR attr,
00123   const char* parameters);
00124 
00125 /*
00126  * opaque --
00127  *   opaque handle passed into file I/O functions
00128  *
00129  */
00130 void ADR_CALL AdrContextAttrSetOpaque(
00131   ADR_CONTEXT_ATTR attr,
00132   void* opaque);
00133 
00134 /*
00135  * file callbacks
00136  *
00137  */
00138 void ADR_CALL AdrContextAttrSetFileCallbacks(
00139   ADR_CONTEXT_ATTR attr,
00140   ADR_FILE_OPEN  open,
00141   ADR_FILE_CLOSE close,
00142   ADR_FILE_READ  read,
00143   ADR_FILE_SEEK  seek,
00144   ADR_FILE_TELL  tell);
00145 
00146 
00147 /*
00148  * AdrCreateContext(attributes)
00149  *
00150  * Returns a new Audiere context or NULL if failure.
00151  *
00152  * attributes - set of context attributes, or NULL for defaults
00153  *
00154  */
00155 ADR_CONTEXT ADR_CALL AdrCreateContext(
00156   ADR_CONTEXT_ATTR attr);
00157 
00158 
00159 /*
00160  * AdrDestroyContext(context)
00161  *
00162  * Destroys a context, stopping the update thread and closing the output device.
00163  * Contexts aren't actually destroyed until all child streams are closed.
00164  *
00165  * context - the context to destroy, of course  ;)
00166  *
00167  */
00168 void ADR_CALL AdrDestroyContext(
00169   ADR_CONTEXT context);
00170 
00171 
00172 /*
00173  * AdrOpenStream(context, filename)
00174  *
00175  * Returns a new audio stream, or NULL if failure.
00176  *
00177  * context  - context within which to create the audio stream
00178  * filename - UTF-8 filename passed into file open callback
00179  *
00180  */
00181 ADR_STREAM ADR_CALL AdrOpenStream(
00182   ADR_CONTEXT context,
00183   const char* filename);
00184 
00185 
00186 /*
00187  * AdrCloseStream(stream)
00188  *
00189  * Closes a stream, halting audio output.
00190  *
00191  */
00192 void ADR_CALL AdrCloseStream(
00193   ADR_STREAM stream);
00194 
00195 
00196 /*
00197  * AdrPlayStream(stream)
00198  *
00199  * Begins playback of an audio stream.
00200  *
00201  */
00202 void ADR_CALL AdrPlayStream(
00203   ADR_STREAM stream);
00204 
00205 
00206 /*
00207  * AdrPauseStream(stream)
00208  *
00209  * Halts playback of an audio stream, but does not reset the position to the
00210  * beginning.
00211  *
00212  */
00213 void ADR_CALL AdrPauseStream(
00214   ADR_STREAM stream);
00215 
00216 
00217 /*
00218  * AdrResetStream(stream)
00219  *
00220  * Resets the current position within the sound file to the beginning.
00221  * This may be called at any time.
00222  *
00223  */
00224 void ADR_CALL AdrResetStream(
00225   ADR_STREAM stream);
00226 
00227 
00228 /*
00229  * AdrIsPlaying(stream)
00230  *
00231  * Returns ADR_TRUE if the stream is currently playing audio.
00232  *
00233  */
00234 ADR_BOOL ADR_CALL AdrIsStreamPlaying(
00235   ADR_STREAM stream);
00236 
00237 
00238 /*
00239  * AdrSetStreamRepeat(stream, repeat)
00240  *
00241  * If repeat is on and playback reaches the end of the stream, it will
00242  * automatically reset the stream and continue playback.
00243  */
00244 void ADR_CALL AdrSetStreamRepeat(
00245   ADR_STREAM stream,
00246   ADR_BOOL repeat);
00247 
00248 
00249 /*
00250  * AdrGetStreamRepeat(stream)
00251  *
00252  * Returns the repeat flag for the given stream.  Repeat defaults to false.
00253  *
00254  */
00255 ADR_BOOL ADR_CALL AdrGetStreamRepeat(
00256   ADR_STREAM);
00257 
00258 
00259 /*
00260  * AdrSetStreamVolume(stream, volume)
00261  *
00262  * Sets the stream volume.  Defaults to ADR_VOLUME_MAX.
00263  * ADR_VOLUME_MIN is silence.
00264  * ADR_VOLUME_MAX is full volume.
00265  *
00266  */
00267 void ADR_CALL AdrSetStreamVolume(
00268   ADR_STREAM stream,
00269   int volume);
00270 
00271 
00272 /*
00273  * AdrGetStreamVolume(stream)
00274  *
00275  * Returns the current stream volume.
00276  *
00277  */
00278 int ADR_CALL AdrGetStreamVolume(
00279   ADR_STREAM stream);
00280 
00281 
00282 #ifdef __cplusplus
00283 }
00284 #endif
00285 
00286 
00287 // C++ convenience classes 
00288 #ifdef __cplusplus
00289 
00290 #include <exception>
00291 #include <string>
00292 
00293 namespace audiere {
00294 
00295   class Context;
00296 
00297 
00298   // STREAM
00299 
00300   class Stream {
00301   private:
00302     Stream(ADR_STREAM stream) {
00303       m_stream = stream;
00304     }
00305 
00306   public:
00307     ~Stream() {
00308       AdrCloseStream(m_stream);
00309     }
00310 
00311     void play() {
00312       AdrPlayStream(m_stream);
00313     }
00314     void pause() {
00315       AdrPauseStream(m_stream);
00316     }
00317     void reset() {
00318       AdrResetStream(m_stream);
00319     }
00320     bool isPlaying() {
00321       return (AdrIsStreamPlaying(m_stream) == ADR_TRUE);
00322     }
00323     void setRepeat(bool repeat) {
00324       AdrSetStreamRepeat(m_stream, repeat ? ADR_TRUE : ADR_FALSE);
00325     }
00326     bool getRepeat() {
00327       return (AdrGetStreamRepeat(m_stream) == ADR_TRUE);
00328     }
00329     void setVolume(int volume) {
00330       AdrSetStreamVolume(m_stream, volume);
00331     }
00332     int getVolume() {
00333       return AdrGetStreamVolume(m_stream);
00334     }
00335     
00336   private:
00337     ADR_STREAM m_stream;
00338 
00339     friend class Context;
00340   };
00341 
00342 
00343   // CONTEXT ATTRIBUTES
00344 
00345   class ContextAttr {
00346   public:
00347     ContextAttr() {
00348       m_attr = AdrCreateContextAttr();
00349     }
00350 
00351     ~ContextAttr() {
00352       AdrDestroyContextAttr(m_attr);
00353     }
00354 
00355     void setOutputDevice(const char* device) {
00356       AdrContextAttrSetOutputDevice(m_attr, device);
00357     }
00358     void setParameters(const char* parameters) {
00359       AdrContextAttrSetParameters(m_attr, parameters);
00360     }
00361     void setOpaque(void* opaque) {
00362       AdrContextAttrSetOpaque(m_attr, opaque);
00363     }
00364     void setFileCallbacks(
00365         ADR_FILE_OPEN  open,
00366         ADR_FILE_CLOSE close,
00367         ADR_FILE_READ  read,
00368         ADR_FILE_SEEK  seek,
00369         ADR_FILE_TELL  tell) {
00370       
00371       AdrContextAttrSetFileCallbacks(m_attr, open, close, read, seek, tell);
00372     }
00373 
00374   private:
00375     ADR_CONTEXT_ATTR m_attr;
00376 
00377     friend Context* CreateContext(ContextAttr* attr);
00378   };
00379 
00380 
00381   // CONTEXT
00382 
00383   class Context {
00384   private:
00385     Context(ADR_CONTEXT context) {
00386       m_context = context;
00387     }
00388 
00389   public:
00390     ~Context() {
00391       AdrDestroyContext(m_context);
00392     }
00393 
00394     Stream* openStream(const char* filename) {
00395       ADR_STREAM stream = AdrOpenStream(m_context, filename);
00396       return (stream ? new Stream(stream) : 0);
00397     }
00398 
00399   private:
00400     ADR_CONTEXT m_context;
00401 
00402     friend Context* CreateContext(ContextAttr* attr);
00403   };
00404 
00405 
00406   // CONTEXT FACTORY
00407   inline Context* CreateContext(ContextAttr* attr = 0) {
00408     ADR_CONTEXT context = AdrCreateContext(attr ? attr->m_attr : 0);
00409     return (context ? new Context(context) : 0);
00410   }
00411 }
00412 
00413 #endif
00414 
00415 
00416 #endif

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