00001 #ifndef AUDIERE_H
00002 #define AUDIERE_H
00003
00004
00005
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009
00010
00011
00012 #ifdef _WIN32
00013 # define ADR_CALL __stdcall
00014 #else
00015 # define ADR_CALL
00016 #endif
00017
00018
00019
00020 typedef int ADR_BOOL;
00021 #define ADR_TRUE 1
00022 #define ADR_FALSE 0
00023
00024
00025
00026 struct ADR_FileHandle;
00027 typedef ADR_FileHandle* ADR_FILE;
00028
00029 typedef enum {
00030 ADR_BEGIN,
00031 ADR_CURRENT,
00032 ADR_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
00057 #define ADR_VOLUME_MIN (0)
00058 #define ADR_VOLUME_MAX (255)
00059
00060
00061
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
00069
00070
00071
00072
00073 const char* ADR_CALL AdrGetVersion(void);
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 ADR_CONTEXT_ATTR ADR_CALL AdrCreateContextAttr(void);
00092
00093
00094
00095
00096
00097
00098
00099
00100 void ADR_CALL AdrDestroyContextAttr(
00101 ADR_CONTEXT_ATTR attr);
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 void ADR_CALL AdrContextAttrSetOutputDevice(
00112 ADR_CONTEXT_ATTR attr,
00113 const char* output_device);
00114
00115
00116
00117
00118
00119
00120
00121 void ADR_CALL AdrContextAttrSetParameters(
00122 ADR_CONTEXT_ATTR attr,
00123 const char* parameters);
00124
00125
00126
00127
00128
00129
00130 void ADR_CALL AdrContextAttrSetOpaque(
00131 ADR_CONTEXT_ATTR attr,
00132 void* opaque);
00133
00134
00135
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
00149
00150
00151
00152
00153
00154
00155 ADR_CONTEXT ADR_CALL AdrCreateContext(
00156 ADR_CONTEXT_ATTR attr);
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 void ADR_CALL AdrDestroyContext(
00169 ADR_CONTEXT context);
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 ADR_STREAM ADR_CALL AdrOpenStream(
00182 ADR_CONTEXT context,
00183 const char* filename);
00184
00185
00186
00187
00188
00189
00190
00191
00192 void ADR_CALL AdrCloseStream(
00193 ADR_STREAM stream);
00194
00195
00196
00197
00198
00199
00200
00201
00202 void ADR_CALL AdrPlayStream(
00203 ADR_STREAM stream);
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 void ADR_CALL AdrPauseStream(
00214 ADR_STREAM stream);
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 void ADR_CALL AdrResetStream(
00225 ADR_STREAM stream);
00226
00227
00228
00229
00230
00231
00232
00233
00234 ADR_BOOL ADR_CALL AdrIsStreamPlaying(
00235 ADR_STREAM stream);
00236
00237
00238
00239
00240
00241
00242
00243
00244 void ADR_CALL AdrSetStreamRepeat(
00245 ADR_STREAM stream,
00246 ADR_BOOL repeat);
00247
00248
00249
00250
00251
00252
00253
00254
00255 ADR_BOOL ADR_CALL AdrGetStreamRepeat(
00256 ADR_STREAM);
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 void ADR_CALL AdrSetStreamVolume(
00268 ADR_STREAM stream,
00269 int volume);
00270
00271
00272
00273
00274
00275
00276
00277
00278 int ADR_CALL AdrGetStreamVolume(
00279 ADR_STREAM stream);
00280
00281
00282 #ifdef __cplusplus
00283 }
00284 #endif
00285
00286
00287
00288 #ifdef __cplusplus
00289
00290 #include <exception>
00291 #include <string>
00292
00293 namespace audiere {
00294
00295 class Context;
00296
00297
00298
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
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
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
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