Hello,
So I am trying just to implement a short code from a book ;-)
When I call the Compression function, the LXR stops running :-(
everything is blocked, no possibility to launch the sequencer anymore, no sound, etc.
Any idea where I am doing something wrong in the code?
One of my guess would be the audio buffer (int16_t *buf) that is not returned correctly once the compression funtion is finished ?
Thanks!
main.c
calcCompressionBlock(buf,size,-20,7,0.1,0.5,1.0);
disto.c
float calcCompressionBlock(int16_t* buf,const uint8_t size, int8_t threshold,uint8_t ratio,float attack_constant,float release_constant,float penv)
{
int i;
float th, rat;
float ac, rc;
float env = penv;
float indb, dest;
float inp[size];
float outp[size];
th = (float) threshold; // in dB FS
rat = 1.0 - (1.0/(float) ratio); // to calculate gain reduction
ac = 1.0 / ((float) attack_constant * (float) SR);
rc = 1.0 / ((float) release_constant * (float) SR);
//env = 1.0;
// -32767 + 32767 to -1.0 +1.0
for(i = 0; i < size; i++){
inp[i] = buf[i]/32767.0f;
}
// compression
//
for(i = 0; i < size; i++)
{
indb = 20.0 * log10(fabs(inp[i])); // to dB FS
if (indb > th) {
dest = (th - indb) * rat; // Gain reduction target
}
else {
dest = 0.0;
}
dest = pow(10, dest * 0.05); // to linear amp
if (env > dest) { // attack
env = env + (dest-env)*ac;
}
else { // release
env = env + (dest-env)*rc;
}
outp[i] = inp[i]* env;
}
// -1.0 +1.0 to -32767 + 32767
for(i = 0; i < size; i++){
buf[i] = outp[i]*32767;
}
return env; // the new ENV value that I should catch back and reinject into the next block calculation .. I don't do it yet :-)
}
Comments
arg. you are going to say my quesiton is stupid but which ANSI C are we compiling if not C99 ?
sorry again for this dummy question :-)
for(i = 0; i < size; i++){
inp[i] = buf[i]/32767.0f;
}
// -1.0 +1.0 to -32767 + 32767
for(i = 0; i < size; i++){
buf[i] = outp[i]*32767;
}
the sound is OKAY.
rat = 1.0 - (1.0/(float) ratio); // to calculate gain reduction
ac = 1.0 / ((float) attack_constant * (float) SR);
rc = 1.0 / ((float) release_constant * (float) SR);
if either 'ratio', 'attack_constant', 'release_constant' or 'SR' == 0 the code will crash.
sorry for my silence, I am a bit busy with work and concert :-) I will play the LXR on the 21st of june in Grenoble, France :-) 23 PM :-) main tekno scene !!!! Parc paul mistral :-)
next week, I will check back my code and chase the divide by sero issue :-)
Meanwhile, I am using the LXR and my code and noticed a bug (when you do RND and save the results, the KIT is not saved with the new random sound, strange ! ). I need to correct this before going back to coding effects.
talk to you soon :-)
So I was at the main scene in Grenoble for Electro Music (very good hour - 11PM till 12PM)... many people and BIG system sound :-)
The LXR sounds just excellent, it was adding PERCUSSIVE sounds to the main composition we played with my friend (a lot of toms, hit hat and I over used the ROLL function !). I used a lot the SRR function (sample rate reduction) but I want to improve the one delivered with the LXR as it lacks of harmonics (I have a idea for this .. adding a sine to the SRR function.. well).
I like the LXR because it adds on top of other sounds its own caracter !
it is much more significant that with a elektron (I have one) drum machine... Also I like that the LXR program and machine is robust, it last one hour without any bugs, etc. it is small, nice, easy to use, I love it!
I will publish one minute of video soon :-)
regards.
so far I just know it from my cheap fostex monitors :-/