Need help to convert C to PB [Resolved]
Posted: Fri Mar 27, 2009 8:56 am
Hello people!
Am new here and needs help with convert from following C code:
I hopes somebody can help me. Thank you 
Am new here and needs help with convert from following C code:
Code: Select all
#define amptarget 30000 // target level
#define ampquiet 800 // quiet level
#define amprate 0.02f // amp adjustment rate
typedef struct {
float gain; // amplification level
int delay; // delay before increasing level
int count; // count of sequential samples below target level
int high; // the highest in that period
int quiet; // count of sequential samples below quiet level
} AUTOAMPSTUFF;
void CALLBACK autoamp(HDSP handle, DWORD channel, void *buffer, DWORD length, AUTOAMPSTUFF *amp)
{
short *data=(short*)buffer;
DWORD c;
for (c=0;c<length/2;c++) {
int s=(int)(data[c]*amp->gain); // amplify sample
int sa=abs(s);
if (abs(data[c])<ampquiet)
amp->quiet++; // sample is below quiet level
else
amp->quiet=0;
if (sa<amptarget) { // amplified level is below target
if (sa>amp->high) amp->high=sa;
amp->count++;
if (amp->count==amp->delay) { // been below target for a while
if (amp->quiet>amp->delay)
// it's quiet, go back towards normal level
amp->gain+=10*amprate*(1-amp->gain);
else
amp->gain+=amprate*amptarget/amp->high; // increase amp
amp->high=amp->count=0; // reset counts
}
} else { // amplified level is above target
if (s<-32768) s=-32768;
else if (s>32767) s=32767;
amp->gain-=2*amprate*sa/amptarget; // decrease amp
amp->high=amp->count=0;
}
data[c]=(short)s; // replace original sample with amplified version
}
}
