caudio/Source/cwavdecoder.cpp
Joshua Jones 28a22c7f73 Fixed problem with the msvc project not outputting a .lib file.
Updated tutorials to fix minor bugs and pathing issues.  Also fixed crash bug on failure to create the audio object.
Added msvc projects for all tutorials.
Updated the listener class to be self contained and only handle stuff related to the OpenAL listener.  It does NOT init OpenAL anymore, that has been moved to cAudioManager.
Extended the listener class to support all settings that native OpenAL supports.
Cleaned up cFileSource and fixed a crash bug on NULL file handle
Fixed returning bad audio buffer chunk sizes from the cOggDecoder on errors in the ogg stream
Seeking can now be down in fractions of a second now, changed the seconds field from int to float
Fixed various odd formatting.
Fixed potential crash bug in cMemorySource if memory could not be allocated.
cMemorySource will no longer clear the buffer you give to it before filling it with data.  This prevents an overwrite from happening in case of error but the user should provide a zeroed buffer to cMemorySource anyway for safety.
Relative seeking is now supported by cOggDecoder.
2009-08-08 05:51:32 +00:00

84 lines
1.9 KiB
C++

#include "../Headers/cWavDecoder.h"
namespace cAudio{
cWavDecoder::cWavDecoder(IDataSource* stream) : IAudioDecoder(stream)
{
Stream->seek(4,false);
Stream->read(&mChunkSize,4);
Stream->seek(16,false);
Stream->read(&mSubChunk1Size,4);
Stream->read(&mFormat,sizeof(short));
Stream->read(&mChannels,sizeof(short));
Stream->read(&mSampleRate,sizeof(int));
Stream->read(&mByteRate,sizeof(int));
Stream->read(&mBlockAlign,sizeof(short));
Stream->read(&mBitsPerSample,sizeof(short));
Stream->seek(40,false);
Stream->read(&mDataSize,sizeof(int));
Stream->seek(44,false);
//Double the sampleRate to fix a bug with half-time speed
mSampleRate += mSampleRate;
}
cWavDecoder::~cWavDecoder()
{
mChunkSize = 0;
mSubChunk1Size = 0;
mFormat = 0;
mChannels = 0;
mSampleRate = 0;
mByteRate = 0;
mBlockAlign = 0;
mBitsPerSample = 0;
mDataSize = 0;
}
//!Returns wav channel format
AudioFormats cWavDecoder::getFormat()
{
if(mChannels = 1)
return EAF_16BIT_MONO;
else
return EAF_16BIT_STEREO;
}
//!Returns wav data frequency
int cWavDecoder::getFrequency()
{
return mSampleRate;
}
//!Returns if seeking is supported
bool cWavDecoder::isSeekingSupported()
{
return false;
}
//!Reads wav data
int cWavDecoder::readAudioData(void* output, int amount)
{
return Stream->read(output,amount);
}
//!Sets data reader position
bool cWavDecoder::setPosition(int position, bool relative)
{
Stream->seek(position,relative);
return true;
}
//!Seeks wav data
bool cWavDecoder::seek(float seconds,bool relative)
{
return false;
}
}