rtl_sdr, rtl_tcp: cleaned up gain handling

This commit is contained in:
Dimitri Stolnikov 2012-05-07 22:59:34 +02:00
parent b290116ac7
commit e042c36cb5
2 changed files with 18 additions and 13 deletions

View File

@ -52,7 +52,7 @@ void usage(void)
"Usage:\t -f frequency_to_tune_to [Hz]\n"
"\t[-s samplerate (default: 2048000 Hz)]\n"
"\t[-d device_index (default: 0)]\n"
"\t[-g tuner_gain (default: 0 dB)]\n"
"\t[-g tuner_gain (default: -1dB)]\n"
"\t[-b output_block_size (default: 16 * 16384)]\n"
"\t[-S force sync output (default: async)]\n"
"\tfilename (a '-' dumps samples to stdout)\n\n");
@ -99,12 +99,12 @@ int main(int argc, char **argv)
char *filename = NULL;
int n_read;
int r, opt;
int i, gain = 0;
int i, gain = -10; // tenths of a dB
int sync_mode = 0;
FILE *file;
uint8_t *buffer;
uint32_t dev_index = 0;
uint32_t frequency = 0;
uint32_t frequency = 100000000;
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
int device_count;
@ -118,7 +118,7 @@ int main(int argc, char **argv)
frequency = (uint32_t)atof(optarg);
break;
case 'g':
gain = (int)atof(optarg) * 10;
gain = (int)(atof(optarg) * 10);
break;
case 's':
samp_rate = (uint32_t)atof(optarg);
@ -145,7 +145,7 @@ int main(int argc, char **argv)
usage();
dev_index = atoi(argv[1]);
samp_rate = atoi(argv[2])*1000;
gain=(int)atof(argv[3]) * 10;
gain=(int)(atof(argv[3]) * 10);
frequency = atoi(argv[4]);
filename = argv[5];
#endif
@ -210,7 +210,7 @@ int main(int argc, char **argv)
if (r < 0)
fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
else
fprintf(stderr, "Tuner gain set to %i dB.\n", gain);
fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0);
if(strcmp(filename, "-") == 0) { /* Write samples to stdout */
file = stdout;

View File

@ -82,9 +82,10 @@ void usage(void)
"[samplerate in kHz] [frequency in Hz] [device index]\n");
#else
printf("rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n"
"Usage:\t -a listen address\n"
"\t[-p listen port (default: 1234)\n"
"\t -f frequency to tune to [Hz]\n"
"Usage:\t[-a listen address]\n"
"\t[-p listen port (default: 1234)]\n"
"\t[-f frequency to tune to [Hz]]\n"
"\t[-g tuner_gain (default: -1dB)]\n"
"\t[-s samplerate in Hz (default: 2048000 Hz)]\n"
"\t[-d device index (default: 0)]\n");
#endif
@ -307,10 +308,11 @@ int main(int argc, char **argv)
int r, opt, i;
char* addr = "127.0.0.1";
int port = 1234;
uint32_t frequency = 0, samp_rate = 2048000;
uint32_t frequency = 100000000, samp_rate = 2048000;
struct sockaddr_in local, remote;
int device_count;
uint32_t dev_index = 0, gain = -10;
uint32_t dev_index = 0;
int gain = -10; // tenths of a dB
struct llist *curelem,*prev;
pthread_attr_t attr;
void *status;
@ -325,7 +327,7 @@ int main(int argc, char **argv)
#endif
#ifndef _WIN32
struct sigaction sigact;
while ((opt = getopt(argc, argv, "a:p:f:s:d:")) != -1) {
while ((opt = getopt(argc, argv, "a:p:f:g:s:d:")) != -1) {
switch (opt) {
case 'd':
dev_index = atoi(optarg);
@ -333,6 +335,9 @@ int main(int argc, char **argv)
case 'f':
frequency = (uint32_t)atof(optarg);
break;
case 'g':
gain = (int)(atof(optarg) * 10);
break;
case 's':
samp_rate = (uint32_t)atof(optarg);
break;
@ -403,7 +408,7 @@ int main(int argc, char **argv)
if (r < 0)
fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
else
fprintf(stderr, "Tuner gain set to %i dB.\n", gain);
fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0);
/* Reset endpoint before we start reading from it (mandatory) */
r = rtlsdr_reset_buffer(dev);