mirror of
https://github.com/rtlsdrblog/rtl-sdr-blog.git
synced 2024-12-27 19:38:27 +01:00
add commandline option for setting the sample rate
Signed-off-by: Steve Markgraf <steve@steve-m.de>
This commit is contained in:
parent
5a4fd14581
commit
8dc13ea3ea
34
src/main.c
34
src/main.c
@ -21,6 +21,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
@ -40,6 +41,8 @@
|
|||||||
#define NOXON_VID 0x0ccd
|
#define NOXON_VID 0x0ccd
|
||||||
#define NOXON_PID 0x00b3
|
#define NOXON_PID 0x00b3
|
||||||
|
|
||||||
|
#define CRYSTAL_FREQ 28800000
|
||||||
|
|
||||||
static struct libusb_device_handle *devh = NULL;
|
static struct libusb_device_handle *devh = NULL;
|
||||||
static int do_exit = 0;
|
static int do_exit = 0;
|
||||||
|
|
||||||
@ -214,12 +217,20 @@ void demod_write_reg(uint8_t page, uint16_t addr, uint16_t val, uint8_t len)
|
|||||||
demod_read_reg(0x0a, 0x01, 1);
|
demod_read_reg(0x0a, 0x01, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_resampler(uint32_t rsamp_ratio)
|
void set_samp_rate(uint32_t samp_rate)
|
||||||
{
|
{
|
||||||
uint16_t tmp;
|
uint16_t tmp;
|
||||||
rsamp_ratio <<= 2;
|
uint32_t rsamp_ratio;
|
||||||
|
|
||||||
tmp = (rsamp_ratio >> 16) & 0xffff;
|
/* check for the maximum rate the resampler supports */
|
||||||
|
if (samp_rate > 3200000)
|
||||||
|
samp_rate = 3200000;
|
||||||
|
|
||||||
|
printf("Setting sample rate: %i Hz\n", samp_rate);
|
||||||
|
rsamp_ratio = (CRYSTAL_FREQ * pow(2, 22)) / samp_rate;
|
||||||
|
|
||||||
|
rsamp_ratio &= ~3;
|
||||||
|
tmp = (rsamp_ratio >> 16);
|
||||||
demod_write_reg(1, 0x9f, tmp, 2);
|
demod_write_reg(1, 0x9f, tmp, 2);
|
||||||
tmp = rsamp_ratio & 0xffff;
|
tmp = rsamp_ratio & 0xffff;
|
||||||
demod_write_reg(1, 0xa1, tmp, 2);
|
demod_write_reg(1, 0xa1, tmp, 2);
|
||||||
@ -265,10 +276,6 @@ void rtl_init(void)
|
|||||||
for (i = 0; i < sizeof (fir_coeff); i++)
|
for (i = 0; i < sizeof (fir_coeff); i++)
|
||||||
demod_write_reg(1, 0x1c + i, fir_coeff[i], 1);
|
demod_write_reg(1, 0x1c + i, fir_coeff[i], 1);
|
||||||
|
|
||||||
/* TODO setting resampler test value, max value is 0xC99999,
|
|
||||||
* value for DAB/FM is 0xE10000*/
|
|
||||||
set_resampler(1 << 24);
|
|
||||||
|
|
||||||
demod_write_reg(0, 0x19, 0x25, 1);
|
demod_write_reg(0, 0x19, 0x25, 1);
|
||||||
|
|
||||||
/* init FSM state-holding register */
|
/* init FSM state-holding register */
|
||||||
@ -295,7 +302,7 @@ void tuner_init(int frequency)
|
|||||||
switch (tuner_type) {
|
switch (tuner_type) {
|
||||||
case TUNER_E4000:
|
case TUNER_E4000:
|
||||||
e4000_Initialize(1);
|
e4000_Initialize(1);
|
||||||
e4000_SetBandwidthHz(1, 80000);
|
e4000_SetBandwidthHz(1, 8000000);
|
||||||
e4000_SetRfFreqHz(1, frequency);
|
e4000_SetRfFreqHz(1, frequency);
|
||||||
break;
|
break;
|
||||||
case TUNER_FC0013:
|
case TUNER_FC0013:
|
||||||
@ -314,7 +321,8 @@ void tuner_init(int frequency)
|
|||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
printf("rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n"
|
printf("rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n"
|
||||||
"Usage:\t-f frequency to tune to [Hz]\n"
|
"Usage:\t -f frequency to tune to [Hz]\n"
|
||||||
|
"\t[-s samplerate (default: 2048000 Hz)]\n"
|
||||||
"\toutput filename\n");
|
"\toutput filename\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -329,16 +337,19 @@ int main(int argc, char **argv)
|
|||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
int r, opt;
|
int r, opt;
|
||||||
char *filename;
|
char *filename;
|
||||||
unsigned int frequency = 0;
|
uint32_t frequency = 0, samp_rate = 2048000;
|
||||||
uint8_t buffer[READLEN];
|
uint8_t buffer[READLEN];
|
||||||
int n_read;
|
int n_read;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "f:")) != -1) {
|
while ((opt = getopt(argc, argv, "f:s:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'f':
|
case 'f':
|
||||||
frequency = atoi(optarg);
|
frequency = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
samp_rate = atoi(optarg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
@ -378,6 +389,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Initialize the RTL2832 */
|
/* Initialize the RTL2832 */
|
||||||
rtl_init();
|
rtl_init();
|
||||||
|
set_samp_rate(samp_rate);
|
||||||
|
|
||||||
/* Initialize tuner & set frequency */
|
/* Initialize tuner & set frequency */
|
||||||
tuner_init(frequency);
|
tuner_init(frequency);
|
||||||
|
Loading…
Reference in New Issue
Block a user