Updating oscillator phase with fixed point arithmetic

I have seen some articles and youtube videos that mention updating oscillator phase using fixed point rather than floating point arithmetic. I gather that it involves creating “artificial” bits to accumulate phase and bit shifting to obtain the integer index but I have been unable to find a source which clearly describes the method so it remains a mystery to me. I’m interested in investigating this further and I would appreciate hearing from anyone who has had experience with this method or can point me to a source which provides a complete description.

Thanks.

float ug_oscillator2::get_sample( float* wavedata, const unsigned int p_count) const
{
	// method 2: int counter. 16% faster on benchmark!
	const unsigned int jflone = 0x3f800000; // see 'numerical recipies in c' pg 285
	const unsigned int jflmsk = 0x007fffff;
	unsigned int itemp = jflone | (jflmsk & p_count );	// use low 23 bits as interpolation fraction
	float* p = wavedata + (p_count >> 23); // keep top 9 bits as index into 512 entry wavetable
	return p[0] + (p[1] - p[0]) * ((*(float*)&itemp) - 1.f);

Thanks Jeff! This is very helpful.

1 Like