eliminate all instances of implicit double-promotion
This commit is contained in:
parent
d002c60a92
commit
639b695f31
@ -17,7 +17,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
AM_CFLAGS = -Wall # -Werror
|
||||
AM_CFLAGS = -Wall # -Werror -Wdouble-promotion
|
||||
|
||||
AM_CPPFLAGS = $(DEPS_CFLAGS)
|
||||
|
||||
|
28
src/fsk.c
28
src/fsk.c
@ -20,7 +20,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h> // fabs, hypotf
|
||||
#include <math.h> // fabsf, hypotf
|
||||
#include <float.h> // FLT_EPSILON
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
@ -49,7 +49,7 @@ fsk_plan_new(
|
||||
#ifdef USE_FFT
|
||||
fskp->band_width = filter_bw;
|
||||
|
||||
float fft_half_bw = fskp->band_width / 2.0;
|
||||
float fft_half_bw = fskp->band_width / 2.0f;
|
||||
fskp->fftsize = (sample_rate + fft_half_bw) / fskp->band_width;
|
||||
fskp->nbands = fskp->fftsize / 2 + 1;
|
||||
|
||||
@ -129,7 +129,7 @@ fsk_bit_analyze( fsk_plan *fskp, float *samples, unsigned int bit_nsamples,
|
||||
|
||||
memcpy(fskp->fftin, samples, bit_nsamples * sizeof(float));
|
||||
|
||||
float magscalar = 2.0 / (float)bit_nsamples;
|
||||
float magscalar = 2.0f / (float)bit_nsamples;
|
||||
|
||||
#if 0
|
||||
//// apodization window
|
||||
@ -148,7 +148,7 @@ fsk_bit_analyze( fsk_plan *fskp, float *samples, unsigned int bit_nsamples,
|
||||
float zoff = 0.0; // 0.5 // FIXME which is it??
|
||||
unsigned int z = bit_nsamples /* not -1 ... explain */;
|
||||
float w = a0
|
||||
- a1 * cos((2.0*M_PI*((float)i+zoff)) / z);
|
||||
- a1 * cosf((2.0*M_PI*((float)i+zoff)) / z);
|
||||
fskp->fftin[i] *= w;
|
||||
}
|
||||
#endif
|
||||
@ -180,7 +180,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
int n_bits, const char *expect_bits_string,
|
||||
unsigned long long *bits_outp, float *ampl_outp )
|
||||
{
|
||||
unsigned int bit_nsamples = (float)(samples_per_bit + 0.5);
|
||||
unsigned int bit_nsamples = (float)(samples_per_bit + 0.5f);
|
||||
|
||||
unsigned int bit_values[64];
|
||||
float bit_sig_mags[64];
|
||||
@ -201,7 +201,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
continue;
|
||||
assert( expect_bits[bitnum] == '1' || expect_bits[bitnum] == '0' );
|
||||
|
||||
bit_begin_sample = (float)(samples_per_bit * bitnum + 0.5);
|
||||
bit_begin_sample = (float)(samples_per_bit * bitnum + 0.5f);
|
||||
debug_log( " bit# %2u @ %7u: ", bitnum, bit_begin_sample);
|
||||
fsk_bit_analyze(fskp, samples+bit_begin_sample, bit_nsamples,
|
||||
&bit_values[bitnum],
|
||||
@ -236,7 +236,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
* diff between start bit and stop bit strength not be "large". */
|
||||
float s_mag = bit_sig_mags[1]; // start bit
|
||||
float p_mag = bit_sig_mags[n_bits-1]; // stop bit
|
||||
if ( fabs(s_mag-p_mag) > (s_mag * FSK_AVOID_TRANSIENTS) ) {
|
||||
if ( fabsf(s_mag-p_mag) > (s_mag * FSK_AVOID_TRANSIENTS) ) {
|
||||
debug_log(" avoid transient\n");
|
||||
return 0.0;
|
||||
}
|
||||
@ -246,7 +246,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
for ( bitnum=0; bitnum<n_bits; bitnum++ ) {
|
||||
if ( expect_bits[bitnum] != 'd' )
|
||||
continue;
|
||||
bit_begin_sample = (float)(samples_per_bit * bitnum + 0.5);
|
||||
bit_begin_sample = (float)(samples_per_bit * bitnum + 0.5f);
|
||||
debug_log( " bit# %2u @ %7u: ", bitnum, bit_begin_sample);
|
||||
fsk_bit_analyze(fskp, samples+bit_begin_sample, bit_nsamples,
|
||||
&bit_values[bitnum],
|
||||
@ -306,7 +306,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
for ( bitnum=0; bitnum<n_bits; bitnum++ ) {
|
||||
float avg_bit_sig_other;
|
||||
avg_bit_sig_other = bit_values[bitnum] ? avg_mark_sig : avg_space_sig;
|
||||
divergence += fabs(bit_sig_mags[bitnum] - avg_bit_sig_other)
|
||||
divergence += fabsf(bit_sig_mags[bitnum] - avg_bit_sig_other)
|
||||
/ avg_bit_sig_other;
|
||||
}
|
||||
divergence *= 2;
|
||||
@ -333,7 +333,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
|
||||
#if CONFIDENCE_ALGO == 6
|
||||
// Frame confidence is the frame ( SNR * consistency )
|
||||
confidence = snr * (1.0 - divergence);
|
||||
confidence = snr * (1.0f - divergence);
|
||||
#else
|
||||
// Frame confidence is the frame SNR
|
||||
confidence = snr;
|
||||
@ -388,8 +388,8 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
else
|
||||
normalized_bit_str = bit_strengths[bitnum] - v_space;
|
||||
debug_log("%.2f ", normalized_bit_str);
|
||||
// float divergence = fabs(1.0 - normalized_bit_str);
|
||||
float divergence = fabs(normalized_bit_str);
|
||||
// float divergence = fabsf(1.0 - normalized_bit_str);
|
||||
float divergence = fabsf(normalized_bit_str);
|
||||
if ( worst_divergence < divergence )
|
||||
worst_divergence = divergence;
|
||||
}
|
||||
@ -423,7 +423,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit,
|
||||
for ( bitnum=0; bitnum<n_bits-1; bitnum++ )
|
||||
{
|
||||
float normalized_bit_str = bit_strengths[bitnum] / v;
|
||||
float divergence = fabs(1.0 - normalized_bit_str);
|
||||
float divergence = fabsf(1.0 - normalized_bit_str);
|
||||
if ( worst_divergence < divergence )
|
||||
worst_divergence = divergence;
|
||||
}
|
||||
@ -548,7 +548,7 @@ fsk_detect_carrier(fsk_plan *fskp, float *samples, unsigned int nsamples,
|
||||
bzero(fskp->fftin, (fskp->fftsize * sizeof(float) * pa_nchannels));
|
||||
memcpy(fskp->fftin, samples, nsamples * sizeof(float));
|
||||
fftwf_execute(fskp->fftplan);
|
||||
float magscalar = 1.0 / ((float)nsamples/2.0);
|
||||
float magscalar = 1.0f / ((float)nsamples/2.0f);
|
||||
float max_mag = 0.0;
|
||||
int max_mag_band = -1;
|
||||
int i = 1; /* start detection at the first non-DC band */
|
||||
|
@ -125,7 +125,7 @@ static void fsk_transmit_stdin(
|
||||
)
|
||||
{
|
||||
size_t sample_rate = simpleaudio_get_rate(sa_out);
|
||||
size_t bit_nsamples = sample_rate / data_rate + 0.5;
|
||||
size_t bit_nsamples = sample_rate / data_rate + 0.5f;
|
||||
|
||||
tx_sa_out = sa_out;
|
||||
tx_bfsk_mark_f = bfsk_mark_f;
|
||||
@ -134,7 +134,7 @@ static void fsk_transmit_stdin(
|
||||
// one-shot
|
||||
struct itimerval itv = {
|
||||
{0, 0}, // it_interval
|
||||
{0, 1000000/(float)(data_rate+data_rate*0.03) } // it_value
|
||||
{0, 1000000/(float)(data_rate+data_rate*0.03f)} // it_value
|
||||
};
|
||||
|
||||
struct itimerval itv_zero = {
|
||||
@ -251,21 +251,21 @@ report_no_carrier( fsk_plan *fskp,
|
||||
nbits_decoded * sample_rate / (float)carrier_nsamples;
|
||||
fprintf(stderr, "\n### NOCARRIER ndata=%u confidence=%.3f ampl=%.3f bps=%.2f",
|
||||
nframes_decoded,
|
||||
confidence_total / nframes_decoded,
|
||||
amplitude_total / nframes_decoded,
|
||||
throughput_rate);
|
||||
(double)(confidence_total / nframes_decoded),
|
||||
(double)(amplitude_total / nframes_decoded),
|
||||
(double)(throughput_rate));
|
||||
#if 0
|
||||
fprintf(stderr, " bits*sr=%llu rate*nsamp=%llu",
|
||||
(unsigned long long)(nbits_decoded * sample_rate + 0.5),
|
||||
(unsigned long long)(bfsk_data_rate * carrier_nsamples) );
|
||||
#endif
|
||||
if ( (unsigned long long)(nbits_decoded * sample_rate + 0.5) == (unsigned long long)(bfsk_data_rate * carrier_nsamples) ) {
|
||||
if ( (unsigned long long)(nbits_decoded * sample_rate + 0.5f) == (unsigned long long)(bfsk_data_rate * carrier_nsamples) ) {
|
||||
fprintf(stderr, " (rate perfect) ###\n");
|
||||
} else {
|
||||
float throughput_skew = (throughput_rate - bfsk_data_rate)
|
||||
/ bfsk_data_rate;
|
||||
fprintf(stderr, " (%.1f%% %s) ###\n",
|
||||
fabs(throughput_skew) * 100.0,
|
||||
(double)(fabsf(throughput_skew) * 100.0f),
|
||||
signbit(throughput_skew) ? "slow" : "fast"
|
||||
);
|
||||
}
|
||||
@ -444,7 +444,7 @@ build_expect_bits_string( char *expect_bits_string,
|
||||
char start_bit_value = invert_start_stop ? '1' : '0';
|
||||
char stop_bit_value = invert_start_stop ? '0' : '1';
|
||||
int j = 0;
|
||||
if ( bfsk_nstopbits != 0.0 )
|
||||
if ( bfsk_nstopbits != 0.0f )
|
||||
expect_bits_string[j++] = stop_bit_value;
|
||||
int i;
|
||||
// Nb. only integer number of start bits works (for rx)
|
||||
@ -456,7 +456,7 @@ build_expect_bits_string( char *expect_bits_string,
|
||||
else
|
||||
expect_bits_string[j] = 'd';
|
||||
}
|
||||
if ( bfsk_nstopbits != 0.0 )
|
||||
if ( bfsk_nstopbits != 0.0f )
|
||||
expect_bits_string[j++] = stop_bit_value;
|
||||
expect_bits_string[j] = 0;
|
||||
|
||||
@ -660,7 +660,7 @@ main( int argc, char*argv[] )
|
||||
tx_amplitude = FLT_EPSILON;
|
||||
else
|
||||
tx_amplitude = atof(optarg);
|
||||
assert( tx_amplitude > 0.0 );
|
||||
assert( tx_amplitude > 0.0f );
|
||||
break;
|
||||
case 'M':
|
||||
bfsk_mark_f = atof(optarg);
|
||||
@ -798,7 +798,7 @@ main( int argc, char*argv[] )
|
||||
fprintf(stderr, "E: callerid --tx mode is not supported.\n");
|
||||
return 1;
|
||||
}
|
||||
if ( carrier_autodetect_threshold > 0.0 )
|
||||
if ( carrier_autodetect_threshold > 0.0f )
|
||||
fprintf(stderr, "W: callerid with --auto-carrier is not recommended.\n");
|
||||
bfsk_databits_decode = databits_decode_callerid;
|
||||
bfsk_data_rate = 1200;
|
||||
@ -826,7 +826,7 @@ main( int argc, char*argv[] )
|
||||
if ( bfsk_n_data_bits == 0 )
|
||||
bfsk_n_data_bits = 8;
|
||||
}
|
||||
if ( bfsk_data_rate == 0.0 )
|
||||
if ( bfsk_data_rate == 0.0f )
|
||||
usage();
|
||||
|
||||
|
||||
@ -964,7 +964,7 @@ main( int argc, char*argv[] )
|
||||
|
||||
sample_rate = simpleaudio_get_rate(sa);
|
||||
|
||||
if ( rxnoise_factor != 0.0 )
|
||||
if ( rxnoise_factor != 0.0f )
|
||||
simpleaudio_set_rxnoise(sa, rxnoise_factor);
|
||||
|
||||
/*
|
||||
@ -1035,19 +1035,19 @@ main( int argc, char*argv[] )
|
||||
// for encodings without start/stop bits:
|
||||
// MUST be <= 0.5 or we may accidentally skip a bit
|
||||
//
|
||||
assert( fsk_frame_overscan >= 0.0 && fsk_frame_overscan < 1.0 );
|
||||
assert( fsk_frame_overscan >= 0.0f && fsk_frame_overscan < 1.0f );
|
||||
|
||||
// ensure that we overscan at least a single sample
|
||||
unsigned int nsamples_overscan
|
||||
= nsamples_per_bit * fsk_frame_overscan + 0.5;
|
||||
if ( fsk_frame_overscan > 0.0 && nsamples_overscan == 0 )
|
||||
= nsamples_per_bit * fsk_frame_overscan + 0.5f;
|
||||
if ( fsk_frame_overscan > 0.0f && nsamples_overscan == 0 )
|
||||
nsamples_overscan = 1;
|
||||
debug_log("fsk_frame_overscan=%f nsamples_overscan=%u\n",
|
||||
fsk_frame_overscan, nsamples_overscan);
|
||||
|
||||
// n databits plus bfsk_startbit start bits plus bfsk_nstopbit stop bits:
|
||||
float frame_n_bits = bfsk_n_data_bits + bfsk_nstartbits + bfsk_nstopbits;
|
||||
unsigned int frame_nsamples = nsamples_per_bit * frame_n_bits + 0.5;
|
||||
unsigned int frame_nsamples = nsamples_per_bit * frame_n_bits + 0.5f;
|
||||
|
||||
char expect_data_string_buffer[64];
|
||||
if (expect_data_string == NULL) {
|
||||
@ -1115,7 +1115,7 @@ main( int argc, char*argv[] )
|
||||
|
||||
/* Auto-detect carrier frequency */
|
||||
static int carrier_band = -1;
|
||||
if ( carrier_autodetect_threshold > 0.0 && carrier_band < 0 ) {
|
||||
if ( carrier_autodetect_threshold > 0.0f && carrier_band < 0 ) {
|
||||
unsigned int i;
|
||||
float nsamples_per_scan = nsamples_per_bit;
|
||||
if ( nsamples_per_scan > fskp->fftsize )
|
||||
@ -1137,7 +1137,7 @@ main( int argc, char*argv[] )
|
||||
}
|
||||
|
||||
// default negative shift -- reasonable?
|
||||
int b_shift = - (float)(autodetect_shift + fskp->band_width/2.0)
|
||||
int b_shift = - (float)(autodetect_shift + fskp->band_width/2.0f)
|
||||
/ fskp->band_width;
|
||||
if ( bfsk_inverted_freqs )
|
||||
b_shift *= -1;
|
||||
@ -1172,7 +1172,7 @@ main( int argc, char*argv[] )
|
||||
// 2. allows us to track slightly slow signals
|
||||
unsigned int try_max_nsamples;
|
||||
if ( carrier )
|
||||
try_max_nsamples = nsamples_per_bit * 0.75 + 0.5;
|
||||
try_max_nsamples = nsamples_per_bit * 0.75f + 0.5f;
|
||||
else
|
||||
try_max_nsamples = nsamples_per_bit;
|
||||
try_max_nsamples += nsamples_overscan;
|
||||
@ -1212,7 +1212,7 @@ main( int argc, char*argv[] )
|
||||
|
||||
int do_refine_frame = 0;
|
||||
|
||||
if ( confidence < peak_confidence * 0.75 ) {
|
||||
if ( confidence < peak_confidence * 0.75f ) {
|
||||
do_refine_frame = 1;
|
||||
debug_log(" ... do_refine_frame rescan (confidence %.3f << %.3f peak)\n", confidence, peak_confidence);
|
||||
peak_confidence = 0;
|
||||
@ -1220,7 +1220,7 @@ main( int argc, char*argv[] )
|
||||
|
||||
// no-confidence if amplitude drops abruptly to < 25% of the
|
||||
// track_amplitude, which follows amplitude with hysteresis
|
||||
if ( amplitude < track_amplitude * 0.25 ) {
|
||||
if ( amplitude < track_amplitude * 0.25f ) {
|
||||
confidence = 0;
|
||||
}
|
||||
|
||||
@ -1273,12 +1273,12 @@ main( int argc, char*argv[] )
|
||||
if ( !quiet_mode ) {
|
||||
if ( bfsk_data_rate >= 100 )
|
||||
fprintf(stderr, "### CARRIER %u @ %.1f Hz ",
|
||||
(unsigned int)(bfsk_data_rate + 0.5),
|
||||
fskp->b_mark * fskp->band_width);
|
||||
(unsigned int)(bfsk_data_rate + 0.5f),
|
||||
(double)(fskp->b_mark * fskp->band_width));
|
||||
else
|
||||
fprintf(stderr, "### CARRIER %.2f @ %.1f Hz ",
|
||||
bfsk_data_rate,
|
||||
fskp->b_mark * fskp->band_width);
|
||||
(double)(bfsk_data_rate),
|
||||
(double)(fskp->b_mark * fskp->band_width));
|
||||
}
|
||||
|
||||
if ( !quiet_mode )
|
||||
@ -1349,7 +1349,7 @@ main( int argc, char*argv[] )
|
||||
frame_start_sample, advance);
|
||||
|
||||
// chop off the prev_stop bit
|
||||
if ( bfsk_nstopbits != 0.0 )
|
||||
if ( bfsk_nstopbits != 0.0f )
|
||||
bits = bits >> 1;
|
||||
|
||||
|
||||
|
@ -49,15 +49,15 @@ simpleaudio_tone_init( unsigned int new_sin_table_len, float mag )
|
||||
}
|
||||
|
||||
unsigned int i;
|
||||
unsigned short mag_s = 32767.0 * tone_mag + 0.5f;
|
||||
unsigned short mag_s = 32767.0f * tone_mag + 0.5f;
|
||||
if ( tone_mag > 1.0f ) // clamp to 1.0 to avoid overflow
|
||||
mag_s = 32767;
|
||||
if ( mag_s < 1 ) // "short epsilon"
|
||||
mag_s = 1;
|
||||
for ( i=0; i<sin_table_len; i++ )
|
||||
sin_table_short[i] = lroundf( mag_s * sin(M_PI*2.0*(float)i/sin_table_len) );
|
||||
sin_table_short[i] = lroundf( mag_s * sinf((float)M_PI*2*i/sin_table_len) );
|
||||
for ( i=0; i<sin_table_len; i++ )
|
||||
sin_table_float[i] = tone_mag * sinf(M_PI*2.0*(float)i/sin_table_len);
|
||||
sin_table_float[i] = tone_mag * sinf((float)M_PI*2*i/sin_table_len);
|
||||
|
||||
} else {
|
||||
if ( sin_table_short ) {
|
||||
@ -116,7 +116,7 @@ simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
||||
float wave_nsamples = simpleaudio_get_rate(sa_out) / tone_freq;
|
||||
size_t i;
|
||||
|
||||
#define TURNS_TO_RADIANS(t) ( M_PI*2.0 * (t) )
|
||||
#define TURNS_TO_RADIANS(t) ( (float)M_PI*2 * (t) )
|
||||
|
||||
#define SINE_PHASE_TURNS ( (float)i/wave_nsamples + sa_tone_cphase )
|
||||
#define SINE_PHASE_RADIANS TURNS_TO_RADIANS(SINE_PHASE_TURNS)
|
||||
@ -143,7 +143,7 @@ simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
||||
for ( i=0; i<nsamples_dur; i++ )
|
||||
short_buf[i] = sin_lu_short(SINE_PHASE_TURNS);
|
||||
} else {
|
||||
unsigned short mag_s = 32767.0 * tone_mag + 0.5f;
|
||||
unsigned short mag_s = 32767.0f * tone_mag + 0.5f;
|
||||
if ( tone_mag > 1.0f ) // clamp to 1.0 to avoid overflow
|
||||
mag_s = 32767;
|
||||
if ( mag_s < 1 ) // "short epsilon"
|
||||
|
@ -61,12 +61,12 @@ sa_sndfile_read( simpleaudio *sa, void *buf, size_t nframes )
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( sa->rxnoise != 0.0 ) {
|
||||
if ( sa->rxnoise != 0.0f ) {
|
||||
int i;
|
||||
float *fbuf = buf;
|
||||
float f = sa->rxnoise * 2;
|
||||
for ( i=0; i<nframes; i++ )
|
||||
fbuf[i] += (drand48() - 0.5) * f;
|
||||
fbuf[i] += (rand()/RAND_MAX - 0.5f) * f;
|
||||
}
|
||||
|
||||
// fprintf(stderr, "sf_read: nframes=%ld n=%d\n", nframes, n);
|
||||
|
Loading…
x
Reference in New Issue
Block a user