Build fixes (gcc4).

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30136 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-04-12 10:08:22 +00:00
parent 1e855c376c
commit 0b8b543af8
7 changed files with 134 additions and 120 deletions

View File

@ -41,9 +41,9 @@ const char* lib_monkeys_audio_components()
//------------------------------------------------------------------------------
const char* lib_monkeys_audio_copyright()
{
static string saCright;
static std::string saCright;
saCright = string(gCright)+"\n"+gOriginal;
saCright = std::string(gCright)+"\n"+gOriginal;
return saCright.c_str();
}
//------------------------------------------------------------------------------

View File

@ -1,6 +1,8 @@
#include "All.h"
#include "APEDecompress.h"
#include <algorithm>
#include "APEInfo.h"
#include "Prepare.h"
#include "UnBitArray.h"
@ -35,14 +37,17 @@ CAPEDecompress::CAPEDecompress(int * pErrorCode, CAPEInfo * pAPEInfo, int nStart
m_bErrorDecodingCurrentFrame = FALSE;
// set the "real" start and finish blocks
m_nStartBlock = (nStartBlock < 0) ? 0 : min(nStartBlock, GetInfo(APE_INFO_TOTAL_BLOCKS));
m_nFinishBlock = (nFinishBlock < 0) ? GetInfo(APE_INFO_TOTAL_BLOCKS) : min(nFinishBlock, GetInfo(APE_INFO_TOTAL_BLOCKS));
m_nStartBlock = (nStartBlock < 0)
? 0 : std::min(nStartBlock, GetInfo(APE_INFO_TOTAL_BLOCKS));
m_nFinishBlock = (nFinishBlock < 0)
? GetInfo(APE_INFO_TOTAL_BLOCKS)
: std::min(nFinishBlock, GetInfo(APE_INFO_TOTAL_BLOCKS));
m_bIsRanged = (m_nStartBlock != 0) || (m_nFinishBlock != GetInfo(APE_INFO_TOTAL_BLOCKS));
}
CAPEDecompress::~CAPEDecompress()
{
}
int CAPEDecompress::InitializeDecompressor()
@ -56,7 +61,7 @@ int CAPEDecompress::InitializeDecompressor()
// create a frame buffer
m_cbFrameBuffer.CreateBuffer((GetInfo(APE_INFO_BLOCKS_PER_FRAME) + DECODE_BLOCK_SIZE) * m_nBlockAlign, m_nBlockAlign * 64);
// create decoding components
m_spUnBitArray.Assign((CUnBitArrayBase *) CreateUnBitArray(this, GetInfo(APE_INFO_FILE_VERSION)));
@ -70,7 +75,7 @@ int CAPEDecompress::InitializeDecompressor()
m_spNewPredictorX.Assign(new CPredictorDecompressNormal3930to3950(GetInfo(APE_INFO_COMPRESSION_LEVEL), GetInfo(APE_INFO_FILE_VERSION)));
m_spNewPredictorY.Assign(new CPredictorDecompressNormal3930to3950(GetInfo(APE_INFO_COMPRESSION_LEVEL), GetInfo(APE_INFO_FILE_VERSION)));
}
// seek to the beginning
return Seek(0);
}
@ -79,14 +84,14 @@ int CAPEDecompress::GetData(char * pBuffer, int nBlocks, int * pBlocksRetrieved)
{
int nRetVal = ERROR_SUCCESS;
if (pBlocksRetrieved) *pBlocksRetrieved = 0;
// make sure we're initialized
RETURN_ON_ERROR(InitializeDecompressor())
// cap
int nBlocksUntilFinish = m_nFinishBlock - m_nCurrentBlock;
const int nBlocksToRetrieve = min(nBlocks, nBlocksUntilFinish);
const int nBlocksToRetrieve = std::min(nBlocks, nBlocksUntilFinish);
// get the data
unsigned char * pOutputBuffer = (unsigned char *) pBuffer;
int nBlocksLeft = nBlocksToRetrieve; int nBlocksThisPass = 1;
@ -99,7 +104,7 @@ int CAPEDecompress::GetData(char * pBuffer, int nBlocks, int * pBlocksRetrieved)
// analyze how much to remove from the buffer
const int nFrameBufferBlocks = m_nFrameBufferFinishedBlocks;
nBlocksThisPass = min(nBlocksLeft, nFrameBufferBlocks);
nBlocksThisPass = std::min(nBlocksLeft, nFrameBufferBlocks);
// remove as much as possible
if (nBlocksThisPass > 0)
@ -127,7 +132,7 @@ int CAPEDecompress::Seek(int nBlockOffset)
// use the offset
nBlockOffset += m_nStartBlock;
// cap (to prevent seeking too far)
if (nBlockOffset >= m_nFinishBlock)
nBlockOffset = m_nFinishBlock - 1;
@ -138,7 +143,7 @@ int CAPEDecompress::Seek(int nBlockOffset)
int nBaseFrame = nBlockOffset / GetInfo(APE_INFO_BLOCKS_PER_FRAME);
int nBlocksToSkip = nBlockOffset % GetInfo(APE_INFO_BLOCKS_PER_FRAME);
int nBytesToSkip = nBlocksToSkip * m_nBlockAlign;
m_nCurrentBlock = nBaseFrame * GetInfo(APE_INFO_BLOCKS_PER_FRAME);
m_nCurrentFrameBufferBlock = nBaseFrame * GetInfo(APE_INFO_BLOCKS_PER_FRAME);
m_nCurrentFrame = nBaseFrame;
@ -149,7 +154,7 @@ int CAPEDecompress::Seek(int nBlockOffset)
// skip necessary blocks
CSmartPtr<char> spTempBuffer(new char [nBytesToSkip], TRUE);
if (spTempBuffer == NULL) return ERROR_INSUFFICIENT_MEMORY;
int nBlocksRetrieved = 0;
GetData(spTempBuffer, nBlocksToSkip, &nBlocksRetrieved);
if (nBlocksRetrieved != nBlocksToSkip)
@ -182,7 +187,7 @@ int CAPEDecompress::FillFrameBuffer()
int nFrameOffsetBlocks = m_nCurrentFrameBufferBlock % GetInfo(APE_INFO_BLOCKS_PER_FRAME);
int nFrameBlocksLeft = nFrameBlocks - nFrameOffsetBlocks;
int nBlocksThisPass = min(nFrameBlocksLeft, nBlocksLeft);
int nBlocksThisPass = std::min(nFrameBlocksLeft, nBlocksLeft);
// start the frame if we need to
if (nFrameOffsetBlocks == 0)
@ -193,7 +198,7 @@ int CAPEDecompress::FillFrameBuffer()
// decode data
DecodeBlocksToFrameBuffer(nBlocksThisPass);
// end the frame if we need to
if ((nFrameOffsetBlocks + nBlocksThisPass) >= nFrameBlocks)
{
@ -234,8 +239,8 @@ void CAPEDecompress::DecodeBlocksToFrameBuffer(int nBlocks)
{
if (m_wfeInput.nChannels == 2)
{
if ((m_nSpecialCodes & SPECIAL_FRAME_LEFT_SILENCE) &&
(m_nSpecialCodes & SPECIAL_FRAME_RIGHT_SILENCE))
if ((m_nSpecialCodes & SPECIAL_FRAME_LEFT_SILENCE) &&
(m_nSpecialCodes & SPECIAL_FRAME_RIGHT_SILENCE))
{
for (nBlocksProcessed = 0; nBlocksProcessed < nBlocks; nBlocksProcessed++)
{
@ -251,7 +256,7 @@ void CAPEDecompress::DecodeBlocksToFrameBuffer(int nBlocks)
m_Prepare.Unprepare(X, 0, &m_wfeInput, m_cbFrameBuffer.GetDirectWritePointer(), &m_nCRC);
m_cbFrameBuffer.UpdateAfterDirectWrite(m_nBlockAlign);
}
}
}
else
{
if (m_spAPEInfo->GetInfo(APE_INFO_FILE_VERSION) >= 3950)
@ -274,7 +279,7 @@ void CAPEDecompress::DecodeBlocksToFrameBuffer(int nBlocks)
{
int X = m_spNewPredictorX->DecompressValue(m_spUnBitArray->DecodeValueRange(m_BitArrayStateX));
int Y = m_spNewPredictorY->DecompressValue(m_spUnBitArray->DecodeValueRange(m_BitArrayStateY));
m_Prepare.Unprepare(X, Y, &m_wfeInput, m_cbFrameBuffer.GetDirectWritePointer(), &m_nCRC);
m_cbFrameBuffer.UpdateAfterDirectWrite(m_nBlockAlign);
}
@ -313,7 +318,7 @@ void CAPEDecompress::DecodeBlocksToFrameBuffer(int nBlocks)
void CAPEDecompress::StartFrame()
{
m_nCRC = 0xFFFFFFFF;
// get the frame header
m_nStoredCRC = m_spUnBitArray->DecodeValue(DECODE_VALUE_METHOD_UNSIGNED_INT);
m_bErrorDecodingCurrentFrame = FALSE;
@ -322,7 +327,7 @@ void CAPEDecompress::StartFrame()
m_nSpecialCodes = 0;
if (GET_USES_SPECIAL_FRAMES(m_spAPEInfo))
{
if (m_nStoredCRC & 0x80000000)
if (m_nStoredCRC & 0x80000000)
{
m_nSpecialCodes = m_spUnBitArray->DecodeValue(DECODE_VALUE_METHOD_UNSIGNED_INT);
}
@ -445,7 +450,7 @@ int CAPEDecompress::GetInfo(APE_DECOMPRESS_FIELDS Field, int nParam1, int nParam
{
char * pBuffer = (char *) nParam1;
int nMaxBytes = nParam2;
if (sizeof(WAVE_HEADER) > static_cast<uint32>(nMaxBytes))
{
nRetVal = -1;
@ -453,8 +458,8 @@ int CAPEDecompress::GetInfo(APE_DECOMPRESS_FIELDS Field, int nParam1, int nParam
else
{
WAVEFORMATEX wfeFormat; GetInfo(APE_INFO_WAVEFORMATEX, (int) &wfeFormat, 0);
WAVE_HEADER WAVHeader; FillWaveHeader(&WAVHeader,
(m_nFinishBlock - m_nStartBlock) * GetInfo(APE_INFO_BLOCK_ALIGN),
WAVE_HEADER WAVHeader; FillWaveHeader(&WAVHeader,
(m_nFinishBlock - m_nStartBlock) * GetInfo(APE_INFO_BLOCK_ALIGN),
&wfeFormat, 0);
memcpy(pBuffer, &WAVHeader, sizeof(WAVE_HEADER));
nRetVal = 0;

View File

@ -9,6 +9,9 @@
#include "MD5.h"
#include "CharacterHelper.h"
#include <algorithm>
#define UNMAC_DECODER_OUTPUT_NONE 0
#define UNMAC_DECODER_OUTPUT_WAV 1
#define UNMAC_DECODER_OUTPUT_APE 2
@ -58,7 +61,7 @@ int __stdcall CompressFileW(const str_utf16 * pInputFilename, const str_utf16 *
CSmartPtr<CMACProgressHelper> spMACProgressHelper;
CSmartPtr<unsigned char> spBuffer;
CSmartPtr<IAPECompress> spAPECompress;
try
{
// create the input source
@ -73,7 +76,7 @@ int __stdcall CompressFileW(const str_utf16 * pInputFilename, const str_utf16 *
// create the compressor
spAPECompress.Assign(CreateIAPECompress());
if (spAPECompress == NULL) throw ERROR_UNDEFINED;
// figure the audio bytes
int nAudioBytes = nAudioBlocks * WaveFormatEx.nBlockAlign;
@ -82,7 +85,7 @@ int __stdcall CompressFileW(const str_utf16 * pInputFilename, const str_utf16 *
THROW_ON_ERROR(spInputSource->GetHeaderData(spBuffer.GetPtr()))
THROW_ON_ERROR(spAPECompress->Start(pOutputFilename, &WaveFormatEx, nAudioBytes,
nCompressionLevel, spBuffer.GetPtr(), nHeaderBytes));
spBuffer.Delete();
// set-up the progress
@ -122,11 +125,11 @@ int __stdcall CompressFileW(const str_utf16 * pInputFilename, const str_utf16 *
{
nFunctionRetVal = ERROR_UNDEFINED;
}
// kill the compressor if we failed
if ((nFunctionRetVal != 0) && (spAPECompress != NULL))
spAPECompress->Kill();
// return
return nFunctionRetVal;
}
@ -146,7 +149,7 @@ int __stdcall VerifyFileW(const str_utf16 * pInputFilename, int * pPercentageDon
// return value
int nRetVal = ERROR_UNDEFINED;
// see if we can quick verify
if (bQuickVerifyIfPossible)
{
@ -154,7 +157,7 @@ int __stdcall VerifyFileW(const str_utf16 * pInputFilename, int * pPercentageDon
try
{
int nFunctionRetVal = ERROR_SUCCESS;
spAPEDecompress.Assign(CreateIAPEDecompress(pInputFilename, &nFunctionRetVal));
if (spAPEDecompress == NULL || nFunctionRetVal != ERROR_SUCCESS) throw(nFunctionRetVal);
@ -183,7 +186,7 @@ int __stdcall VerifyFileW(const str_utf16 * pInputFilename, int * pPercentageDon
if (spAPEDecompress == NULL || nFunctionRetVal != ERROR_SUCCESS) throw(nFunctionRetVal);
CMD5Helper MD5Helper;
CIO * pIO = GET_IO(spAPEDecompress);
APE_FILE_INFO * pInfo = (APE_FILE_INFO *) spAPEDecompress->GetInfo(APE_INTERNAL_INFO);
@ -198,13 +201,13 @@ int __stdcall VerifyFileW(const str_utf16 * pInputFilename, int * pPercentageDon
CSmartPtr<unsigned char> spHeadBuffer(new unsigned char [nHeadBytes], TRUE);
if ((pIO->Read(spHeadBuffer, nHeadBytes, &nBytesRead) != ERROR_SUCCESS) || (nHeadBytes != int(nBytesRead)))
throw(ERROR_IO_READ);
int nBytesLeft = pInfo->spAPEDescriptor->nHeaderDataBytes + pInfo->spAPEDescriptor->nAPEFrameDataBytes + pInfo->spAPEDescriptor->nTerminatingDataBytes;
CSmartPtr<unsigned char> spBuffer(new unsigned char [16384], TRUE);
nBytesRead = 1;
while ((nBytesLeft > 0) && (nBytesRead > 0))
{
int nBytesToRead = min(16384, nBytesLeft);
int nBytesToRead = std::min(16384, nBytesLeft);
if (pIO->Read(spBuffer, nBytesToRead, &nBytesRead) != ERROR_SUCCESS)
throw(ERROR_IO_READ);
@ -232,7 +235,7 @@ int __stdcall VerifyFileW(const str_utf16 * pInputFilename, int * pPercentageDon
{
nFunctionRetVal = ERROR_UNDEFINED;
}
// return value
nRetVal = nFunctionRetVal;
}
@ -259,7 +262,7 @@ int __stdcall DecompressFileW(const str_utf16 * pInputFilename, const str_utf16
/*****************************************************************************************
Convert file
*****************************************************************************************/
int __stdcall ConvertFileW(const str_utf16 * pInputFilename, const str_utf16 * pOutputFilename, int nCompressionLevel, int * pPercentageDone, APE_PROGRESS_CALLBACK ProgressCallback, int * pKillFlag)
int __stdcall ConvertFileW(const str_utf16 * pInputFilename, const str_utf16 * pOutputFilename, int nCompressionLevel, int * pPercentageDone, APE_PROGRESS_CALLBACK ProgressCallback, int * pKillFlag)
{
return DecompressCore(pInputFilename, pOutputFilename, UNMAC_DECODER_OUTPUT_APE, nCompressionLevel, pPercentageDone, ProgressCallback, pKillFlag);
}
@ -267,10 +270,10 @@ int __stdcall ConvertFileW(const str_utf16 * pInputFilename, const str_utf16 * p
/*****************************************************************************************
Decompress a file using the specified output method
*****************************************************************************************/
int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFilename, int nOutputMode, int nCompressionLevel, int * pPercentageDone, APE_PROGRESS_CALLBACK ProgressCallback, int * pKillFlag)
int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFilename, int nOutputMode, int nCompressionLevel, int * pPercentageDone, APE_PROGRESS_CALLBACK ProgressCallback, int * pKillFlag)
{
// error check the function parameters
if (pInputFilename == NULL)
if (pInputFilename == NULL)
{
return ERROR_INVALID_FUNCTION_PARAMETER;
}
@ -305,7 +308,7 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
{
// create the file
spioOutput.Assign(new IO_CLASS_NAME); THROW_ON_ERROR(spioOutput->Create(pOutputFilename))
// output the header
THROW_ON_ERROR(WriteSafe(spioOutput, spTempBuffer, spAPEDecompress->GetInfo(APE_INFO_WAV_HEADER_BYTES)));
}
@ -326,7 +329,7 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
if (spTempBuffer == NULL) throw(ERROR_INSUFFICIENT_MEMORY);
int nBlocksLeft = spAPEDecompress->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS);
// create the progress helper
spMACProgressHelper.Assign(new CMACProgressHelper(nBlocksLeft / BLOCKS_PER_DECODE, pPercentageDone, ProgressCallback, pKillFlag));
@ -336,7 +339,7 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
// decode data
int nBlocksDecoded = -1;
int nRetVal = spAPEDecompress->GetData((char *) spTempBuffer.GetPtr(), BLOCKS_PER_DECODE, &nBlocksDecoded);
if (nRetVal != ERROR_SUCCESS)
if (nRetVal != ERROR_SUCCESS)
throw(ERROR_INVALID_CHECKSUM);
// handle the output
@ -345,7 +348,7 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
unsigned int nBytesToWrite = (nBlocksDecoded * spAPEDecompress->GetInfo(APE_INFO_BLOCK_ALIGN));
unsigned int nBytesWritten = 0;
int nRetVal = spioOutput->Write(spTempBuffer, nBytesToWrite, &nBytesWritten);
if ((nRetVal != 0) || (nBytesToWrite != nBytesWritten))
if ((nRetVal != 0) || (nBytesToWrite != nBytesWritten))
throw(ERROR_IO_WRITE);
}
else if (nOutputMode == UNMAC_DECODER_OUTPUT_APE)
@ -355,7 +358,7 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
// update amount remaining
nBlocksLeft -= nBlocksDecoded;
// update progress and kill flag
spMACProgressHelper->UpdateProgress();
if (spMACProgressHelper->ProcessKillFlag(TRUE) != 0)
@ -366,16 +369,16 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
if (nOutputMode == UNMAC_DECODER_OUTPUT_WAV)
{
// write any terminating WAV data
if (spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_BYTES) > 0)
if (spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_BYTES) > 0)
{
spTempBuffer.Assign(new unsigned char[spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_BYTES)], TRUE);
if (spTempBuffer == NULL) throw(ERROR_INSUFFICIENT_MEMORY);
THROW_ON_ERROR(spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_DATA, (int) spTempBuffer.GetPtr(), spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_BYTES)))
unsigned int nBytesToWrite = spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_BYTES);
unsigned int nBytesWritten = 0;
int nRetVal = spioOutput->Write(spTempBuffer, nBytesToWrite, &nBytesWritten);
if ((nRetVal != 0) || (nBytesToWrite != nBytesWritten))
if ((nRetVal != 0) || (nBytesToWrite != nBytesWritten))
throw(ERROR_IO_WRITE);
}
}
@ -387,11 +390,11 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
int nTerminatingBytes = nTagBytes;
nTerminatingBytes += spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_BYTES);
if (nTerminatingBytes > 0)
if (nTerminatingBytes > 0)
{
spTempBuffer.Assign(new unsigned char[nTerminatingBytes], TRUE);
if (spTempBuffer == NULL) throw(ERROR_INSUFFICIENT_MEMORY);
THROW_ON_ERROR(spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_DATA, (int) spTempBuffer.GetPtr(), nTerminatingBytes))
if (bHasTag)
@ -403,7 +406,7 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
THROW_ON_ERROR(spAPECompress->Finish(spTempBuffer, nTerminatingBytes, spAPEDecompress->GetInfo(APE_INFO_WAV_TERMINATING_BYTES)));
}
else
else
{
THROW_ON_ERROR(spAPECompress->Finish(NULL, 0, 0));
}
@ -420,7 +423,7 @@ int DecompressCore(const str_utf16 * pInputFilename, const str_utf16 * pOutputFi
{
nFunctionRetVal = ERROR_UNDEFINED;
}
// return
return nFunctionRetVal;
}

View File

@ -1,6 +1,9 @@
#include "All.h"
#include "ID3Genres.h"
#include "APETag.h"
#include <algorithm>
#include "ID3Genres.h"
#include "CharacterHelper.h"
#include "IO.h"
#include IO_HEADER_FILE
@ -14,9 +17,9 @@ CAPETagField::CAPETagField(const str_utf16 * pFieldName, const void * pFieldValu
// field name
m_spFieldNameUTF16.Assign(new str_utf16 [wcslen(pFieldName) + 1], TRUE);
memcpy(m_spFieldNameUTF16, pFieldName, (wcslen(pFieldName) + 1) * sizeof(str_utf16));
// data (we'll always allocate two extra bytes and memset to 0 so we're safely NULL terminated)
m_nFieldValueBytes = max(nFieldBytes, 0);
m_nFieldValueBytes = std::max(nFieldBytes, 0);
m_spFieldValue.Assign(new char [m_nFieldValueBytes + 2], TRUE);
memset(m_spFieldValue, 0, m_nFieldValueBytes + 2);
if (m_nFieldValueBytes > 0)
@ -29,10 +32,10 @@ CAPETagField::CAPETagField(const str_utf16 * pFieldName, const void * pFieldValu
CAPETagField::~CAPETagField()
{
}
int CAPETagField::GetFieldSize()
{
CSmartPtr<char> spFieldNameANSI(GetANSIFromUTF16(m_spFieldNameUTF16), TRUE);
CSmartPtr<char> spFieldNameANSI(GetANSIFromUTF16(m_spFieldNameUTF16), TRUE);
return (strlen(spFieldNameANSI) + 1) + m_nFieldValueBytes + 4 + 4;
}
@ -62,8 +65,8 @@ int CAPETagField::SaveField(char * pBuffer)
pBuffer += 4;
*((int *) pBuffer) = m_nFieldFlags;
pBuffer += 4;
CSmartPtr<char> spFieldNameANSI((char *) GetANSIFromUTF16(m_spFieldNameUTF16), TRUE);
CSmartPtr<char> spFieldNameANSI((char *) GetANSIFromUTF16(m_spFieldNameUTF16), TRUE);
strcpy(pBuffer, spFieldNameANSI);
pBuffer += strlen(spFieldNameANSI) + 1;
@ -86,7 +89,7 @@ CAPETag::CAPETag(const str_utf16 * pFilename, BOOL bAnalyze)
m_nFields = 0;
m_nTagBytes = 0;
m_bIgnoreReadOnly = FALSE;
if (bAnalyze)
{
Analyze();
@ -99,7 +102,7 @@ CAPETag::CAPETag(CIO * pIO, BOOL bAnalyze)
m_bAnalyzed = FALSE;
m_nFields = 0;
m_nTagBytes = 0;
if (bAnalyze)
{
Analyze();
@ -134,7 +137,7 @@ int CAPETag::Save(BOOL bUseOldID3)
{
if (Remove(FALSE) != ERROR_SUCCESS)
return -1;
if (m_nFields == 0) { return ERROR_SUCCESS; }
int nRetVal = -1;
@ -184,12 +187,12 @@ int CAPETag::Save(BOOL bUseOldID3)
int CAPETag::WriteBufferToEndOfIO(void * pBuffer, int nBytes)
{
int nOriginalPosition = m_spIO->GetPosition();
unsigned int nBytesWritten = 0;
m_spIO->Seek(0, FILE_END);
int nRetVal = m_spIO->Write(pBuffer, nBytes, &nBytesWritten);
m_spIO->Seek(nOriginalPosition, FILE_BEGIN);
return nRetVal;
@ -206,7 +209,7 @@ int CAPETag::Analyze()
// store the original location
int nOriginalPosition = m_spIO->GetPosition();
// check for a tag
unsigned int nBytesRead;
int nRetVal;
@ -215,16 +218,16 @@ int CAPETag::Analyze()
m_nAPETagVersion = -1;
m_spIO->Seek(-ID3_TAG_BYTES, FILE_END);
nRetVal = m_spIO->Read((unsigned char *) &ID3Tag, sizeof(ID3_TAG), &nBytesRead);
if ((nBytesRead == sizeof(ID3_TAG)) && (nRetVal == 0))
{
if (ID3Tag.Header[0] == 'T' && ID3Tag.Header[1] == 'A' && ID3Tag.Header[2] == 'G')
if (ID3Tag.Header[0] == 'T' && ID3Tag.Header[1] == 'A' && ID3Tag.Header[2] == 'G')
{
m_bHasID3Tag = TRUE;
m_nTagBytes += ID3_TAG_BYTES;
}
}
// set the fields
if (m_bHasID3Tag)
{
@ -233,13 +236,13 @@ int CAPETag::Analyze()
SetFieldID3String(APE_TAG_FIELD_TITLE, ID3Tag.Title, 30);
SetFieldID3String(APE_TAG_FIELD_COMMENT, ID3Tag.Comment, 28);
SetFieldID3String(APE_TAG_FIELD_YEAR, ID3Tag.Year, 4);
char cTemp[16]; sprintf(cTemp, "%d", ID3Tag.Track);
SetFieldString(APE_TAG_FIELD_TRACK, cTemp, FALSE);
if ((ID3Tag.Genre == GENRE_UNDEFINED) || (ID3Tag.Genre >= GENRE_COUNT))
if ((ID3Tag.Genre == GENRE_UNDEFINED) || (ID3Tag.Genre >= GENRE_COUNT))
SetFieldString(APE_TAG_FIELD_GENRE, APE_TAG_GENRE_UNDEFINED);
else
else
SetFieldString(APE_TAG_FIELD_GENRE, g_ID3Genre[ID3Tag.Genre]);
}
@ -258,7 +261,7 @@ int CAPETag::Analyze()
int nRawFieldBytes = APETagFooter.GetFieldBytes();
m_nTagBytes += APETagFooter.GetTotalTagBytes();
CSmartPtr<char> spRawTag(new char [nRawFieldBytes], TRUE);
m_spIO->Seek(-(APETagFooter.GetTotalTagBytes() - APETagFooter.GetFieldsOffset()), FILE_END);
nRetVal = m_spIO->Read((unsigned char *) spRawTag.GetPtr(), nRawFieldBytes, &nBytesRead);
@ -270,7 +273,7 @@ int CAPETag::Analyze()
for (int z = 0; z < APETagFooter.GetNumberFields(); z++)
{
int nMaximumFieldBytes = nRawFieldBytes - nLocation;
int nBytes = 0;
if (LoadField(&spRawTag[nLocation], nMaximumFieldBytes, &nBytes) != ERROR_SUCCESS)
{
@ -287,7 +290,7 @@ int CAPETag::Analyze()
// restore the file pointer
m_spIO->Seek(nOriginalPosition, FILE_BEGIN);
return ERROR_SUCCESS;
}
@ -297,7 +300,7 @@ int CAPETag::ClearFields()
{
SAFE_DELETE(m_aryFields[z])
}
m_nFields = 0;
return ERROR_SUCCESS;
@ -347,7 +350,7 @@ int CAPETag::GetFieldString(const str_utf16 * pFieldName, str_ansi * pBuffer, in
*pBufferCharacters = strlen(spANSI);
}
}
delete [] pUTF16;
return nRetVal;
@ -413,7 +416,7 @@ int CAPETag::GetFieldString(const str_utf16 * pFieldName, str_utf16 * pBuffer, i
int CAPETag::GetFieldBinary(const str_utf16 * pFieldName, void * pBuffer, int * pBufferBytes)
{
if (m_bAnalyzed == FALSE) { Analyze(); }
int nRetVal = ERROR_UNDEFINED;
if (*pBufferBytes > 0)
@ -447,7 +450,7 @@ int CAPETag::GetFieldBinary(const str_utf16 * pFieldName, void * pBuffer, int *
int CAPETag::CreateID3Tag(ID3_TAG * pID3Tag)
{
// error check
// error check
if (pID3Tag == NULL) { return -1; }
if (m_bAnalyzed == FALSE) { Analyze(); }
if (m_nFields == 0) { return -1; }
@ -457,7 +460,7 @@ int CAPETag::CreateID3Tag(ID3_TAG * pID3Tag)
// header
pID3Tag->Header[0] = 'T'; pID3Tag->Header[1] = 'A'; pID3Tag->Header[2] = 'G';
// standard fields
GetFieldID3String(APE_TAG_FIELD_ARTIST, pID3Tag->Artist, 30);
GetFieldID3String(APE_TAG_FIELD_ALBUM, pID3Tag->Album, 30);
@ -469,11 +472,11 @@ int CAPETag::CreateID3Tag(ID3_TAG * pID3Tag)
str_utf16 cBuffer[256] = { 0 }; int nBufferCharacters = 255;
GetFieldString(APE_TAG_FIELD_TRACK, cBuffer, &nBufferCharacters);
pID3Tag->Track = (unsigned char) _wtoi(cBuffer);
// genre
cBuffer[0] = 0; nBufferCharacters = 255;
GetFieldString(APE_TAG_FIELD_GENRE, cBuffer, &nBufferCharacters);
// convert the genre string to an index
pID3Tag->Genre = 255;
int nGenreIndex = 0;
@ -485,7 +488,7 @@ int CAPETag::CreateID3Tag(ID3_TAG * pID3Tag)
pID3Tag->Genre = nGenreIndex;
bFound = TRUE;
}
nGenreIndex++;
}
@ -503,7 +506,7 @@ int CAPETag::LoadField(const char * pBuffer, int nMaximumBytes, int * pBytes)
nLocation += 4;
int nFieldFlags = *((int *) &pBuffer[nLocation]);
nLocation += 4;
// safety check (so we can't get buffer overflow attacked)
int nMaximumRead = nMaximumBytes - 8 - nFieldValueSize;
BOOL bSafe = TRUE;
@ -585,7 +588,7 @@ int CAPETag::SetFieldBinary(const str_utf16 * pFieldName, const void * pFieldVal
// fail if we're read-only (and not ignoring the read-only flag)
if ((m_bIgnoreReadOnly == FALSE) && (m_aryFields[nFieldIndex]->GetIsReadOnly()))
return -1;
// erase the existing field
SAFE_DELETE(m_aryFields[nFieldIndex])
@ -602,7 +605,7 @@ int CAPETag::SetFieldBinary(const str_utf16 * pFieldName, const void * pFieldVal
nFieldIndex = m_nFields;
m_nFields++;
}
// create the field and add it to the field array
m_aryFields[nFieldIndex] = new CAPETagField(pFieldName, pFieldValue, nFieldBytes, nFieldFlags);
@ -685,7 +688,7 @@ int CAPETag::Remove(BOOL bUpdate)
}
}
m_spIO->Seek(nOriginalPosition, FILE_BEGIN);
if (bUpdate && bFailedToRemove == FALSE)
@ -701,17 +704,17 @@ int CAPETag::SetFieldID3String(const str_utf16 * pFieldName, const char * pField
// allocate a buffer and terminate it
CSmartPtr<str_ansi> spBuffer(new str_ansi [nBytes + 1], TRUE);
spBuffer[nBytes] = 0;
// make a capped copy of the string
memcpy(spBuffer.GetPtr(), pFieldValue, nBytes);
// remove trailing white-space
char * pEnd = &spBuffer[nBytes];
while (((*pEnd == ' ') || (*pEnd == 0)) && pEnd >= &spBuffer[0]) { *pEnd-- = 0; }
// set the field
SetFieldString(pFieldName, spBuffer, FALSE);
return ERROR_SUCCESS;
}

View File

@ -1,7 +1,7 @@
#ifndef APE_CIRCLEBUFFER_H
#define APE_CIRCLEBUFFER_H
class CCircleBuffer
class CCircleBuffer
{
public:
@ -17,14 +17,14 @@ public:
int MaxGet();
// direct writing
inline unsigned char * CCircleBuffer::GetDirectWritePointer()
inline unsigned char * GetDirectWritePointer()
{
// return a pointer to the tail -- note that it will always be safe to write
// at least m_nMaxDirectWriteBytes since we use an end cap region
return &m_pBuffer[m_nTail];
}
inline void CCircleBuffer::UpdateAfterDirectWrite(int nBytes)
inline void UpdateAfterDirectWrite(int nBytes)
{
// update the tail
m_nTail += nBytes;

View File

@ -86,6 +86,6 @@ public:
#ifdef _MSC_VER
#pragma warning(pop)
#endif _MSC_VER
#endif // _MSC_VER
#endif // #ifndef APE_SMARTPTR_H

View File

@ -3,6 +3,9 @@
#include "UnBitArray.h"
#include "BitArray.h"
#include <algorithm>
const uint32 POWERS_OF_TWO_MINUS_ONE_REVERSED[33] = {4294967295,2147483647,1073741823,536870911,268435455,134217727,67108863,33554431,16777215,8388607,4194303,2097151,1048575,524287,262143,131071,65535,32767,16383,8191,4095,2047,1023,511,255,127,63,31,15,7,3,1,0};
const uint32 K_SUM_MIN_BOUNDARY[32] = {0,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,0,0,0,0};
@ -27,7 +30,7 @@ const uint32 RANGE_WIDTH_2[64] = {19578,16582,12257,7906,4576,2366,1170,536,261,
/***********************************************************************************
Construction
***********************************************************************************/
CUnBitArray::CUnBitArray(CIO * pIO, int nVersion)
CUnBitArray::CUnBitArray(CIO * pIO, int nVersion)
{
CreateHelper(pIO, 16384, nVersion);
m_nFlushCounter = 0;
@ -46,11 +49,11 @@ unsigned int CUnBitArray::DecodeValue(DECODE_VALUE_METHOD DecodeMethod, int nPar
case DECODE_VALUE_METHOD_UNSIGNED_INT:
return DecodeValueXBits(32);
}
return 0;
}
void CUnBitArray::GenerateArray(int * pOutputArray, int nElements, int nBytesRequired)
void CUnBitArray::GenerateArray(int * pOutputArray, int nElements, int nBytesRequired)
{
GenerateArrayRange(pOutputArray, nElements);
}
@ -60,12 +63,12 @@ __inline unsigned char CUnBitArray::GetC()
unsigned char nValue = (unsigned char) (m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31)));
m_nCurrentBitIndex += 8;
return nValue;
}
}
__inline int CUnBitArray::RangeDecodeFast(int nShift)
{
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
{
{
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
m_nCurrentBitIndex += 8;
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
@ -80,7 +83,7 @@ __inline int CUnBitArray::RangeDecodeFast(int nShift)
__inline int CUnBitArray::RangeDecodeFastWithUpdate(int nShift)
{
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
{
{
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
m_nCurrentBitIndex += 8;
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
@ -108,21 +111,21 @@ int CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
if (m_nVersion >= 3990)
{
// figure the pivot value
int nPivotValue = max(BitArrayState.nKSum / 32, 1);
int nPivotValue = std::max(BitArrayState.nKSum / 32, 1UL);
// get the overflow
int nOverflow = 0;
{
// decode
int nRangeTotal = RangeDecodeFast(RANGE_OVERFLOW_SHIFT);
// lookup the symbol (must be a faster way than this)
while (nRangeTotal >= RANGE_TOTAL_2[nOverflow + 1]) { nOverflow++; }
// update
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * RANGE_TOTAL_2[nOverflow];
m_RangeCoderInfo.range = m_RangeCoderInfo.range * RANGE_WIDTH_2[nOverflow];
// get the working k
if (nOverflow == (MODEL_ELEMENTS - 1))
{
@ -146,7 +149,7 @@ int CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
int nPivotValueB = nSplitFactor;
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
{
{
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
m_nCurrentBitIndex += 8;
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
@ -157,7 +160,7 @@ int CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nBaseA;
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
{
{
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
m_nCurrentBitIndex += 8;
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
@ -172,7 +175,7 @@ int CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
else
{
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
{
{
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
m_nCurrentBitIndex += 8;
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
@ -195,15 +198,15 @@ int CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
{
// decode
int nRangeTotal = RangeDecodeFast(RANGE_OVERFLOW_SHIFT);
// lookup the symbol (must be a faster way than this)
int nOverflow = 0;
while (nRangeTotal >= RANGE_TOTAL_1[nOverflow + 1]) { nOverflow++; }
// update
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * RANGE_TOTAL_1[nOverflow];
m_RangeCoderInfo.range = m_RangeCoderInfo.range * RANGE_WIDTH_1[nOverflow];
// get the working k
int nTempK;
if (nOverflow == (MODEL_ELEMENTS - 1))
@ -215,30 +218,30 @@ int CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
{
nTempK = (BitArrayState.k < 1) ? 0 : BitArrayState.k - 1;
}
// figure the extra bits on the left and the left value
if (nTempK <= 16 || m_nVersion < 3910)
{
nValue = RangeDecodeFastWithUpdate(nTempK);
}
}
else
{
{
int nX1 = RangeDecodeFastWithUpdate(16);
int nX2 = RangeDecodeFastWithUpdate(nTempK - 16);
nValue = nX1 | (nX2 << 16);
}
// build the value and output it
nValue += (nOverflow << nTempK);
}
// update nKSum
BitArrayState.nKSum += ((nValue + 1) / 2) - ((BitArrayState.nKSum + 16) >> 5);
// update k
if (BitArrayState.nKSum < K_SUM_MIN_BOUNDARY[BitArrayState.k])
if (BitArrayState.nKSum < K_SUM_MIN_BOUNDARY[BitArrayState.k])
BitArrayState.k--;
else if (BitArrayState.nKSum >= K_SUM_MIN_BOUNDARY[BitArrayState.k + 1])
else if (BitArrayState.nKSum >= K_SUM_MIN_BOUNDARY[BitArrayState.k + 1])
BitArrayState.k++;
// output the value (converted to signed)
@ -266,11 +269,11 @@ void CUnBitArray::Finalize()
{
// normalize
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
{
{
m_nCurrentBitIndex += 8;
m_RangeCoderInfo.range <<= 8;
}
// used to back-pedal the last two bytes out
// this should never have been a problem because we've outputted and normalized beforehand
// but stopped doing it as of 3.96 in case it accounted for rare decompression failures
@ -283,11 +286,11 @@ void CUnBitArray::GenerateArrayRange(int * pOutputArray, int nElements)
UNBIT_ARRAY_STATE BitArrayState;
FlushState(BitArrayState);
FlushBitArray();
for (int z = 0; z < nElements; z++)
{
pOutputArray[z] = DecodeValueRange(BitArrayState);
}
Finalize();
Finalize();
}