Skip to content

Commit

Permalink
r82xx: set_dithering()
Browse files Browse the repository at this point in the history
  • Loading branch information
keenerd committed Aug 3, 2014
1 parent 3dfa4ad commit 3f2632d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
11 changes: 11 additions & 0 deletions include/rtl-sdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ RTLSDR_API int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on);
*/
RTLSDR_API int rtlsdr_get_offset_tuning(rtlsdr_dev_t *dev);

/*!
* Enable or disable frequency dithering for r820t tuners.
* Must be performed before freq_set().
* Fails for other tuners.
*
* \param dev the device handle given by rtlsdr_open()
* \param on 0 means disabled, 1 enabled
* \return 0 on success
*/
RTLSDR_API int rtlsdr_set_dithering(rtlsdr_dev_t *dev, int dither);

/* streaming functions */

RTLSDR_API int rtlsdr_reset_buffer(rtlsdr_dev_t *dev);
Expand Down
2 changes: 2 additions & 0 deletions include/tuner_r82xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct r82xx_priv {
uint8_t input;
int has_lock;
int init_done;
int disable_dither;

/* Store current mode */
uint32_t delsys;
Expand Down Expand Up @@ -116,5 +117,6 @@ int r82xx_init(struct r82xx_priv *priv);
int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq);
int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain);
int r82xx_set_nomod(struct r82xx_priv *priv);
int r82xx_set_dither(struct r82xx_priv *priv, int dither);

#endif
8 changes: 8 additions & 0 deletions src/librtlsdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,14 @@ int rtlsdr_get_offset_tuning(rtlsdr_dev_t *dev)
return (dev->offs_freq) ? 1 : 0;
}

int rtlsdr_set_dithering(rtlsdr_dev_t *dev, int dither)
{
if (dev->tuner_type == RTLSDR_TUNER_R820T) {
return r82xx_set_dither(&dev->r82xx_p, dither);
}
return 1;
}

static rtlsdr_dongle_t *find_known_device(uint16_t vid, uint16_t pid)
{
unsigned int i;
Expand Down
17 changes: 16 additions & 1 deletion src/rtl_sdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void usage(void)
"\t[-n number of samples to read (default: 0, infinite)]\n"
"\t[-S force sync output (default: async)]\n"
"\t[-D direct_sampling_mode, 0 (default/off), 1 (I), 2 (Q), 3 (no-mod)]\n"
"\t[-N no dithering (default: use dithering)]\n"
"\tfilename (a '-' dumps samples to stdout)\n\n");
exit(1);
}
Expand Down Expand Up @@ -115,6 +116,7 @@ int main(int argc, char **argv)
int ppm_error = 0;
int sync_mode = 0;
int direct_sampling = 0;
int dithering = 1;
FILE *file;
uint8_t *buffer;
int dev_index = 0;
Expand All @@ -123,7 +125,7 @@ int main(int argc, char **argv)
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
uint32_t out_block_size = DEFAULT_BUF_LENGTH;

while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:D:S")) != -1) {
while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:D:SN")) != -1) {
switch (opt) {
case 'd':
dev_index = verbose_device_search(optarg);
Expand Down Expand Up @@ -153,6 +155,9 @@ int main(int argc, char **argv)
case 'D':
direct_sampling = atoi(optarg);
break;
case 'N':
dithering = 0;
break;
default:
usage();
break;
Expand Down Expand Up @@ -203,6 +208,16 @@ int main(int argc, char **argv)
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );
#endif

if (!dithering) {
fprintf(stderr, "Disabling dithering... ");
r = rtlsdr_set_dithering(dev, dithering);
if (r) {
fprintf(stderr, "failure\n");
} else {
fprintf(stderr, "success\n");
}
}

if (direct_sampling) {
verbose_direct_sampling(dev, direct_sampling);
}
Expand Down
11 changes: 9 additions & 2 deletions src/tuner_r82xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,10 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
else
val = 0x00;

rc = r82xx_write_reg_mask(priv, 0x12, val, 0x08);
if (priv->disable_dither)
val |= 0x10;

rc = r82xx_write_reg_mask(priv, 0x12, val, 0x18);
if (rc < 0)
return rc;

Expand Down Expand Up @@ -1142,7 +1145,11 @@ int r82xx_set_nomod(struct r82xx_priv *priv)
return rc;
}


int r82xx_set_dither(struct r82xx_priv *priv, int dither)
{
priv->disable_dither = !dither;
return 0;
}

/*
* r82xx standby logic
Expand Down

0 comments on commit 3f2632d

Please sign in to comment.