请帮忙把以下C++代码翻译成DELPHI,100分谢,先给30(30分)

  • 主题发起人 白河愁
  • 开始时间

白河愁

Unregistered / Unconfirmed
GUEST, unregistred user!
////////////ADPCM/////////////////////
short adpcmValprev;
// Previous output value;
char adpcmIndex;
// Index into stepsize table
short adpcmStep;
// Stepsize
short adpcmValprevp;
// Previous output value;
char adpcmIndexp;
// Index into stepsize table
short adpcmStepp;
// Stepsize
BOOL adpcmLsbMsb;
//
unsigned short adpcmNibble;

// Intel ADPCM step variation table
static short indexTable[16] = { -1, -1, -1, -1, 2, 4, 6, 8};
static short stepsizeTable[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 };

void adpcm_ini(void)
{
adpcmValprev=0;
adpcmIndex=0;
adpcmStep=stepsizeTable[adpcmIndex];
adpcmValprevp=0;
adpcmIndexp=0;
adpcmStepp=stepsizeTable[adpcmIndexp];
adpcmLsbMsb=FALSE;
} // adpcm_ini()
unsigned short adpcm_code_1_sample(short diff)
{
// short diff; // Difference between val and valprev
BOOL sign;
unsigned char delta; // Current adpcm output value
short vpdiff; // Current change to valpred
//short step; // Stepsize
long aux;
// Step 1 - compute difference with previous value
// diff=val-adpcmValprev;

aux=(long)diff;
aux-=(long)adpcmValprev;
//if (aux>32767) aux=32767;
else
if (aux<-32768) aux=-32768;
if (aux>32767) aux=32767;
else
if (aux<-32767) aux=-32767;
diff=(short)aux;

if (diff<0) {sign=TRUE;diff=-diff;} else
sign=FALSE;
// Step 2 - Divide and clamp
// Note: This code *approximately* computes: delta = diff*4/step;
vpdiff = (delta+0.5)*step/4;
but in shift step bits are dropped.
// The net result of this is that even if you have fast mul/div hardware you cannot put it to good use since the fixup would be too expensive.
delta=0;
vpdiff=adpcmStep>>3;
if (diff>=adpcmStep) {delta =4;
diff-=adpcmStep;
vpdiff+=adpcmStep;} adpcmStep>>=1;
if (diff>=adpcmStep) {delta|=2;
diff-=adpcmStep;
vpdiff+=adpcmStep;} adpcmStep>>=1;
if (diff>=adpcmStep) {delta|=1;
vpdiff+=adpcmStep;}
// Step 3 and 4 - Update previous value and clamp
//if (sign) adpcmValprev-=vpdiff;
else
adpcmValprev+=vpdiff;
//if (adpcmValprev>32767) adpcmValprev=32767;
else
if (adpcmValprev<-32768) adpcmValprev=-32768;
aux=adpcmValprev;
if (sign) aux-=(long)vpdiff;
else
aux+=(long)vpdiff;
// // if (aux>32767) aux=32767;
else
if (aux<-32768) aux=-32768;
if (aux>32767) aux=32767;
else
if (aux<-32767) aux=-32767;
adpcmValprev=(short)aux;
// Step 5 - Assemble value, update index and step values
adpcmIndex+=indexTable[delta];
if (adpcmIndex<0) adpcmIndex=0;
if (adpcmIndex>88) adpcmIndex=88;
adpcmStep=stepsizeTable[adpcmIndex];
if (sign) delta|=0x08;
// Step 6 - Output value
adpcmLsbMsb=!adpcmLsbMsb;
if (adpcmLsbMsb) {adpcmNibble=((unsigned short)delta)<<4;
return(0xffff);}
else
return(adpcmNibble|((unsigned short)delta));
} // adpcm_code_1_sample()

void adpcm_compress(signed short *buffin,unsigned int len,unsigned char *buffout)
{
int i;
adpcm_ini();
for(i=0;i<len;++i)
{
unsigned short sample=adpcm_code_1_sample(buffin);
if(sample!=0xffff)
buffout[i/2]=sample&0xff;
}
}
 
能翻译出来的。我也给他加100分。[:D]
说真的!
 
居然没人会?
 
不是没人会, 而是人太懒, 分太少的缘故...[:D]
 
这段程序不算长吧?
 
既然嫌分少。那我再加100分。连上我以前加的100分,还有白河愁的100分。
现在是300分!
问题一回答出来。我一定以最快的速度另外开一帖子,给足200分!
 
////////////ADPCM/////////////////////
var
adpcmValprev,adpcmStep,adpcmValprevp,adpcmStepp:integer;
adpcmIndex,adpcmIndexp :Char;
adpcmLsbMsb:Boolean;
adpcmNibble:Word;
// Intel ADPCM step variation table
indexTable:array[0..16] of integer=(-1,-1,-1,-1,2,4,6,8);
stepsizeTable:array[0..16] of integer=(
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 );


procedure adpcm_ini;
begin
adpcmValprev := 0;
adpcmIndex := 0;
adpcmStep := stepsizeTable[adpcmIndex];
adpcmValprevp := 0;
adpcmIndexp := 0;
adpcmStepp := stepsizeTable[adpcmIndexp];
adpcmLsbMsb := False;
end;
// adpcm_ini;
function adpcm_code_1_sample(diff:integer):integer;
var
sign :boolean;
delta :char;
vpdiff :integer;
aux :longint;
begin
aux := longint(diff);
aux := longint(adpcmValprev) - aux;
if aux>32767 then
aux=32767
else

if aux<-32767 then

aux := -32767;

diff := integer(aux);

if diff<0 then

begin
sign:=true;
diff:=-diff;
end
else

sign:=false;
delta := 0;
vpdiff := adpcmStep shr 3;
if diff>=adpcmStep then
beign
delta := 4;
diff := adpcmStep - diff;
vpdiff := adpcmStep + vpdiff;
end;
adpcmStep := adpcmStep shr 1;
if diff>=adpcmStep then

beign
delta := delta or 2;
diff := adpcmStep - diff;
vpdiff := adpcmStep + vpdiff;
end;

adpcmStep := adpcmStep shr 1;
if diff>=adpcmStep then
begin
delta := delta or 1;

vpdiff := dpcmStep + vpdiff;
end;

aux := adpcmValprev;
if sign then
aux := longint(vpdiff) - aux
else

aux := longint(vpdiff) + aux;
if aux>32767 then

aux=32767
else

if aux<-32767 then
aux := -32767;
adpcmValprev := integer(aux);
adpcmIndex :=indexTable[delta] + adpcmIndex;

if adpcmIndex<0 then
adpcmIndex := 0;
if adpcmIndex>88 then
adpcmIndex := 88;
adpcmStep := stepsizeTable[adpcmIndex];
if sign then
delta := delta or 0x08;
adpcmLsbMsb := not adpcmLsbMsb;
if adpcmLsbMsb then

begin
adpcmNibble :=word(delta) shl 4;
Result := $FFFF;
end
else

Resutl := adpcmNibble OR Word(delta);
end;
// adpcm_code_1_sample()

// void adpcm_compress(signed short *buffin,unsigned int len,unsigned char *buffout)
procedure adpcm_compress(var buffin:integer,integer len,var buffout:string);
var
i:integer;
sample:word;
begin
adpcm_ini();
for i=0 to len-1 do

begin
sample := adpcm_code_1_sample(buffin);
if sample <> $FFFF then
buffout[i div 2]=sample AND $FF;
end;
 
给点专业精神吧,不能编译的有什么用?
 
拜托有点专业精神好不好,这样叫翻译?
 
你很小器,一看就知道是奸商,不是程序员,给你干什么?
 
UP。
这么久了为什么还没人回答?[:)]
我再加100分如何?一共400分了。[:)]
 
虽然没答案,算了。
 
顶部