#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
}
}
I hopes somebody can help me. Thank you
Last edited by ThorstenD on Fri Mar 27, 2009 1:55 pm, edited 1 time in total.
I would try and convert it but without a test-case I might be way off. The only thing that might be misleading is the '->'. If you pass a structure pointer you can access structure members using the '\' character instead of C's '.'.
Hell yeah. The example above taught me a thing or two about C conversions.
It's like looking at the ASM output of a PureBasic source; it teaches you a bit
about ASM when reading it. But I know it's a big ask, I was just wondering if
it's an easy thing to do.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
@Hroudtwolf
Many thanks for the fast help. Functions like it has to do. Thank you also to the other. Have a nice day and up to next... Greetings Thorsten