Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

audioconvert.h

Go to the documentation of this file.
00001 
00028 #ifndef AUDIOCONVERT_H_INCLUDED
00029 #define AUDIOCONVERT_H_INCLUDED
00030 
00031 #include "openalpp/export.h"
00032 #include <AL/al.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include "openalpp/error.h"
00036 
00037 namespace openalpp {
00038 
00042 class OPENALPP_API AudioConvert {
00043   unsigned short channels_,bits_;
00044   unsigned int frequency_;
00045   ALenum format_;
00046  public:
00052   AudioConvert(ALenum format,unsigned int frequency);
00053 
00061   void *apply(void *data,ALenum format,unsigned int frequency,unsigned int &size);
00062 };
00063 
00064 typedef struct _acAudioCVT {
00065   int needed;                     /* Set to 1 if conversion possible */
00066   ALushort src_format;            /* Source audio format */
00067   ALushort dst_format;            /* Target audio format */
00068   double rate_incr;               /* Rate conversion increment */
00069   void   *buf;                    /* Buffer to hold entire audio data */
00070   int    len;                     /* Length of original audio buffer */
00071   int    len_cvt;                 /* Length of converted audio buffer */
00072   int    len_mult;                /* buffer must be len*len_mult big */
00073   double len_ratio;       /* Given len, final size is len*len_ratio */
00074   void (*filters[10])(struct _acAudioCVT *cvt, ALushort format);
00075   int filter_index;               /* Current audio conversion function */
00076 } acAudioCVT;
00077 
00078 /* Audio format flags (defaults to LSB byte order) */
00079 #define AUDIO_U8        0x0008  /* Unsigned 8-bit samples */
00080 #define AUDIO_S8        0x8008  /* Signed 8-bit samples */
00081 #define AUDIO_U16LSB    0x0010  /* Unsigned 16-bit samples */
00082 #define AUDIO_S16LSB    0x8010  /* Signed 16-bit samples */
00083 #define AUDIO_U16MSB    0x1010  /* As above, but big-endian byte order */
00084 #define AUDIO_S16MSB    0x9010  /* As above, but big-endian byte order */
00085 
00086 /* Native audio byte ordering */
00087 #ifndef WORDS_BIGENDIAN
00088 #define AUDIO_U16       AUDIO_U16LSB
00089 #define AUDIO_S16       AUDIO_S16LSB
00090 #define swap16le(x) (x)
00091 #define swap32le(x) (x)
00092 #define swap16be(x) swap16(x)
00093 #define swap32be(x) swap32(x)
00094 #else
00095 #define AUDIO_U16       AUDIO_U16MSB
00096 #define AUDIO_S16       AUDIO_S16MSB
00097 #define swap16le(x) swap16(x)
00098 #define swap32le(x) swap32(x)
00099 #define swap16be(x) (x)
00100 #define swap32be(x) (x)
00101 #endif
00102 
00103 #define _al_ALCHANNELS(fmt) ((fmt==AL_FORMAT_MONO16||fmt==AL_FORMAT_MONO8)?1:2)
00104 
00105 #define DATA            0x61746164              /* "data" */
00106 #define FACT            0x74636166              /* "fact" */
00107 #define LIST            0x5453494c              /* "LIST" */
00108 #define RIFF            0x46464952
00109 #define WAVE            0x45564157
00110 #define FMT             0x20746D66
00111 
00112 #define AL_FORMAT_IMA_ADPCM_MONO16_EXT            0x10000
00113 #define AL_FORMAT_IMA_ADPCM_STEREO16_EXT          0x10001
00114 #define AL_FORMAT_WAVE_EXT                        0x10002
00115 
00116 #define NELEMS(x) ((sizeof x) / (sizeof *x))
00117 
00118 #define PCM_CODE        0x0001
00119 #define MS_ADPCM_CODE   0x0002
00120 #define IMA_ADPCM_CODE  0x0011
00121 
00122 #define MS_ADPCM_max ((1<<(16-1))-1)
00123 #define MS_ADPCM_min -(1<<(16-1))
00124 
00125 typedef struct Chunk {
00126   ALuint magic;
00127   ALuint length;
00128   void *data;
00129 } Chunk;
00130 
00131 struct MS_ADPCM_decodestate_FULL {
00132   ALubyte hPredictor;
00133   ALushort iDelta;
00134   ALshort iSamp1;
00135   ALshort iSamp2;
00136 };
00137 
00138 typedef struct WaveFMT {
00139   ALushort encoding;
00140   ALushort channels;               /* 1 = mono, 2 = stereo */
00141   ALuint frequency;              /* One of 11025, 22050, or 44100 Hz */
00142   ALuint byterate;               /* Average bytes per second */
00143   ALushort blockalign;             /* Bytes per sample block */
00144   ALushort bitspersample;
00145 } alWaveFMT_LOKI;
00146 
00147 typedef struct IMA_ADPCM_decodestate_s {
00148   ALint valprev;  /* Previous output value */
00149   ALbyte index;           /* Index into stepsize table */
00150 } alIMAADPCM_decodestate_LOKI;
00151 
00152 typedef struct IMA_ADPCM_decoder {
00153   alWaveFMT_LOKI wavefmt;
00154   ALushort wSamplesPerBlock;
00155   alIMAADPCM_decodestate_LOKI state[2];
00156 } alIMAADPCM_state_LOKI;
00157 /*
00158 void *AudioConvert(ALvoid *data,
00159                    ALenum f_format, ALuint f_size, ALuint f_freq,
00160                    ALenum t_format, ALuint t_freq, ALuint *retsize);
00161 */
00162 }
00163 
00164 #endif

Generated on Thu Dec 9 14:08:12 2004 for openalpp by  doxygen 1.3.9.1