Initial
This commit is contained in:
84
sample/FmtChnk.cpp
Normal file
84
sample/FmtChnk.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <sample/fmtchnk.hpp>
|
||||
#include <common/mmreg.hpp>
|
||||
|
||||
FormatChunk &FormatChunk::operator=(const FormatChunk &someFormatChunk)
|
||||
{
|
||||
formatTag(someFormatChunk.formatTag());
|
||||
channels(someFormatChunk.channels());
|
||||
samplesPerSecond(someFormatChunk.samplesPerSecond());
|
||||
averageBytesPerSecond(someFormatChunk.averageBytesPerSecond());
|
||||
blockAlign(someFormatChunk.blockAlign());
|
||||
bitsPerSample(someFormatChunk.bitsPerSample());
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool FormatChunk::write(MemFile &memFile)
|
||||
{
|
||||
if(!mChunkID.write(memFile))return false;
|
||||
if(!memFile.write((char*)&mSize,sizeof(mSize)))return false;
|
||||
if(!memFile.write((char*)&mFormatTag,sizeof(mFormatTag)))return false;
|
||||
if(!memFile.write((char*)&mChannels,sizeof(mChannels)))return false;
|
||||
if(!memFile.write((char*)&mSamplesPerSecond,sizeof(mSamplesPerSecond)))return false;
|
||||
if(!memFile.write((char*)&mAvgBytesPerSecond,sizeof(mAvgBytesPerSecond)))return false;
|
||||
if(!memFile.write((char*)&mBlockAlign,sizeof(mBlockAlign)))return false;
|
||||
if(!memFile.write((char*)&mBitsPerSample,sizeof(mBitsPerSample)))return false;
|
||||
if(WAVE_FORMAT_ADPCM==formatTag())
|
||||
{
|
||||
mFormatChunkADPCM->write(memFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mExtraInfo.size()>0)
|
||||
{
|
||||
memFile.write((char*)(BYTE*)&mExtraInfo[0],mExtraInfo.size());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FormatChunk::read(FileHandle &handle)
|
||||
{
|
||||
int extraBytes;
|
||||
if(!mChunkID.read(handle))return false;
|
||||
if(!handle.read((BYTE*)&mSize,sizeof(mSize)))return false;
|
||||
if(!handle.read((BYTE*)&mFormatTag,sizeof(mFormatTag)))return false;
|
||||
if(!handle.read((BYTE*)&mChannels,sizeof(mChannels)))return false;
|
||||
if(!handle.read((BYTE*)&mSamplesPerSecond,sizeof(mSamplesPerSecond)))return false;
|
||||
if(!handle.read((BYTE*)&mAvgBytesPerSecond,sizeof(mAvgBytesPerSecond)))return false;
|
||||
if(!handle.read((BYTE*)&mBlockAlign,sizeof(mBlockAlign)))return false;
|
||||
if(!handle.read((BYTE*)&mBitsPerSample,sizeof(mBitsPerSample)))return false;
|
||||
if(WAVE_FORMAT_ADPCM==formatTag())
|
||||
{
|
||||
mFormatChunkADPCM=new FormatChunkADPCM();
|
||||
mFormatChunkADPCM.disposition(PointerDisposition::Delete);
|
||||
if(!mFormatChunkADPCM->read(handle))return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
extraBytes=mSize-(sizeof(mFormatTag)+sizeof(mChannels)+sizeof(mSamplesPerSecond)+sizeof(mAvgBytesPerSecond)+sizeof(mBlockAlign)+sizeof(mBitsPerSample));
|
||||
if(extraBytes<0)extraBytes=0;
|
||||
if(extraBytes)
|
||||
{
|
||||
mExtraInfo.size(extraBytes);
|
||||
handle.read((BYTE*)&mExtraInfo[0],mExtraInfo.size());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String FormatChunk::toString(void)const
|
||||
{
|
||||
String strChunk;
|
||||
strChunk+=String("<FORMATCHUNK>");
|
||||
strChunk+=mChunkID.toString();
|
||||
strChunk+=String(" Size=")+String().fromInt(mSize).quotes();
|
||||
strChunk+=String(" FormatTag=")+String().fromInt(mFormatTag).quotes();
|
||||
strChunk+=String(" Channels=")+String().fromInt(mChannels).quotes();
|
||||
strChunk+=String(" SamplesPerSecond=")+String().fromInt(mSamplesPerSecond).quotes();
|
||||
strChunk+=String(" AvgBytesPerSecond=")+String().fromInt(mAvgBytesPerSecond).quotes();
|
||||
strChunk+=String(" BlockAlign=")+String().fromInt(mBlockAlign).quotes();
|
||||
strChunk+=String(" BitsPerSample=")+String().fromInt(mBitsPerSample).quotes();
|
||||
strChunk+=String(" ExtraInfo=")+String().fromInt(mExtraInfo.size()).quotes()+String("</FORMATCHUNK>");
|
||||
if(WAVE_FORMAT_ADPCM==formatTag())strChunk+=((SmartPointer<FormatChunkADPCM>&)mFormatChunkADPCM)->toString();
|
||||
return strChunk;
|
||||
}
|
||||
Reference in New Issue
Block a user