Proper Use of Optimized DSPInt Functions

grinch

Well-known member
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?

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);
  }

}
 
I would say, that does not work as intended.
Not for using DSPInt functions that are really not necessary for 32-bit operations, but compiler should be able to handle that.
But for taking the 3rd power of a 16bit value. In particular x3, defined as 32 bit can easily be too small for a potential 48 bit value (3*16 bit)
scaling all multiplication results back to 16 bit could help
 
Back
Top