Go to the documentation of this file.00001 #pragma once
00002 #include "OpenAL.h"
00003
00004 namespace REAL
00005 {
00006 namespace GRAPHIC
00007 {
00008 BufferData* loadAUFile(InputStream *stream)
00009 {
00010 int dataOffset;
00011 int len;
00012 int encoding;
00013 int sampleFrequency;
00014 int numChannels;
00015 size_t length;
00016 Codec *codec;
00017 char *data;
00018 ALint bitsPerSample;
00019
00020 if (!_alutInputStreamReadInt32BE (stream, &dataOffset) ||
00021 !_alutInputStreamReadInt32BE (stream, &len) ||
00022 !_alutInputStreamReadInt32BE (stream, &encoding) ||
00023 !_alutInputStreamReadInt32BE (stream, &sampleFrequency) ||
00024 !_alutInputStreamReadInt32BE (stream, &numChannels))
00025 return AL_FALSE;
00026
00027 length = (len == -1) ?
00028 (stream->remainingLength - AU_HEADER_SIZE - dataOffset) : (size_t) len;
00029
00030 if(!(dataOffset >= AU_HEADER_SIZE && length > 0 && sampleFrequency >= 1
00031 && numChannels >= 1))
00032 return AL_FALSE;
00033
00034 if (!_alutInputStreamSkip (stream, dataOffset - AU_HEADER_SIZE))
00035 return AL_FALSE;
00036
00037 switch (encoding)
00038 {
00039 case AU_ULAW_8:
00040 bitsPerSample = 16;
00041 codec = _alutCodecULaw;
00042 break;
00043 case AU_PCM_8:
00044 bitsPerSample = 8;
00045 codec = _alutCodecPCM8s;
00046 break;
00047 case AU_PCM_16:
00048 bitsPerSample = 16;
00049 codec = (endianess() == BigEndian) ? _alutCodecLinear : _alutCodecPCM16;
00050 break;
00051 case AU_ALAW_8:
00052 bitsPerSample = 16;
00053 codec = _alutCodecALaw;
00054 break;
00055 default:
00056 return AL_FALSE;
00057 }
00058
00059 data = _alutInputStreamRead(stream, length);
00060 if (data == NULL)
00061 {
00062 return NULL;
00063 }
00064 return codec(data, length, numChannels, bitsPerSample, (ALfloat)sampleFrequency);
00065 }
00066 }
00067 }