Hi, I am experimenting with writing my own audio library objects. Look a build a harmonic distortion algorithm and thought I'd try and use the optimized integer math functions the audio library provides.
My harmonic distortion is a transfer function represented by:
y = x - x^2 * x2c - x^3 * x3c
For variable amounts of second and third order harmonic distortion.
My question is whether I'm using the dspint functions correctly for this purpose. Does this implementation look alright?
My harmonic distortion is a transfer function represented by:
y = x - x^2 * x2c - x^3 * x3c
For variable amounts of second and third order harmonic distortion.
My question is whether I'm using the dspint functions correctly for this purpose. Does this implementation look alright?
Code:
void Harmonic_Distortion::update(void)
{
audio_block_t *block = receiveWritable(0);
if(block){
for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
int32_t x2 = multiply_16bx16b(block->data[i], block->data[i]);
int32_t x3 = multiply_32x16b(x2, block->data[i]);
x2 = multiply_32x16b(x2c, x2);
x3 = multiply_32x16b(x3c, x3);
block->data[i] -= (x2 + x3);
block->data[i] = signed_saturate_rshift(block->data[i], 16, 0);
}
transmit(block);
release(block);
}
}