2828static int32_t smpShiftValue ;
2929static uint32_t oldAudioFreq , tickTimeLenInt , randSeed = INITIAL_DITHER_SEED ;
3030static uint64_t tickTimeLenFrac ;
31- static float fSqrtPanningTable [256 + 1 ];
32- static double dAudioNormalizeMul , dPrngStateL , dPrngStateR ;
31+ static float fSqrtPanningTable [256 + 1 ], fAudioNormalizeMul , fPrngStateL , fPrngStateR ;
3332static voice_t voice [MAX_CHANNELS * 2 ];
3433
3534// globalized
@@ -103,11 +102,11 @@ void setAudioAmp(int16_t amp, int16_t masterVol, bool bitDepth32Flag)
103102 amp = CLAMP (amp , 1 , 32 );
104103 masterVol = CLAMP (masterVol , 0 , 256 );
105104
106- double dAmp = (amp * masterVol ) / (32.0 * 256.0 );
105+ float fAmp = (amp * masterVol ) / (32.0f * 256.0f );
107106 if (!bitDepth32Flag )
108- dAmp *= 32768.0 ;
107+ fAmp *= 32768.0f ;
109108
110- dAudioNormalizeMul = dAmp ;
109+ fAudioNormalizeMul = fAmp ;
111110}
112111
113112void decreaseMasterVol (void )
@@ -194,17 +193,15 @@ void audioSetInterpolationType(uint8_t interpolationType)
194193 // set sinc LUT pointers
195194 if (config .interpolation == INTERPOLATION_SINC8 )
196195 {
197- fSinc_1 = fSinc8_1 ;
198- fSinc_2 = fSinc8_2 ;
199- fSinc_3 = fSinc8_3 ;
196+ for (int32_t i = 0 ; i < SINC_KERNELS ; i ++ )
197+ fSinc [i ] = fSinc8 [i ];
200198
201199 audio .sincInterpolation = true;
202200 }
203201 else if (config .interpolation == INTERPOLATION_SINC16 )
204202 {
205- fSinc_1 = fSinc16_1 ;
206- fSinc_2 = fSinc16_2 ;
207- fSinc_3 = fSinc16_3 ;
203+ for (int32_t i = 0 ; i < SINC_KERNELS ; i ++ )
204+ fSinc [i ] = fSinc16 [i ];
208205
209206 audio .sincInterpolation = true;
210207 }
@@ -381,19 +378,16 @@ void updateVoices(void)
381378
382379 if (status & CF_UPDATE_PERIOD )
383380 {
384- const double dVoiceHz = dPeriod2Hz (ch -> finalPeriod );
381+ v -> delta = period2VoiceDelta (ch -> finalPeriod );
385382
386- // set voice delta
387- v -> delta = (int64_t )((dVoiceHz * audio .dHz2MixDeltaMul ) + 0.5 ); // Hz -> fixed-point delta (rounded)
388383 if (audio .sincInterpolation )
389384 {
390- // decide which sinc LUT to use according to the resampling ratio
391385 if (v -> delta <= sincRatio1 )
392- v -> fSincLUT = fSinc_1 ;
386+ v -> fSincLUT = fSinc [ 0 ] ;
393387 else if (v -> delta <= sincRatio2 )
394- v -> fSincLUT = fSinc_2 ;
388+ v -> fSincLUT = fSinc [ 1 ] ;
395389 else
396- v -> fSincLUT = fSinc_3 ;
390+ v -> fSincLUT = fSinc [ 2 ] ;
397391 }
398392 }
399393
@@ -405,7 +399,7 @@ void updateVoices(void)
405399void resetAudioDither (void )
406400{
407401 randSeed = INITIAL_DITHER_SEED ;
408- dPrngStateL = dPrngStateR = 0.0 ;
402+ fPrngStateL = fPrngStateR = 0.0f ;
409403}
410404
411405static inline int32_t random32 (void )
@@ -420,26 +414,26 @@ static inline int32_t random32(void)
420414static void sendSamples16BitStereo (void * stream , uint32_t sampleBlockLength )
421415{
422416 int32_t out32 ;
423- double dOut , dPrng ;
417+ float fOut , fPrng ;
424418
425419 int16_t * streamPtr16 = (int16_t * )stream ;
426420 for (uint32_t i = 0 ; i < sampleBlockLength ; i ++ )
427421 {
428422 // left channel - 1-bit triangular dithering
429- dPrng = random32 () * (1.0 / (UINT32_MAX + 1.0 )); // -0.5 .. 0.5
430- dOut = ( double ) audio .fMixBufferL [i ] * dAudioNormalizeMul ;
431- dOut = (dOut + dPrng ) - dPrngStateL ;
432- dPrngStateL = dPrng ;
433- out32 = (int32_t )dOut ;
423+ fPrng = ( float ) random32 () * (1.0f / (UINT32_MAX + 1.0f )); // -0.5f .. 0.5f
424+ fOut = audio .fMixBufferL [i ] * fAudioNormalizeMul ;
425+ fOut = (fOut + fPrng ) - fPrngStateL ;
426+ fPrngStateL = fPrng ;
427+ out32 = (int32_t )fOut ;
434428 CLAMP16 (out32 );
435429 * streamPtr16 ++ = (int16_t )out32 ;
436430
437431 // right channel - 1-bit triangular dithering
438- dPrng = random32 () * (1.0 / (UINT32_MAX + 1.0 )); // -0.5 .. 0.5
439- dOut = ( double ) audio .fMixBufferR [i ] * dAudioNormalizeMul ;
440- dOut = (dOut + dPrng ) - dPrngStateR ;
441- dPrngStateR = dPrng ;
442- out32 = (int32_t )dOut ;
432+ fPrng = ( float ) random32 () * (1.0f / (UINT32_MAX + 1.0f )); // -0.5f .. 0.5f
433+ fOut = audio .fMixBufferR [i ] * fAudioNormalizeMul ;
434+ fOut = (fOut + fPrng ) - fPrngStateR ;
435+ fPrngStateR = fPrng ;
436+ out32 = (int32_t )fOut ;
443437 CLAMP16 (out32 );
444438 * streamPtr16 ++ = (int16_t )out32 ;
445439
@@ -450,20 +444,20 @@ static void sendSamples16BitStereo(void *stream, uint32_t sampleBlockLength)
450444
451445static void sendSamples32BitFloatStereo (void * stream , uint32_t sampleBlockLength )
452446{
453- double dOut ;
447+ float fOut ;
454448
455449 float * fStreamPtr32 = (float * )stream ;
456450 for (uint32_t i = 0 ; i < sampleBlockLength ; i ++ )
457451 {
458452 // left channel
459- dOut = ( double ) audio .fMixBufferL [i ] * dAudioNormalizeMul ;
460- dOut = CLAMP (dOut , -1.0 , 1.0 );
461- * fStreamPtr32 ++ = ( float ) dOut ;
453+ fOut = audio .fMixBufferL [i ] * fAudioNormalizeMul ;
454+ fOut = CLAMP (fOut , -1.0f , 1.0f );
455+ * fStreamPtr32 ++ = fOut ;
462456
463457 // right channel
464- dOut = ( double ) audio .fMixBufferR [i ] * dAudioNormalizeMul ;
465- dOut = CLAMP (dOut , -1.0 , 1.0 );
466- * fStreamPtr32 ++ = ( float ) dOut ;
458+ fOut = audio .fMixBufferR [i ] * fAudioNormalizeMul ;
459+ fOut = CLAMP (fOut , -1.0f , 1.0f );
460+ * fStreamPtr32 ++ = fOut ;
467461
468462 // clear what we read from the mixing buffer
469463 audio .fMixBufferL [i ] = audio .fMixBufferR [i ] = 0.0f ;
0 commit comments