Skip to content

Commit

Permalink
Fixed samplerate by value for the -a switch in airspy_rx
Browse files Browse the repository at this point in the history
  • Loading branch information
touil committed Apr 23, 2016
1 parent 0764074 commit 1efcd9a
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions airspy-tools/src/airspy_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ int gettimeofday(struct timeval *tv, void* ignored)
#define SENSITIVITY_GAIN_MAX (21)
#define SAMPLES_TO_XFER_MAX_U64 (0x8000000000000000ull) /* Max value */

#define MIN_SAMPLERATE_BY_VALUE (1000000)

/* WAVE or RIFF WAVE file format containing data for AirSpy compatible with SDR# Wav IQ file */
typedef struct
{
Expand Down Expand Up @@ -877,26 +879,39 @@ int main(int argc, char** argv)

airspy_get_samplerates(device, &count, 0);

if (sample_rate_val < 0)
{
printf("argument error: sample rate out of range\n");
airspy_close(device);
airspy_exit();
return EXIT_FAILURE;
}

supported_samplerates = (uint32_t *) malloc(count * sizeof(uint32_t));
airspy_get_samplerates(device, supported_samplerates, count);

if(sample_rate_val < count)
if (sample_rate_val <= MIN_SAMPLERATE_BY_VALUE)
{
wav_sample_per_sec = supported_samplerates[sample_rate_val];
}else
if (sample_rate_val < count)
{
wav_sample_per_sec = supported_samplerates[sample_rate_val];
}
else
{
free(supported_samplerates);
printf("argument error: unsupported sample rate\n");
airspy_close(device);
airspy_exit();
return EXIT_FAILURE;
}
}
else
{
wav_sample_per_sec = sample_rate_val * (1000 / 2);
wav_sample_per_sec = sample_rate_val;
}

free(supported_samplerates);

result = airspy_set_samplerate(device, sample_rate_val);
if (result != AIRSPY_SUCCESS) {
printf("airspy_set_samplerate() failed: %s (%d)\n", airspy_error_name(result), result);
airspy_close(device);
airspy_exit();
return EXIT_FAILURE;
}

if (verbose)
{
printf("sample_rate -a %d (%f MSPS %s)\n", sample_rate_val, wav_sample_per_sec * 0.000001f, wav_nb_channels == 1 ? "Real" : "IQ");
Expand Down Expand Up @@ -925,14 +940,6 @@ int main(int argc, char** argv)
}
}

result = airspy_set_samplerate(device, sample_rate_val);
if( result != AIRSPY_SUCCESS ) {
printf("airspy_set_samplerate() failed: %s (%d)\n", airspy_error_name(result), result);
airspy_close(device);
airspy_exit();
return EXIT_FAILURE;
}

result = airspy_set_rf_bias(device, biast_val);
if( result != AIRSPY_SUCCESS ) {
printf("airspy_set_rf_bias() failed: %s (%d)\n", airspy_error_name(result), result);
Expand Down

0 comments on commit 1efcd9a

Please sign in to comment.