Forrest Zhang
2019-May-27 11:58 UTC
[opus] opus-1.3.1 patch for ARM Cortex-M4F (single precision)
The patch prevents KEIL MDK compile warnings, like: warning: #1035-d: single-precision operand implicitly converted to double-precision Actually ARM Cortex-M4F has only a *single precision* (float) FPU. It's suit for all platforms. See the comment at the begin of patch file. Sincerely Forrest Zhang -------------- next part -------------- Specify the floating point constant with single precision. The patch changes the similar line A to B. A: if (analysis->activity<.4) B: if (analysis->activity<.4f) For ARM Cortex-M4F, it has only a *single precision* (float) FPU, and Keil MDK compiler cannot recognize "-fsingle-precision-constant". The compiler gives the following warning to the line A warning: #1035-d: single-precision operand implicitly converted to double-precision More details, refer to: https://mcuoneclipse.com/2019/03/29/be-aware-floating-point-operations-on-arm-cortex-m4f/ diff -Naupr opus-1.3.1-vanilla/celt/celt_encoder.c opus-1.3.1/celt/celt_encoder.c --- opus-1.3.1-vanilla/celt/celt_encoder.c 2018-10-17 03:52:45 +0800 +++ opus-1.3.1/celt/celt_encoder.c 2019-05-27 17:15:55 +0800 @@ -1321,7 +1321,7 @@ static int compute_vbr(const CELTMode *m /*printf("%f %f %f %f %d %d ", st->analysis.activity, st->analysis.tonality, tf_estimate, st->stereo_saving, tot_boost, coded_bands);*/ #ifndef DISABLE_FLOAT_API - if (analysis->valid && analysis->activity<.4) + if (analysis->valid && analysis->activity<.4f) target -= (opus_int32)((coded_bins<<BITRES)*(.4f-analysis->activity)); #endif /* Stereo savings */ @@ -1666,7 +1666,7 @@ int celt_encode_with_ec(CELTEncoder * OP prefilter_tapset = st->tapset_decision; pf_on = run_prefilter(st, in, prefilter_mem, CC, N, prefilter_tapset, &pitch_index, &gain1, &qg, enabled, nbAvailableBytes, &st->analysis); - if ((gain1 > QCONST16(.4f,15) || st->prefilter_gain > QCONST16(.4f,15)) && (!st->analysis.valid || st->analysis.tonality > .3) + if ((gain1 > QCONST16(.4f,15) || st->prefilter_gain > QCONST16(.4f,15)) && (!st->analysis.valid || st->analysis.tonality > .3f) && (pitch_index > 1.26*st->prefilter_period || pitch_index < .79*st->prefilter_period)) pitch_change = 1; if (pf_on==0) diff -Naupr opus-1.3.1-vanilla/celt/fixed_generic.h opus-1.3.1/celt/fixed_generic.h --- opus-1.3.1-vanilla/celt/fixed_generic.h 2018-09-26 14:49:41 +0800 +++ opus-1.3.1/celt/fixed_generic.h 2019-05-27 17:16:07 +0800 @@ -65,10 +65,10 @@ #endif /** Compile-time conversion of float constant to 16-bit value */ -#define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) +#define QCONST16(x,bits) ((opus_val16)(.5f+(x)*(((opus_val32)1)<<(bits)))) /** Compile-time conversion of float constant to 32-bit value */ -#define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits)))) +#define QCONST32(x,bits) ((opus_val32)(.5f+(x)*(((opus_val32)1)<<(bits)))) /** Negate a 16-bit value */ #define NEG16(x) (-(x)) diff -Naupr opus-1.3.1-vanilla/celt/mathops.h opus-1.3.1/celt/mathops.h --- opus-1.3.1-vanilla/celt/mathops.h 2018-09-26 14:49:41 +0800 +++ opus-1.3.1/celt/mathops.h 2019-05-27 17:17:49 +0800 @@ -38,7 +38,7 @@ #include "entcode.h" #include "os_support.h" -#define PI 3.141592653f +#define PI 3.14159265358979f /* Multiplies two 16-bit fractional values. Bit-exactness of this macro is important */ #define FRAC_MUL16(a,b) ((16384+((opus_int32)(opus_int16)(a)*(opus_int16)(b)))>>15) diff -Naupr opus-1.3.1-vanilla/celt/modes.c opus-1.3.1/celt/modes.c --- opus-1.3.1-vanilla/celt/modes.c 2018-09-26 14:49:41 +0800 +++ opus-1.3.1/celt/modes.c 2019-05-27 17:18:26 +0800 @@ -71,7 +71,7 @@ static const unsigned char band_allocati #endif /* CUSTOM_MODES_ONLY */ #ifndef M_PI -#define M_PI 3.141592653 +#define M_PI 3.14159265358979f #endif #ifdef CUSTOM_MODES diff -Naupr opus-1.3.1-vanilla/silk/SigProc_FIX.h opus-1.3.1/silk/SigProc_FIX.h --- opus-1.3.1-vanilla/silk/SigProc_FIX.h 2018-09-26 14:49:41 +0800 +++ opus-1.3.1/silk/SigProc_FIX.h 2019-05-27 17:18:59 +0800 @@ -540,7 +540,7 @@ static OPUS_INLINE opus_int32 silk_ROR32 #define silk_max(a, b) (((a) > (b)) ? (a) : (b)) /* Macro to convert floating-point constants to fixed-point */ -#define SILK_FIX_CONST( C, Q ) ((opus_int32)((C) * ((opus_int64)1 << (Q)) + 0.5)) +#define SILK_FIX_CONST( C, Q ) ((opus_int32)((C) * ((opus_int64)1 << (Q)) + 0.5f)) /* silk_min() versions with typecast in the function call */ static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) diff -Naupr opus-1.3.1-vanilla/silk/quant_LTP_gains.c opus-1.3.1/silk/quant_LTP_gains.c --- opus-1.3.1-vanilla/silk/quant_LTP_gains.c 2018-09-26 14:49:41 +0800 +++ opus-1.3.1/silk/quant_LTP_gains.c 2019-05-27 17:18:47 +0800 @@ -79,7 +79,7 @@ void silk_quant_LTP_gains( rate_dist_Q7 = 0; sum_log_gain_tmp_Q7 = *sum_log_gain_Q7; for( j = 0; j < nb_subfr; j++ ) { - max_gain_Q7 = silk_log2lin( ( SILK_FIX_CONST( MAX_SUM_LOG_GAIN_DB / 6.0, 7 ) - sum_log_gain_tmp_Q7 ) + max_gain_Q7 = silk_log2lin( ( SILK_FIX_CONST( MAX_SUM_LOG_GAIN_DB / 6.0f, 7 ) - sum_log_gain_tmp_Q7 ) + SILK_FIX_CONST( 7, 7 ) ) - gain_safety; silk_VQ_WMat_EC( &temp_idx[ j ], /* O index of best codebook vector */ diff -Naupr opus-1.3.1-vanilla/src/analysis.c opus-1.3.1/src/analysis.c --- opus-1.3.1-vanilla/src/analysis.c 2019-02-26 06:04:23 +0800 +++ opus-1.3.1/src/analysis.c 2019-05-27 17:19:28 +0800 @@ -45,7 +45,7 @@ #include "float_cast.h" #ifndef M_PI -#define M_PI 3.141592653 +#define M_PI 3.14159265358979f #endif #ifndef DISABLE_FLOAT_API @@ -675,7 +675,7 @@ static void tonality_analysis(TonalityAn tonal->logE[tonal->E_count][b] = logE[b]; if (tonal->count==0) tonal->highE[b] = tonal->lowE[b] = logE[b]; - if (tonal->highE[b] > tonal->lowE[b] + 7.5) + if (tonal->highE[b] > tonal->lowE[b] + 7.5f) { if (tonal->highE[b] - logE[b] > logE[b] - tonal->lowE[b]) tonal->highE[b] -= .01f; @@ -700,7 +700,7 @@ static void tonality_analysis(TonalityAn L2 += tonal->E[i][b]; } - stationarity = MIN16(0.99f,L1/(float)sqrt(1e-15+NB_FRAMES*L2)); + stationarity = MIN16(0.99f,L1/(float)sqrt(1e-15f+NB_FRAMES*L2)); stationarity *= stationarity; stationarity *= stationarity; frame_stationarity += stationarity; @@ -748,7 +748,7 @@ static void tonality_analysis(TonalityAn neighbouring bands. */ float boost = MAX16(0, leakage_to[b] - band_log2[b]) + MAX16(0, band_log2[b] - (leakage_from[b]+LEAKAGE_OFFSET)); - info->leak_boost[b] = IMIN(255, (int)floor(.5 + 64.f*boost)); + info->leak_boost[b] = IMIN(255, (int)floor(.5f + 64.f*boost)); } for (;b<LEAK_BANDS;b++) info->leak_boost[b] = 0; diff -Naupr opus-1.3.1-vanilla/src/opus_encoder.c opus-1.3.1/src/opus_encoder.c --- opus-1.3.1-vanilla/src/opus_encoder.c 2019-04-11 07:47:31 +0800 +++ opus-1.3.1/src/opus_encoder.c 2019-05-27 17:19:54 +0800 @@ -348,8 +348,8 @@ static void hp_cutoff(const opus_val16 * opus_int32 Fc_Q19, r_Q28, r_Q22; (void)arch; - silk_assert( cutoff_Hz <= silk_int32_MAX / SILK_FIX_CONST( 1.5 * 3.14159 / 1000, 19 ) ); - Fc_Q19 = silk_DIV32_16( silk_SMULBB( SILK_FIX_CONST( 1.5 * 3.14159 / 1000, 19 ), cutoff_Hz ), Fs/1000 ); + silk_assert( cutoff_Hz <= silk_int32_MAX / SILK_FIX_CONST( 1.5f * PI / 1000, 19 ) ); + Fc_Q19 = silk_DIV32_16( silk_SMULBB( SILK_FIX_CONST( 1.5f * PI / 1000, 19 ), cutoff_Hz ), Fs/1000 ); silk_assert( Fc_Q19 > 0 && Fc_Q19 < 32768 ); r_Q28 = SILK_FIX_CONST( 1.0, 28 ) - silk_MUL( SILK_FIX_CONST( 0.92, 9 ), Fc_Q19 ); @@ -1182,7 +1182,7 @@ opus_int32 opus_encode_native(OpusEncode prob = analysis_info.music_prob_max; else prob = analysis_info.music_prob_min; - st->voice_ratio = (int)floor(.5+100*(1-prob)); + st->voice_ratio = (int)floor(.5f+100*(1-prob)); } analysis_bandwidth = analysis_info.bandwidth;