|
libnrsc5 bd41663
NRSC-5 digital radio via the RTL-SDR
|
#include <stdint.h>#include <stdlib.h>#include <stdio.h>#include <time.h>Go to the source code of this file.
Data Structures | |
| struct | nrsc5_sig_component_t |
| struct | nrsc5_sig_service_t |
| struct | nrsc5_sis_asd_t |
| struct | nrsc5_sis_dsd_t |
| struct | nrsc5_id3_comment_t |
| struct | nrsc5_event_t |
Macros | |
| #define | NRSC5_SCAN_BEGIN 87.9e6 |
| #define | NRSC5_SCAN_END 107.9e6 |
| #define | NRSC5_SCAN_SKIP 0.2e6 |
| #define | NRSC5_MIME_PRIMARY_IMAGE 0xBE4B7536 |
| #define | NRSC5_MIME_STATION_LOGO 0xD9C72536 |
| #define | NRSC5_MIME_NAVTEQ 0x2D42AC3E |
| #define | NRSC5_MIME_HERE_TPEG 0x82F03DFC |
| #define | NRSC5_MIME_HERE_IMAGE 0xB7F03DFC |
| #define | NRSC5_MIME_HD_TMC 0xEECB55B6 |
| #define | NRSC5_MIME_HDC 0x4DC66C5A |
| #define | NRSC5_MIME_TEXT 0xBB492AAC |
| #define | NRSC5_MIME_JPEG 0x1E653E9C |
| #define | NRSC5_MIME_PNG 0x4F328CA0 |
| #define | NRSC5_MIME_TTN_TPEG_1 0xB39EBEB2 |
| #define | NRSC5_MIME_TTN_TPEG_2 0x4EB03469 |
| #define | NRSC5_MIME_TTN_TPEG_3 0x52103469 |
| #define | NRSC5_MIME_TTN_STM_TRAFFIC 0xFF8422D7 |
| #define | NRSC5_MIME_TTN_STM_WEATHER 0xEF042E96 |
| #define | NRSC5_MIME_UNKNOWN_00000000 0x00000000 |
| #define | NRSC5_MIME_UNKNOWN_B81FFAA8 0xB81FFAA8 |
| #define | NRSC5_MIME_UNKNOWN_FFFFFFFF 0xFFFFFFFF |
| #define | NRSC5_AUDIO_FRAME_SAMPLES 2048 |
| #define | NRSC5_SAMPLE_RATE_CU8 1488375 |
| #define | NRSC5_SAMPLE_RATE_CS16_FM 744187.5 |
| #define | NRSC5_SAMPLE_RATE_CS16_AM 46511.71875 |
| #define | NRSC5_SAMPLE_RATE_AUDIO 44100 |
| #define | NRSC5_API |
Typedefs | |
| typedef struct nrsc5_sig_component_t | nrsc5_sig_component_t |
| typedef struct nrsc5_sig_service_t | nrsc5_sig_service_t |
| typedef struct nrsc5_sis_asd_t | nrsc5_sis_asd_t |
| typedef struct nrsc5_sis_dsd_t | nrsc5_sis_dsd_t |
| typedef struct nrsc5_id3_comment_t | nrsc5_id3_comment_t |
| typedef struct nrsc5_event_t | nrsc5_event_t |
| typedef void(* | nrsc5_callback_t) (const nrsc5_event_t *evt, void *opaque) |
| typedef struct nrsc5_t | nrsc5_t |
Functions | |
| NRSC5_API void | nrsc5_get_version (const char **version) |
| NRSC5_API void | nrsc5_service_data_type_name (unsigned int type, const char **name) |
| NRSC5_API void | nrsc5_program_type_name (unsigned int type, const char **name) |
| NRSC5_API void | nrsc5_alert_category_name (unsigned int category, const char **name) |
| NRSC5_API int | nrsc5_open (nrsc5_t **st, int device_index) |
| NRSC5_API int | nrsc5_open_file (nrsc5_t **st, FILE *fp) |
| NRSC5_API int | nrsc5_open_pipe (nrsc5_t **st) |
| NRSC5_API int | nrsc5_open_rtltcp (nrsc5_t **st, int socket) |
| NRSC5_API void | nrsc5_close (nrsc5_t *st) |
| NRSC5_API void | nrsc5_start (nrsc5_t *st) |
| NRSC5_API void | nrsc5_stop (nrsc5_t *st) |
| NRSC5_API int | nrsc5_set_mode (nrsc5_t *st, int mode) |
| NRSC5_API int | nrsc5_set_bias_tee (nrsc5_t *st, int on) |
| NRSC5_API int | nrsc5_set_direct_sampling (nrsc5_t *st, int on) |
| NRSC5_API int | nrsc5_set_freq_correction (nrsc5_t *st, int ppm_error) |
| NRSC5_API void | nrsc5_get_frequency (nrsc5_t *st, float *freq) |
| NRSC5_API int | nrsc5_set_frequency (nrsc5_t *st, float freq) |
| NRSC5_API void | nrsc5_get_gain (nrsc5_t *st, float *gain) |
| NRSC5_API int | nrsc5_set_gain (nrsc5_t *st, float gain) |
| NRSC5_API void | nrsc5_set_auto_gain (nrsc5_t *st, int enabled) |
| NRSC5_API void | nrsc5_set_callback (nrsc5_t *st, nrsc5_callback_t callback, void *opaque) |
| NRSC5_API int | nrsc5_pipe_samples_cu8 (nrsc5_t *st, const uint8_t *samples, unsigned int length) |
| NRSC5_API int | nrsc5_pipe_samples_cs16 (nrsc5_t *st, const int16_t *samples, unsigned int length) |
External API for the nrsc5 library.
| #define NRSC5_AUDIO_FRAME_SAMPLES 2048 |
Number of audio samples per HDC frame
| #define NRSC5_MIME_HDC 0x4DC66C5A |
MIME type for HD Codec audio
| #define NRSC5_MIME_JPEG 0x1E653E9C |
MIME type for JPEG image
| #define NRSC5_MIME_PNG 0x4F328CA0 |
MIME type for PNG image
| #define NRSC5_MIME_PRIMARY_IMAGE 0xBE4B7536 |
MIME type for album art
| #define NRSC5_MIME_STATION_LOGO 0xD9C72536 |
MIME type for station logo
| #define NRSC5_MIME_TEXT 0xBB492AAC |
MIME type for text file
| #define NRSC5_SAMPLE_RATE_AUDIO 44100 |
Sample rate of outgoing audio
| #define NRSC5_SAMPLE_RATE_CS16_AM 46511.71875 |
Sample rate at which nrsc5_pipe_samples_cs16() expects samples (AM only)
| #define NRSC5_SAMPLE_RATE_CS16_FM 744187.5 |
Sample rate at which nrsc5_pipe_samples_cs16() expects samples (FM only)
| #define NRSC5_SAMPLE_RATE_CU8 1488375 |
Sample rate at which nrsc5_pipe_samples_cu8() expects samples (FM or AM)
| typedef void(* nrsc5_callback_t) (const nrsc5_event_t *evt, void *opaque) |
Prototype for a user event handling callback function. The function will be invoked with a pointer to the nrsc5_event_t and a pointer to a second contextual argument, established by nrsc5_set_callback().
| typedef struct nrsc5_event_t nrsc5_event_t |
Defines a typename for struct nrsc5_event_t
| typedef struct nrsc5_id3_comment_t nrsc5_id3_comment_t |
Defines a typename for struct nrsc5_id3_comment_t
| typedef struct nrsc5_sig_component_t nrsc5_sig_component_t |
Defines a typename for struct nrsc5_sig_component_t
| typedef struct nrsc5_sig_service_t nrsc5_sig_service_t |
Defines a typename for struct nrsc5_sig_service_t
| typedef struct nrsc5_sis_asd_t nrsc5_sis_asd_t |
Defines a typename for struct nrsc5_sis_asd_t
| typedef struct nrsc5_sis_dsd_t nrsc5_sis_dsd_t |
Defines a typename for struct nrsc5_sis_dsd_t
An opaque data type used by API functions to represent session information. Applications should acquire a pointer to one via the open_ functions: nrsc5_open(), nrsc5_open_file(), nrsc5_open_pipe(), or nrsc5_open_rtltcp().
| NRSC5_API void nrsc5_alert_category_name | ( | unsigned int | category, |
| const char ** | name | ||
| ) |
Retrieves a string corresponding to an alert category.
| [in] | type | an alert category integer. |
| [out] | name | character pointer to a string naming the alert category |
This name will be quite short, e.g. "Weather" or "Safety". If the type is not recognized, it will be the string "Unknown".
| NRSC5_API void nrsc5_close | ( | nrsc5_t * | st | ) |
Closes an nrsc5 session.
| [in] | st | pointer to an nrsc5_t |
Any worker thread is signalled to exit, files and sockets are closed, and I/O buffers are freed.
| NRSC5_API void nrsc5_get_frequency | ( | nrsc5_t * | st, |
| float * | freq | ||
| ) |
Retrieve the frequency to which the device is currently tuned if initialized to a local dongle, otherwise the cached frequency.
| [in] | st | pointer to an nrsc5_t session object |
| [out] | freq | frequency in Hz |
| NRSC5_API void nrsc5_get_gain | ( | nrsc5_t * | st, |
| float * | gain | ||
| ) |
Retrieve the actual receiver gain.
| [in] | st | pointer to an nrsc5_t session object |
| [out] | gain | in dB |
| NRSC5_API void nrsc5_get_version | ( | const char ** | version | ) |
Retrieves the version string of the library.
| [out] | version | character pointer that will reference the version string. |
| NRSC5_API int nrsc5_open | ( | nrsc5_t ** | st, |
| int | device_index | ||
| ) |
Initializes a session for a particular RTLSDR radio dongle.
| [out] | st | handle for an nrsc5_t |
| [in] | device_index | the RTLSDR device index |
The device_index is commonly 0 on systems with a single radio dongle. This, or another open_ command should be issued before using the other API functions that need an nrsc5_t session handle. This function will allocate and initialize an opaque nsrc5_t struct and set the pointer result to it on success. It uses librtlsdr to:
device_indexOther session options are initialized to defaults, e.g. mode to FM. It creates (but does not start) a worker thread.
| NRSC5_API int nrsc5_open_file | ( | nrsc5_t ** | st, |
| FILE * | fp | ||
| ) |
Initializes a session given an open FILE pointer.
| [out] | st | handle for an nrsc5_t |
| [in] | fp | FILE pointer handle with nrsc5 data |
| NRSC5_API int nrsc5_open_pipe | ( | nrsc5_t ** | st | ) |
Initializes a session for use with a pipe.
| [out] | st | handle for an nrsc5_t |
| NRSC5_API int nrsc5_open_rtltcp | ( | nrsc5_t ** | st, |
| int | socket | ||
| ) |
Initializes a session given a TCP socket file descriptor.
| [out] | st | handle for an nrsc5_t |
| [in] | socket | the TCP socket with nrsc5 data |
| NRSC5_API int nrsc5_pipe_samples_cs16 | ( | nrsc5_t * | st, |
| const int16_t * | samples, | ||
| unsigned int | length | ||
| ) |
Push an IQ input array of 16-bit signed samples into the demodulator.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | samples | pointer to an array 16-bit signed samples |
| [in] | length | the number of samples in the array |
| NRSC5_API int nrsc5_pipe_samples_cu8 | ( | nrsc5_t * | st, |
| const uint8_t * | samples, | ||
| unsigned int | length | ||
| ) |
Push an IQ array of 8-bit unsigned samples into the demodulator.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | samples | pointer to an array 8-bit unsigned samples |
| [in] | length | the number of samples in the array |
| NRSC5_API void nrsc5_program_type_name | ( | unsigned int | type, |
| const char ** | name | ||
| ) |
Retrieves a string corresponding to a program type.
| [in] | type | a program data type integer. |
| [out] | name | character pointer to a string naming the service type |
This name will be quite short, e.g. "News" or "Rock". If the type is not recognized, it will be the string "Unknown".
| NRSC5_API void nrsc5_service_data_type_name | ( | unsigned int | type, |
| const char ** | name | ||
| ) |
Retrieves a string corresponding to a service data type.
| [in] | type | a service data type integer. |
| [out] | name | character pointer to a string naming the service type |
This name will be quite short, e.g. "News" or "Weather". If the type is not recognized, it will be the string "Unknown".
| NRSC5_API void nrsc5_set_auto_gain | ( | nrsc5_t * | st, |
| int | enabled | ||
| ) |
Enable or disable receiver auto-gain control.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | enabled | set to 1 to enable auto gain, 0 to disable |
| NRSC5_API int nrsc5_set_bias_tee | ( | nrsc5_t * | st, |
| int | on | ||
| ) |
Enable or disable the bias-T for the radio.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | on | 1 indicates enabled, and 0 indicates disabled |
This works with both a local SDR and over a TCP connection. A Bias-T is often used to power a low noise amplifier by injecting DC on the antenna cable. Do not enable this unless you know you have an LNA and compatible antenna.
| NRSC5_API void nrsc5_set_callback | ( | nrsc5_t * | st, |
| nrsc5_callback_t | callback, | ||
| void * | opaque | ||
| ) |
Establish a callback function.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | callback | pointer to an event handling function of two arguments |
| [in] | opaque | pointer to the function's intended 2nd argument |
| NRSC5_API int nrsc5_set_direct_sampling | ( | nrsc5_t * | st, |
| int | on | ||
| ) |
Enable or disable direct sampling.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | on | 1 indicates enabled, and 0 indicates disabled |
This works with both a local SDR and over a TCP connection.
| NRSC5_API int nrsc5_set_freq_correction | ( | nrsc5_t * | st, |
| int | ppm_error | ||
| ) |
Adjust the radio frequency correction.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | ppm_error | correction offset in parts-per-million |
This works with both a local SDR and over a TCP connection.
| NRSC5_API int nrsc5_set_frequency | ( | nrsc5_t * | st, |
| float | freq | ||
| ) |
Sets the frequency to which the receiver is tuned.
| [in] | st | pointer to an nrsc5_t session object |
| [out] | freq | frequency in Hz |
This function may only be called when the device is stopped. Input, output are reset. Gain is reset if auto-gain is enabled. Works with both a local SDR and over a TCP connection.
| NRSC5_API int nrsc5_set_gain | ( | nrsc5_t * | st, |
| float | gain | ||
| ) |
Set the receiver gain.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | gain | in dB |
| NRSC5_API int nrsc5_set_mode | ( | nrsc5_t * | st, |
| int | mode | ||
| ) |
Set the session mode to AM or FM.
| [in] | st | pointer to an nrsc5_t session object |
| [in] | mode | either NRSC5_MODE_FM or NRSC5_MODE_AM |
| NRSC5_API void nrsc5_start | ( | nrsc5_t * | st | ) |
Signals the worker to start demodulation.
| [in] | st | pointer to an nrsc5_t session object |
| NRSC5_API void nrsc5_stop | ( | nrsc5_t * | st | ) |
Signals the worker to stop demodulation.
| [in] | st | pointer to an nrsc5_t session object |
This function will block until the worker is stopped.