Skip to content

Commit

Permalink
templatification of dsp code
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Dec 8, 2024
1 parent 4635b09 commit 8232349
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 113 deletions.
32 changes: 24 additions & 8 deletions src/rvoice/fluid_rvoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,37 @@ int fluid_rvoice_dsp_interpolate_7th_order(fluid_rvoice_t *voice, fluid_real_t *
* least sig. 8 bit part in order to create a 24 bit sample.
*/
static FLUID_INLINE int32_t
fluid_rvoice_get_sample(const short int *dsp_msb, const char *dsp_lsb, unsigned int idx)
fluid_rvoice_get_sample24(const short int *FLUID_RESTRICT dsp_msb, const char *FLUID_RESTRICT dsp_lsb, unsigned int idx)
{
/* cast sample to unsigned type, so we can safely shift and bitwise or
* without relying on undefined behaviour (should never happen anyway ofc...) */
uint32_t msb = (uint32_t)dsp_msb[idx];
uint8_t lsb = 0U;
uint8_t lsb = (uint8_t)dsp_lsb[idx];

/* most soundfonts have 16 bit samples, assume that it's unlikely we
* experience 24 bit samples here */
if(FLUID_UNLIKELY(dsp_lsb != NULL))
return (int32_t)((msb << 8) | lsb);
}

static FLUID_INLINE int32_t
fluid_rvoice_get_sample16(const short int *FLUID_RESTRICT dsp_msb, unsigned int idx)
{
/* cast sample to unsigned type, so we can safely shift and bitwise or
* without relying on undefined behaviour (should never happen anyway ofc...) */
uint32_t msb = (uint32_t)dsp_msb[idx];

return (int32_t)((msb << 8) | 0);
}

static FLUID_INLINE int32_t
fluid_rvoice_get_sample(const short int *FLUID_RESTRICT dsp_msb, const char *FLUID_RESTRICT dsp_lsb, unsigned int idx)
{
if (dsp_lsb != NULL)
{
lsb = (uint8_t)dsp_lsb[idx];
return fluid_rvoice_get_sample24(dsp_msb, dsp_lsb, idx);
}
else
{
return fluid_rvoice_get_sample16(dsp_msb, idx);
}

return (int32_t)((msb << 8) | lsb);
}

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 8232349

Please sign in to comment.