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;
00066 ALushort src_format;
00067 ALushort dst_format;
00068 double rate_incr;
00069 void *buf;
00070 int len;
00071 int len_cvt;
00072 int len_mult;
00073 double len_ratio;
00074 void (*filters[10])(struct _acAudioCVT *cvt, ALushort format);
00075 int filter_index;
00076 } acAudioCVT;
00077
00078
00079 #define AUDIO_U8 0x0008
00080 #define AUDIO_S8 0x8008
00081 #define AUDIO_U16LSB 0x0010
00082 #define AUDIO_S16LSB 0x8010
00083 #define AUDIO_U16MSB 0x1010
00084 #define AUDIO_S16MSB 0x9010
00085
00086
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
00106 #define FACT 0x74636166
00107 #define LIST 0x5453494c
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;
00141 ALuint frequency;
00142 ALuint byterate;
00143 ALushort blockalign;
00144 ALushort bitspersample;
00145 } alWaveFMT_LOKI;
00146
00147 typedef struct IMA_ADPCM_decodestate_s {
00148 ALint valprev;
00149 ALbyte index;
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
00159
00160
00161
00162 }
00163
00164 #endif