/************************************************************************/ /* APPENDIX A.1 */ /* Adaptive Delta Modulation 2/23/95 */ /* */ /************************************************************************/ /* */ /* This program uses adaptive delta modulation to reconstruct a */ /* speech input. The step size is made variable to better */ /* estimate the actual signal. */ /* */ /* This program defines the port addressses for the */ /* particular input and output channel being used, sets up the */ /* IRQ3 to call the delta-modulation routine, and sets up */ /* an idle wait loop to conserve power while waiting for the */ /* interrupt. */ /************************************************************************/ #include <21020.h> /* For the idle() command */ #include /* For the interrupt command */ #include /* For the segment function */ #include volatile int in_port segment(hip_reg0); /* hip_reg0, hip_reg2, hip_reg3 are */ volatile int out_port segment(hip_reg2);/* used in architecture file */ volatile int out_port2 segment(hip_reg3); float current, previous,energy,sumcross=0,sumpower=0; int button=0,temp,j=0,i=0,on,counter=0; int correlation,x,b,value,value1; float crossing[25]; float dist[25]; float power[25]; void process_input(int); void main(void) { interrupt(SIG_IRQ3, process_input); while (1) { set_flag(SET_FLAG1, CLR_FLAG); set_flag(SET_FLAG2, CLR_FLAG); set_flag(SET_FLAG3, CLR_FLAG); temp=10000000; poll_flag_in(0,0); i=0; button=1; j++; set_flag(SET_FLAG1, SET_FLAG); poll_flag_in(0,1); crossing[j]=(counter/i); power[j]=(energy/i); if (j==5) {for (b=1;b<=5;b++) {sumcross=sumcross+crossing[b]; sumpower=sumpower+power[b];} for (b=1;b<=5;b++) {crossing[b]=crossing[b]/sumcross; power[b]=power[b]/sumpower;}} button=0; set_flag(SET_FLAG1, CLR_FLAG); counter=0; if(j>=6) crossing[j]=crossing[j]/sumcross; power[j]=power[j]/sumpower; {for(x=1;x<=5;x++) {dist[x]=(crossing[x]-crossing[j])*(crossing[x]-crossing[j])+(power[x]-power[j])*(power[x]-power[j]); if(dist[x]0) value=1; else value=2; previous=previous/524288; energy=previous*previous;} else {current=in_port; current=current/(1-0.95*previous); if (current>0) value1=1; else value1=2; if ((value1-value)!=0) counter++; value=value1; current=current/524288; energy=energy+current*current; previous=current;} } }