• Revista PROGRAMAR: Já está disponível a edição #53 da revista programar. Faz já o download aqui!

arthur.m

Necessito de ajuda a compilar código.

1 mensagem neste tópico

olá. estou acostumado com c...e necessito compilar um código que tenho em c++(da net) para experimentar um codec audio para voz(ima_adpcm).

estou a chamar o compilador assim:

g++ IMA_ADPCM.cpp -o IMA_ADPCM

e o erro que me dá é:

common.h:209: error: 'operator new' takes type 'size_t' ('long unsigned int') as first parameter

já entendi que é no ficheiro common...  e tentei mudar o argumento do tipo size_t para long unsigned int, mas não dá.

alguém me ajuda a compilar isto sem erros?

pelo que entendi este common é para dar uma volta ao gcc...

obrigado

common.h

/*
This program is distributed under the terms of the 'MIT license'. The text
of this licence follows...

Copyright (c) 2004-2005 J.D.Medhurst (a.k.a. Tixy)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
@file

@brief Type definitions and helper macros which aren't part of Standard C++

@version 2007-01-17
- Fixed definition of <CODE>offsetof</CODE> to work on GGC 4.
- Added global placement new operator for constructing an object at a specified address.

*/

#ifndef __COMMON_H__
#define __COMMON_H__


#if _DEBUG
#undef DEBUG
#define DEBUG	/**< Defined when compiling code for debugging */
#endif

#if defined(_MSC_VER)
// Compiling for Microsoft Visual C++...
#define BREAKPOINT	{ _asm int 3 }			/**< Invoke debugger */
#define IMPORT		__declspec(dllexport)	/**< Mark a function which is to be imported from a DLL */
#define EXPORT		__declspec(dllexport)	/**< Mark a function to be exported from a DLL */
#define ASSERT(c)	{if(!(c)) BREAKPOINT;}	/**< Assert that expression 'c' is true */
typedef __int64 longlong;
typedef unsigned __int64 ulonglong;

// disable annoying warnings from MSVC...
#pragma warning( disable : 4244 )	/* conversion from x to y, possible loss of data */
#pragma warning( disable : 4514 )	/* unreferenced inline function has been removed */
#pragma warning( disable : 4146 )	/* unary minus operator applied to unsigned type, result still unsigned */
#pragma warning( disable : 4710 )	/* function x not inlined */
#pragma warning( disable : 4355 )   /* 'this' : used in base member initializer list */
#pragma warning( disable : 4512 )   /* assignment operator could not be generated */
#pragma warning( disable : 4800 )	/* forcing value to bool 'true' or 'false' (performance warning) */

#elif defined(__EPOC32__) || defined(__WINS__)
// Compiling for Symbian OS...

#define COMPILE_FOR_SYMBIAN
#include <e32std.h>

#if !defined(__BREAKPOINT)

#if defined(__WINS__)

#if defined(__WINSCW__)
#define BREAKPOINT { _asm byte 0xcc }		/**< Invoke debugger */
#else
#define BREAKPOINT { _asm int 3 }			/**< Invoke debugger */
#endif

#else
#define BREAKPOINT							/**< Invoke debugger */
#endif

#else
#define BREAKPOINT	{__BREAKPOINT()}		/**< Invoke debugger */
#endif

#define IMPORT		IMPORT_C				/**< Mark a function which is to be imported from a DLL */
#define EXPORT		EXPORT_C				/**< Mark a function to be exported from a DLL */

#undef ASSERT
#define ASSERT(c)	{if(!(c)) BREAKPOINT;}	/**< Assert that expression 'c' is true */

#if !defined(DEBUG) && defined(_DEBUG)
#define DEBUG								/**< Defined when compiling code for debugging */
#endif

typedef TInt64 longlong;
typedef TUint64 ulonglong;


#else
// Compiling for unknown system...
#define BREAKPOINT							/**< Invoke debugger */
#define IMPORT								/**< Mark a function which is to be imported from a DLL */
#define EXPORT								/**< Mark a function to be exported from a DLL */
#define ASSERT(c) (void)(c)					/**< Assert that expression 'c' is true */
typedef long long longlong;
typedef unsigned long long ulonglong;

#endif


#ifdef DEBUG
#define ASSERT_DEBUG(c) ASSERT(c)	/**< Assert that expression 'c' is true (when compiled for debugging)*/
#else
#define ASSERT_DEBUG(c) 			/**< Assert that expression 'c' is true (when compiled for debugging)*/
#endif


#ifndef ASSERT_COMPILE
/** Assert, at compile time, that expression 'c' is true. */
#define ASSERT_COMPILE(c) void assert_compile(int assert_compile[(c)?1:-1])
#endif


#ifndef NULL
#define NULL 0		/**< Used to represent a null pointer type */
#endif


/**
@defgroup integers Common - Basic Integer Types.

These definitions will need to be modified on systems where 'char', 'short' and 'int'
have sizes different from 8, 16 and 32 bits.

Note, 'int' is assumed to be in 2s complement format and at least 32 bits in size.
@{
*/
typedef unsigned char		uint8_t;		/**< An 8 bit unsigned integer */
typedef unsigned short		uint16_t;		/**< An 16 bit unsigned integer */
typedef unsigned int		uint32_t;		/**< An 32 bit unsigned integer */
typedef ulonglong			uint64_t;		/**< An 64 bit unsigned integer */
typedef signed char			int8_t;			/**< An 8 bit signed integer (2s complement) */
typedef signed short		int16_t;		/**< An 16 bit signed integer (2s complement) */
typedef signed int			int32_t;		/**< An 32 bit signed integer (2s complement) */
typedef longlong			int64_t;		/**< An 64 bit signed integer (2s complement) */
typedef int					intptr_t;		/**< An signed integer of the same size as a pointer type */
typedef unsigned int		uintptr_t;		/**< An unsigned integer of the same size as a pointer type */
typedef int64_t				intmax_t;		/**< Largest signed integer type */
typedef uint64_t			uintmax_t;		/**< Largest unsigned integer type */
typedef uintptr_t			size_t;			/**< A size of an object or memory region */
typedef intptr_t			ptrdiff_t;		/**< A signed integer which can hold the different between two pointer */

/** @} */ // End of group

ASSERT_COMPILE(sizeof(uintptr_t)==sizeof(void*));
ASSERT_COMPILE(sizeof(intptr_t)==sizeof(void*));


/**
Number of bits in an int.
*/
#define INT_BITS (sizeof(int)*8)


/**
Return log2(x) rounded up to the nearest integer.
@param x An unsigned integer which must be less than 2^32.
*/
#define LOG2(x)	((unsigned)(\
(unsigned)(x)<=(unsigned)(1<< 0) ?  0 : (unsigned)(x)<=(unsigned)(1<< 1) ?  1 : (unsigned)(x)<=(unsigned)(1<< 2) ?  2 : (unsigned)(x)<=(unsigned)(1<< 3) ?  3 : \
(unsigned)(x)<=(unsigned)(1<< 4) ?  4 : (unsigned)(x)<=(unsigned)(1<< 5) ?  5 : (unsigned)(x)<=(unsigned)(1<< 6) ?  6 : (unsigned)(x)<=(unsigned)(1<< 7) ?  7 : \
(unsigned)(x)<=(unsigned)(1<< 8) ?  8 : (unsigned)(x)<=(unsigned)(1<< 9) ?  9 : (unsigned)(x)<=(unsigned)(1<<10) ? 10 : (unsigned)(x)<=(unsigned)(1<<11) ? 11 : \
(unsigned)(x)<=(unsigned)(1<<12) ? 12 : (unsigned)(x)<=(unsigned)(1<<13) ? 13 : (unsigned)(x)<=(unsigned)(1<<14) ? 14 : (unsigned)(x)<=(unsigned)(1<<15) ? 15 : \
(unsigned)(x)<=(unsigned)(1<<16) ? 16 : (unsigned)(x)<=(unsigned)(1<<17) ? 17 : (unsigned)(x)<=(unsigned)(1<<18) ? 18 : (unsigned)(x)<=(unsigned)(1<<19) ? 19 : \
(unsigned)(x)<=(unsigned)(1<<20) ? 20 : (unsigned)(x)<=(unsigned)(1<<21) ? 21 : (unsigned)(x)<=(unsigned)(1<<22) ? 22 : (unsigned)(x)<=(unsigned)(1<<23) ? 23 : \
(unsigned)(x)<=(unsigned)(1<<24) ? 24 : (unsigned)(x)<=(unsigned)(1<<25) ? 25 : (unsigned)(x)<=(unsigned)(1<<26) ? 26 : (unsigned)(x)<=(unsigned)(1<<27) ? 27 : \
(unsigned)(x)<=(unsigned)(1<<28) ? 28 : (unsigned)(x)<=(unsigned)(1<<29) ? 29 : (unsigned)(x)<=(unsigned)(1<<30) ? 30 : (unsigned)(x)<=(unsigned)(1<<31) ? 31 : \
32))


#if __GNUC__<4
/**
Calculate address offset of member within a type.
*/
#define offsetof(type,member)	((size_t)(&((type*)256)->member)-256)
#else
#define offsetof(type,member)	__builtin_offsetof(type,member)
#endif


#if defined(__GNUC__) && defined(_ARM)

/**
Used to stop GCC "warning: control reaches end of non-void function" in __naked__ functions.
*/
#define dummy_return(type) register type _r0 asm("r0"); asm("" : "=r"(_r0)); return _r0

#endif


#ifndef COMPILE_FOR_SYMBIAN

/**
Global placement new operator for constructing an object at a specified address.
*/
inline void* operator new(size_t, void* ptr) throw()
{ return ptr; }

/**
Global placement delete operator.
*/
inline void operator delete(void*, void*) throw()
{ }

#endif // !COMPILE_FOR_SYMBIAN


#endif

ima_adpcm.h

/*
This program is distributed under the terms of the 'MIT license'. The text
of this licence follows...

Copyright (c) 2005 J.D.Medhurst (a.k.a. Tixy)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
@file

@brief Implementation of the IMA ADPCM audio coding algorithm
*/

#ifndef __IMA_ADPCM_H__
#define __IMA_ADPCM_H__

/**
@defgroup ima_adpcm Audio Codec - IMA ADPCM
@{
*/

/**
@brief A class which implements the IMA ADPCM audio coding algorithm.

Typically, IMA ADPCM data is stored as blocks of data with the #PredictedValue
and #StepIndex values held in a header to each block. When decoding, these values
should be writen to this class to initialise the decoding of a block. When encoding, 
these values should be writen out to a block's header prior to encoding the samples
in the block.

Note, when IMA ADPCM data is stored in Microsoft WAV files, the #PredictedValue
found in the block's header is used as the first sample for that block. The first ADPCM
value in the block's data then represents the second sample.

@version 2006-05-20
- Changed code to use standard typedefs, e.g. replaced uint8 with uint8_t, and made use of size_t.
*/
class IMA_ADPCM
{
public:
/**
Initialise the #PredictedValue and #StepIndex members to the
optimum values for encoding an audio stream whoes first two PCM samples have the
values given. Use of this method at the start of audio stream encoding gives
improved accuracy over a naive initialisation which sets #PredictedValue
and #StepIndex to predetermined constant values.

@param sample1 The first PCM sample in the audio stream.
@param sample2 The second PCM sample in the audio stream.
*/
IMPORT void EncodeInit(int16_t sample1,int16_t sample2);

/**
Encode a single linear PCM sample as an ADPCM value.

@param pcm16 The PCM value to encode.

@return The 4 least significan bits represent the encoded ADPCM value.
		Other bits are zero.

@post #PredictedValue and #StepIndex are updated ready
	  for encoding the next sample.
*/
IMPORT unsigned Encode(int16_t pcm16);

/**
Decode a single ADPCM value into a 16bit linear PCM value.

@param adpcm The 4 least significan bits represent ADPCM value to encode. 
			 Other bits are ignored.

@return The decoded 16 bit PCM value sign extended to an int.

@post #PredictedValue and #StepIndex are updated ready
	  for decoding the next sample.
*/
IMPORT int Decode(unsigned adpcm);

/**
Encode a buffer of 16 bit uniform PCM values into ADPCM values.

Two ADPCM values are stored in each byte. The value stored in bits 0-3
corresponds to the sample preceding that stored in bits 4-7.
Note, if the last encoded ADPCM value is stored in bits 0-3, then bits 4-7
will be cleared to zero.

@param dst		 Pointer to location to store ADPCM values.
@param dstOffset Offset from \a dst, in number-of-bits, at which the decoded values
				 will be stored. I.e. the least significant bit of the first ADPCM
				 value will be stored in byte 
				 @code	 dst[dstOffset>>3]	 @endcode
				 at bit position
				 @code	 dstOffset&7		 @endcode
				 Where the bit 0 is the least significant bit in a byte
				 and bit 7 is the most significant bit.
				 The value of \a dstOffset must be a multiple of 4.
@param src		 Pointer to the buffer of PCM values to be converted.
@param srcSize	 The size, in bytes, of the buffer at \a src.
				 Must be a multiple of 2.

@return 		 The number of bits which were stored at dst.
*/
IMPORT unsigned Encode(uint8_t* dst, int dstOffset, const int16_t* src, size_t srcSize);

/**
Decode a buffer of ADPCM values into 16 bit uniform PCM values.

Two ADPCM values are stored in each byte. The value stored in bits 0-3
corresponds to the sample preceding that stored in bits 4-7.

@param dst		 Pointer to location to store PCM values.
@param src		 Pointer to the buffer of ADPCM values to be converted.
@param srcOffset Offset from \a src, in number-of-bits, from which the ADPCM values
				 will be read. I.e. the least significant bit of the first ADPCM
				 value will be read from byte 
				 @code	 src[srcOffset>>3]	 @endcode
				 at bit position
				 @code	 srcOffset&7		 @endcode
				 Where the bit 0 is the least significant bit in a byte
				 and bit 7 is the most significant bit.
				 The value of \a srcOffset must be a multiple of 4.
@param srcSize	 The number of bits to be read from the buffer at \a src.
				 Must be a multiple of the size of 4.

@return 		 The number of bytes which were stored at dst.
*/
IMPORT unsigned Decode(int16_t* dst, const uint8_t* src, int srcOffset, unsigned srcSize);
public:
/**
The predicted value of the next sample.
Typically, this value is read from the header, or written to the header, of a block
of ADPCM values.
*/
int16_t PredictedValue;

/**
The step index used for the next ADPCM value
Typically, this value is read from the header, or written to the header, of a block
of ADPCM values.
*/
uint8_t StepIndex;
};

/** @} */ // End of group

#endif




ima_adpcm.cpp

/*
This program is distributed under the terms of the 'MIT license'. The text
of this licence follows...

Copyright (c) 2005 J.D.Medhurst (a.k.a. Tixy)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
@file

@brief Implementation of the IMA ADPCM audio coding algorithm
*/

#include "common.h"
#include "IMA_ADPCM.h"


static const uint16_t IMA_ADPCMStepTable[89] =
{
7,	  8,	9,	 10,   11,	 12,   13,	 14,
16,	 17,   19,	 21,   23,	 25,   28,	 31,
34,	 37,   41,	 45,   50,	 55,   60,	 66,
73,	 80,   88,	 97,  107,	118,  130,	143,
157,	173,  190,	209,  230,	253,  279,	307,
337,	371,  408,	449,  494,	544,  598,	658,
724,	796,  876,	963, 1060, 1166, 1282, 1411,
1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
7132, 7845, 8630, 9493,10442,11487,12635,13899,
15289,16818,18500,20350,22385,24623,27086,29794,
32767
};


static const int IMA_ADPCMIndexTable[8] =
{
-1, -1, -1, -1, 2, 4, 6, 8,
};


EXPORT void IMA_ADPCM::EncodeInit(int16_t sample1,int16_t sample2)
{
PredictedValue = sample1;
int delta = sample2-sample1;
if(delta<0)
	delta = - delta;
if(delta>32767)
	delta = 32767;
int stepIndex = 0;
while(IMA_ADPCMStepTable[stepIndex]<(unsigned)delta)
	stepIndex++;
StepIndex = stepIndex;
}


EXPORT unsigned IMA_ADPCM::Encode(int16_t pcm16)
{
int predicedValue = PredictedValue;
int stepIndex = StepIndex;

int delta = pcm16-predicedValue;
unsigned value;
if(delta>=0)
	value = 0;
else
{
	value = 8;
	delta = -delta;
}

int step = IMA_ADPCMStepTable[stepIndex];
int diff = step>>3;
if(delta>step)
{
	value |= 4;
	delta -= step;
	diff += step;
}
step >>= 1;
if(delta>step)
{
	value |= 2;
	delta -= step;
	diff += step;
}
step >>= 1;
if(delta>step)
{
	value |= 1;
	diff += step;
}

if(value&8)
	predicedValue -= diff;
else
	predicedValue += diff;
if(predicedValue<-0x8000)
	predicedValue = -0x8000;
else if(predicedValue>0x7fff)
	predicedValue = 0x7fff;
PredictedValue = predicedValue;

stepIndex += IMA_ADPCMIndexTable[value&7];
if(stepIndex<0)
	stepIndex = 0;
else if(stepIndex>88)
	stepIndex = 88;
StepIndex = stepIndex;

return value;
}


EXPORT int IMA_ADPCM::Decode(unsigned adpcm)
{
int stepIndex = StepIndex;
int step = IMA_ADPCMStepTable[stepIndex];

stepIndex += IMA_ADPCMIndexTable[adpcm&7];
if(stepIndex<0)
	stepIndex = 0;
else if(stepIndex>88)
	stepIndex = 88;
StepIndex = stepIndex;

int diff = step>>3;
if(adpcm&4)
	diff += step;
if(adpcm&2)
	diff += step>>1;
if(adpcm&1)
	diff += step>>2;

int predicedValue = PredictedValue;
if(adpcm&8)
	predicedValue -= diff;
else
	predicedValue += diff;
if(predicedValue<-0x8000)
	predicedValue = -0x8000;
else if(predicedValue>0x7fff)
	predicedValue = 0x7fff;
PredictedValue = predicedValue;

return predicedValue;
}


EXPORT unsigned IMA_ADPCM::Encode(uint8_t* dst, int dstOffset, const int16_t* src, size_t srcSize)
{
// use given bit offset
dst += dstOffset>>3;
unsigned bitOffset = dstOffset&4;

// make sure srcSize represents a whole number of samples
srcSize &= ~1;

// calculate end of input buffer
const int16_t* end = (const int16_t*)((const uint8_t*)src+srcSize);

while(src<end)
{
	// encode a pcm value from input buffer
	unsigned adpcm = Encode(*src++);

	// pick which nibble to write adpcm value to...
	if(!bitOffset)
		*dst = adpcm;		// write adpcm value to low nibble
	else
	{
		unsigned b = *dst;		// get byte from ouput
		b &= 0x0f;			// clear bits of high nibble
		b |= adpcm<<4;		// or adpcm value into the high nibble
		*dst++ = (uint8_t)b;	// write value back to output and move on to next byte
	}

	// toggle which nibble in byte to write to next
	bitOffset ^= 4; 		
}

// return number bits written to dst
return srcSize*2;
}


EXPORT unsigned IMA_ADPCM::Decode(int16_t* dst, const uint8_t* src, int srcOffset, unsigned srcSize)
{
// use given bit offset
src += srcOffset>>3;

// calculate pointers to iterate output buffer
int16_t* out = dst;
int16_t* end = out+(srcSize>>2);

while(out<end)
{
	// get byte from src
	unsigned adpcm = *src; 

	// pick which nibble holds a adpcm value...
	if(srcOffset&4)
	{
		adpcm >>= 4;  // use high nibble of byte
		++src;		  // move on a byte for next sample
	}

	*out++ = Decode(adpcm);  // decode value and store it

	// toggle which nibble in byte to write to next
	srcOffset ^= 4;
}

// return number of bytes written to dst
return (unsigned)out-(unsigned)dst;
}

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora