Interpolation algorithm uses neighbor sample - so we can optimize ADPCM channel process to use last decoded values. We can rid of "nxt*" variables and second adpcm decode cycles (will speed up ADPCM a little bit). Following diff against aosdk 1.4.1 shows my assumption.
Code
diff -Nru aosdk_base/eng_dsf/aica.c aosdk/eng_dsf/aica.c
--- aosdk_base/eng_dsf/aica.c 2008-03-07 21:21:32.000000000 +0300
+++ aosdk/eng_dsf/aica.c 2008-07-27 23:05:18.596041500 +0400
@@ -125,12 +125,10 @@
struct _LFO ALFO; //Amplitude LFO
int slot;
int cur_sample; //current ADPCM sample
- int nxt_sample; //next ADPCM sample
int cur_quant; //current ADPCM step
- int nxt_quant; //next ADPCM step
- int curstep, nxtstep;
+ int curstep;
int cur_lpquant, cur_lpsample, cur_lpstep;
- UINT8 *adbase, *nxtbase, *adlpbase;
+ UINT8 *adbase, *adlpbase;
UINT8 mslc; // monitored?
};
@@ -431,10 +429,9 @@
UINT8 *base;
UINT32 curstep, steps_to_go;
- slot->curstep = slot->nxtstep = 0;
- slot->adbase = slot->nxtbase = (unsigned char *) (AICA->AICARAM+((SA(slot))&0x7fffff));
+ slot->curstep = 0;
+ slot->adbase = (unsigned char *) (AICA->AICARAM+((SA(slot))&0x7fffff));
InitADPCM(&(slot->cur_sample), &(slot->cur_quant));
- InitADPCM(&(slot->nxt_sample), &(slot->nxt_quant));
InitADPCM(&(slot->cur_lpsample), &(slot->cur_lpquant));
// walk to the ADPCM state at LSA
@@ -956,7 +953,6 @@
UINT32 addr1,addr2,addr_select; // current and next sample addresses
UINT32 *addr[2] = {&addr1, &addr2}; // used for linear interpolation
UINT32 *slot_addr[2] = {&(slot->cur_addr), &(slot->nxt_addr)}; //
- int *adpcm_sample[2] = {&(slot->cur_sample), &(slot->nxt_sample)};
if(SSCTL(slot)!=0) //no FM or noise yet
return 0;
@@ -1007,12 +1003,16 @@
UINT8 *p1=(unsigned char *) (AICA->AICARAM+((SA(slot)+(addr1>>1))&0x7fffff));
UINT8 *p2=(unsigned char *) (AICA->AICARAM+((SA(slot)+(addr2>>1))&0x7fffff));
INT32 s;
+ int cur_sample; //current ADPCM sample
+ int nxt_sample; //next ADPCM sample
INT32 fpart=slot->cur_addr&((1<<SHIFT)-1);
- UINT32 steps_to_go = addr1, curstep = slot->curstep;
+ UINT32 steps_to_go = addr2, curstep = slot->curstep;
if (slot->adbase)
{
- // seek to the current sample
+ cur_sample = slot->cur_sample; // may already contains current decoded sample
+
+ // seek to the interpolation sample
while (curstep < steps_to_go)
{
int shift1, delta1;
@@ -1024,33 +1024,15 @@
{
base++;
}
+ if (curstep == addr1)
+ cur_sample = slot->cur_sample;
}
+ nxt_sample = slot->cur_sample;
slot->adbase = base;
slot->curstep = curstep;
- base = slot->nxtbase;
- curstep = slot->nxtstep;
- steps_to_go = addr2;
-
- // seek to the interpolation sample
- while (curstep < steps_to_go)
- {
- int shift1, delta1;
- shift1 = 4*((curstep&1));
- delta1 = (*base>>shift1)&0xf;
- DecodeADPCM(&(slot->nxt_sample),delta1,&(slot->nxt_quant));
- curstep++;
- if (!(curstep & 1))
- {
- base++;
- }
- }
-
- slot->nxtbase = base;
- slot->nxtstep = curstep;
-
- s=(int) slot->cur_sample*((1<<SHIFT)-fpart)+(int) slot->nxt_sample*fpart;
+ s=(int)cur_sample*((1<<SHIFT)-fpart)+(int)nxt_sample*fpart;
}
else
{
@@ -1093,7 +1075,7 @@
rem_addr = *slot_addr[addr_select] - (LEA(slot)<<SHIFT);
*slot_addr[addr_select]=(LSA(slot)<<SHIFT) + rem_addr;
- if(PCMS(slot)>=2 && addr_select==0)
+ if(PCMS(slot)>=2)
{
// restore the state @ LSA - the sampler will naturally walk to (LSA + remainder)
slot->adbase = &AICA->AICARAM[SA(slot)+(LSA(slot)/2)];
@@ -1106,16 +1088,6 @@
// printf("Looping: slot_addr %x LSA %x LEA %x step %x base %x\n", *slot_addr[addr_select]>>SHIFT, LSA(slot), LEA(slot), slot->curstep, slot->adbase);
}
- else if(PCMS(slot)>=2 && addr_select==1)
- {
- slot->nxtbase = &AICA->AICARAM[SA(slot)+(LSA(slot)/2)];
- slot->nxtstep = LSA(slot);
- if (PCMS(slot) == 2)
- {
- slot->nxt_sample = slot->cur_lpsample;
- slot->nxt_quant = slot->cur_lpquant;
- }
- }
}
break;
}