libnrsc5 28520e0
NRSC-5 digital radio via the RTL-SDR
Loading...
Searching...
No Matches
nrsc5.h
Go to the documentation of this file.
1#ifndef NRSC5_H_
2#define NRSC5_H_
3
19#include <stdint.h>
20#include <stdlib.h>
21#include <stdio.h>
22#include <time.h>
23
24/*
25 * Definitions.
26 */
27#define NRSC5_SCAN_BEGIN 87.9e6
28#define NRSC5_SCAN_END 107.9e6
29#define NRSC5_SCAN_SKIP 0.2e6
30
31#define NRSC5_MIME_PRIMARY_IMAGE 0xBE4B7536
32#define NRSC5_MIME_STATION_LOGO 0xD9C72536
33#define NRSC5_MIME_NAVTEQ 0x2D42AC3E
34#define NRSC5_MIME_HERE_TPEG 0x82F03DFC
35#define NRSC5_MIME_HERE_IMAGE 0xB7F03DFC
36#define NRSC5_MIME_HD_TMC 0xEECB55B6
37#define NRSC5_MIME_HDC 0x4DC66C5A
38#define NRSC5_MIME_TEXT 0xBB492AAC
39#define NRSC5_MIME_JPEG 0x1E653E9C
40#define NRSC5_MIME_PNG 0x4F328CA0
41#define NRSC5_MIME_TTN_TPEG_1 0xB39EBEB2
42#define NRSC5_MIME_TTN_TPEG_2 0x4EB03469
43#define NRSC5_MIME_TTN_TPEG_3 0x52103469
44#define NRSC5_MIME_TTN_STM_TRAFFIC 0xFF8422D7
45#define NRSC5_MIME_TTN_STM_WEATHER 0xEF042E96
46#define NRSC5_MIME_UNKNOWN_00000000 0x00000000
47#define NRSC5_MIME_UNKNOWN_B81FFAA8 0xB81FFAA8
48#define NRSC5_MIME_UNKNOWN_FFFFFFFF 0xFFFFFFFF
49
50#define NRSC5_AUDIO_FRAME_SAMPLES 2048
52#define NRSC5_SAMPLE_RATE_CU8 1488375
53#define NRSC5_SAMPLE_RATE_CS16_FM 744187.5
54#define NRSC5_SAMPLE_RATE_CS16_AM 46511.71875
55#define NRSC5_SAMPLE_RATE_AUDIO 44100
57#ifdef NRSC5_EXPORTS
58#ifdef __MINGW32__
59#define NRSC5_API __declspec(dllexport)
60#else
61#define NRSC5_API
62#endif
63#else
64#define NRSC5_API
65#endif
66
67enum
68{
69 NRSC5_MODE_FM,
70 NRSC5_MODE_AM
71};
72
73/*
74 * Data types.
75 */
76enum
77{
78 NRSC5_SIG_COMPONENT_AUDIO,
79 NRSC5_SIG_COMPONENT_DATA
80};
81
82enum
83{
84 NRSC5_AAS_TYPE_STREAM = 0,
85 NRSC5_AAS_TYPE_PACKET = 1,
86 NRSC5_AAS_TYPE_LOT = 3
87};
88
96{
98 uint8_t type;
99 uint8_t id;
100 union
101 {
104 struct {
105 uint16_t port;
108 uint8_t type;
109 uint32_t mime;
113 struct {
114 uint8_t port;
115 uint8_t type;
116 uint32_t mime;
118 };
119};
124
125enum
126{
127 NRSC5_SIG_SERVICE_AUDIO,
128 NRSC5_SIG_SERVICE_DATA
129};
130
158
159enum
160{
161 NRSC5_EVENT_LOST_DEVICE,
162 NRSC5_EVENT_IQ,
163 NRSC5_EVENT_SYNC,
164 NRSC5_EVENT_LOST_SYNC,
165 NRSC5_EVENT_MER,
166 NRSC5_EVENT_BER,
167 NRSC5_EVENT_HDC,
168 NRSC5_EVENT_AUDIO,
169 NRSC5_EVENT_ID3,
170 NRSC5_EVENT_SIG,
171 NRSC5_EVENT_LOT,
172 NRSC5_EVENT_SIS,
173 NRSC5_EVENT_STREAM,
174 NRSC5_EVENT_PACKET,
175 NRSC5_EVENT_AUDIO_SERVICE,
176 NRSC5_EVENT_STATION_ID,
177 NRSC5_EVENT_STATION_NAME,
178 NRSC5_EVENT_STATION_SLOGAN,
179 NRSC5_EVENT_STATION_MESSAGE,
180 NRSC5_EVENT_STATION_LOCATION,
181 NRSC5_EVENT_AUDIO_SERVICE_DESCRIPTOR,
182 NRSC5_EVENT_DATA_SERVICE_DESCRIPTOR,
183 NRSC5_EVENT_EMERGENCY_ALERT,
184 NRSC5_EVENT_HERE_IMAGE,
185 NRSC5_EVENT_LOT_HEADER,
186 NRSC5_EVENT_LOT_FRAGMENT,
187 NRSC5_EVENT_AGC
188};
189
190enum
191{
192 NRSC5_ACCESS_PUBLIC,
193 NRSC5_ACCESS_RESTRICTED
194};
195
196enum
197{
198 NRSC5_PROGRAM_TYPE_UNDEFINED = 0,
199 NRSC5_PROGRAM_TYPE_NEWS = 1,
200 NRSC5_PROGRAM_TYPE_INFORMATION = 2,
201 NRSC5_PROGRAM_TYPE_SPORTS = 3,
202 NRSC5_PROGRAM_TYPE_TALK = 4,
203 NRSC5_PROGRAM_TYPE_ROCK = 5,
204 NRSC5_PROGRAM_TYPE_CLASSIC_ROCK = 6,
205 NRSC5_PROGRAM_TYPE_ADULT_HITS = 7,
206 NRSC5_PROGRAM_TYPE_SOFT_ROCK = 8,
207 NRSC5_PROGRAM_TYPE_TOP_40 = 9,
208 NRSC5_PROGRAM_TYPE_COUNTRY = 10,
209 NRSC5_PROGRAM_TYPE_OLDIES = 11,
210 NRSC5_PROGRAM_TYPE_SOFT = 12,
211 NRSC5_PROGRAM_TYPE_NOSTALGIA = 13,
212 NRSC5_PROGRAM_TYPE_JAZZ = 14,
213 NRSC5_PROGRAM_TYPE_CLASSICAL = 15,
214 NRSC5_PROGRAM_TYPE_RHYTHM_AND_BLUES = 16,
215 NRSC5_PROGRAM_TYPE_SOFT_RHYTHM_AND_BLUES = 17,
216 NRSC5_PROGRAM_TYPE_FOREIGN_LANGUAGE = 18,
217 NRSC5_PROGRAM_TYPE_RELIGIOUS_MUSIC = 19,
218 NRSC5_PROGRAM_TYPE_RELIGIOUS_TALK = 20,
219 NRSC5_PROGRAM_TYPE_PERSONALITY = 21,
220 NRSC5_PROGRAM_TYPE_PUBLIC = 22,
221 NRSC5_PROGRAM_TYPE_COLLEGE = 23,
222 NRSC5_PROGRAM_TYPE_SPANISH_TALK = 24,
223 NRSC5_PROGRAM_TYPE_SPANISH_MUSIC = 25,
224 NRSC5_PROGRAM_TYPE_HIP_HOP = 26,
225 NRSC5_PROGRAM_TYPE_WEATHER = 29,
226 NRSC5_PROGRAM_TYPE_EMERGENCY_TEST = 30,
227 NRSC5_PROGRAM_TYPE_EMERGENCY = 31,
228 NRSC5_PROGRAM_TYPE_TRAFFIC = 65,
229 NRSC5_PROGRAM_TYPE_SPECIAL_READING_SERVICES = 76
230};
231
232enum
233{
234 NRSC5_BLEND_DISABLE,
235 NRSC5_BLEND_SELECT,
236 NRSC5_BLEND_ENABLE
237};
238
239enum
240{
241 NRSC5_LOCATION_FORMAT_SAME,
242 NRSC5_LOCATION_FORMAT_FIPS,
243 NRSC5_LOCATION_FORMAT_ZIP
244};
245
246enum
247{
248 NRSC5_ALERT_CATEGORY_NON_SPECIFIC = 1,
249 NRSC5_ALERT_CATEGORY_GEOPHYSICAL = 2,
250 NRSC5_ALERT_CATEGORY_WEATHER = 3,
251 NRSC5_ALERT_CATEGORY_SAFETY = 4,
252 NRSC5_ALERT_CATEGORY_SECURITY = 5,
253 NRSC5_ALERT_CATEGORY_RESCUE = 6,
254 NRSC5_ALERT_CATEGORY_FIRE = 7,
255 NRSC5_ALERT_CATEGORY_HEALTH = 8,
256 NRSC5_ALERT_CATEGORY_ENVIRONMENTAL = 9,
257 NRSC5_ALERT_CATEGORY_TRANSPORTATION = 10,
258 NRSC5_ALERT_CATEGORY_UTILITIES = 11,
259 NRSC5_ALERT_CATEGORY_HAZMAT = 12,
260 NRSC5_ALERT_CATEGORY_TEST = 30
261};
262
263enum
264{
265 NRSC5_HERE_IMAGE_TRAFFIC = 8,
266 NRSC5_HERE_IMAGE_WEATHER = 13
267};
268
280{
282 unsigned int program;
283 unsigned int access;
284 unsigned int type;
285 unsigned int sound_exp;
286};
291
292enum
293{
294 NRSC5_SERVICE_DATA_TYPE_NON_SPECIFIC = 0,
295 NRSC5_SERVICE_DATA_TYPE_NEWS = 1,
296 NRSC5_SERVICE_DATA_TYPE_SPORTS = 3,
297 NRSC5_SERVICE_DATA_TYPE_WEATHER = 29,
298 NRSC5_SERVICE_DATA_TYPE_EMERGENCY = 31,
299 NRSC5_SERVICE_DATA_TYPE_TRAFFIC = 65,
300 NRSC5_SERVICE_DATA_TYPE_IMAGE_MAPS = 66,
301 NRSC5_SERVICE_DATA_TYPE_TEXT = 80,
302 NRSC5_SERVICE_DATA_TYPE_ADVERTISING = 256,
303 NRSC5_SERVICE_DATA_TYPE_FINANCIAL = 257,
304 NRSC5_SERVICE_DATA_TYPE_STOCK_TICKER = 258,
305 NRSC5_SERVICE_DATA_TYPE_NAVIGATION = 259,
306 NRSC5_SERVICE_DATA_TYPE_ELECTRONIC_PROGRAM_GUIDE = 260,
307 NRSC5_SERVICE_DATA_TYPE_AUDIO = 261,
308 NRSC5_SERVICE_DATA_TYPE_PRIVATE_DATA_NETWORK = 262,
309 NRSC5_SERVICE_DATA_TYPE_SERVICE_MAINTENANCE = 263,
310 NRSC5_SERVICE_DATA_TYPE_HD_RADIO_SYSTEM_SERVICES = 264,
311 NRSC5_SERVICE_DATA_TYPE_AUDIO_RELATED_DATA = 265,
312 NRSC5_SERVICE_DATA_TYPE_RESERVED_FOR_SPECIAL_TESTS = 511
313};
314
323{
325 unsigned int access;
326 unsigned int type;
327 uint32_t mime_type;
328};
333
349
357{
388 unsigned int event;
389 union
390 {
391 struct {
392 const void *data;
393 size_t count;
394 } iq;
395 struct {
397 int psmi;
398 } sync;
399 struct {
400 float cber;
401 } ber;
402 struct {
403 float lower;
404 float upper;
405 } mer;
406 struct {
407 unsigned int program;
408 const uint8_t *data;
409 size_t count;
410 } hdc;
411 struct {
412 unsigned int program;
413 const int16_t *data;
414 size_t count;
415 } audio;
416 struct {
417 unsigned int program;
418 const char *title;
419 const char *artist;
420 const char *album;
421 const char *genre;
422 struct {
423 const char *owner;
424 const char *id;
425 } ufid;
426 struct {
427 uint32_t mime;
428 int param;
429 int lot;
430 } xhdr;
431 nrsc5_id3_comment_t *comments;
432 } id3;
433 struct {
434 uint16_t port;
435 uint16_t seq;
436 unsigned int size;
437 uint32_t mime;
438 const uint8_t *data;
441 } stream;
442 struct {
443 uint16_t port;
444 uint16_t seq;
445 unsigned int size;
446 uint32_t mime;
447 const uint8_t *data;
450 } packet;
451 struct {
452 uint16_t port;
453 unsigned int lot;
454 unsigned int size;
455 uint32_t mime;
456 const char *name;
457 const uint8_t *data;
458 struct tm *expiry_utc;
461 } lot;
462 struct {
463 unsigned int lot;
464 unsigned int seq;
465 unsigned int repeat;
466 unsigned int size;
467 unsigned int bytes_so_far;
469 const uint8_t *data;
470 nrsc5_sig_service_t *service;
471 nrsc5_sig_component_t *component;
472 } lot_fragment;
473 struct {
474 unsigned int program;
475 unsigned int access;
476 unsigned int type;
477 unsigned int codec_mode;
478 unsigned int blend_control;
480 unsigned int common_delay;
481 unsigned int latency;
482 } audio_service;
483 struct {
484 nrsc5_sig_service_t *services;
485 } sig;
486 struct {
487 const char *country_code;
488 int fcc_facility_id;
489 const char *name;
490 const char *slogan;
491 const char *message;
492 const char *alert;
493 float latitude;
494 float longitude;
495 int altitude;
496 nrsc5_sis_asd_t *audio_services;
497 nrsc5_sis_dsd_t *data_services;
498 const uint8_t *alert_cnt;
499 int alert_cnt_length;
500 int alert_category1;
501 int alert_category2;
502 int alert_location_format;
503 int alert_num_locations;
504 const int *alert_locations;
505 } sis;
506 struct {
507 const char *country_code;
508 int fcc_facility_id;
509 } station_id;
510 struct {
511 const char *name;
512 } station_name;
513 struct {
514 const char *slogan;
515 } station_slogan;
516 struct {
517 const char *message;
518 } station_message;
519 struct {
520 float latitude;
521 float longitude;
522 int altitude;
523 } station_location;
524 struct {
525 unsigned int program;
526 unsigned int access;
527 unsigned int type;
528 unsigned int sound_exp;
529 } asd;
530 struct {
531 unsigned int access;
532 unsigned int type;
533 uint32_t mime_type;
534 } dsd;
535 struct {
536 const char *message;
537 const uint8_t *control_data;
538 int control_data_length;
539 int category1;
540 int category2;
541 int location_format;
542 int num_locations;
543 const int *locations;
544 } emergency_alert;
545 struct {
547 int seq;
548 int n1;
549 int n2;
550 struct tm *time_utc;
551 float latitude1;
553 float latitude2;
555 const char *name;
556 unsigned int size;
557 const uint8_t *data;
558 } here_image;
559 struct {
560 float gain_db;
561 float peak_dbfs;
563 } agc;
564 };
565};
570
577typedef void (*nrsc5_callback_t)(const nrsc5_event_t *evt, void *opaque);
578
584typedef struct nrsc5_t nrsc5_t;
585
586
587/* ============================================================================
588 * Public functions. All functions return void or an error code (0 == success).
589 */
590
595NRSC5_API void nrsc5_get_version(const char **version);
596
605NRSC5_API void nrsc5_service_data_type_name(unsigned int type, const char **name);
606
615NRSC5_API void nrsc5_program_type_name(unsigned int type, const char **name);
616
625 NRSC5_API void nrsc5_alert_category_name(unsigned int category, const char **name);
626
647NRSC5_API int nrsc5_open(nrsc5_t **st, int device_index);
648
656NRSC5_API int nrsc5_open_file(nrsc5_t **st, FILE *fp);
657
664NRSC5_API int nrsc5_open_pipe(nrsc5_t **st);
665
673NRSC5_API int nrsc5_open_rtltcp(nrsc5_t **st, int socket);
674
682NRSC5_API void nrsc5_close(nrsc5_t *st);
683
689NRSC5_API void nrsc5_start(nrsc5_t *st);
690
697NRSC5_API void nrsc5_stop(nrsc5_t *st);
698
706NRSC5_API int nrsc5_set_mode(nrsc5_t *st, int mode);
707
719NRSC5_API int nrsc5_set_bias_tee(nrsc5_t *st, int on);
720
729NRSC5_API int nrsc5_set_direct_sampling(nrsc5_t *st, int on);
730
739NRSC5_API int nrsc5_set_freq_correction(nrsc5_t *st, int ppm_error);
740
748NRSC5_API void nrsc5_get_frequency(nrsc5_t *st, float *freq);
749
761NRSC5_API int nrsc5_set_frequency(nrsc5_t *st, float freq);
762
770NRSC5_API void nrsc5_get_gain(nrsc5_t *st, float *gain);
771
780NRSC5_API int nrsc5_set_gain(nrsc5_t *st, float gain);
781
789NRSC5_API void nrsc5_set_auto_gain(nrsc5_t *st, int enabled);
790
799NRSC5_API void nrsc5_set_callback(nrsc5_t *st, nrsc5_callback_t callback, void *opaque);
800
811NRSC5_API int nrsc5_pipe_samples_cu8(nrsc5_t *st, const uint8_t *samples, unsigned int length);
812
823NRSC5_API int nrsc5_pipe_samples_cs16(nrsc5_t *st, const int16_t *samples, unsigned int length);
824
825#endif /* NRSC5_H_ */
NRSC5_API int nrsc5_open_rtltcp(nrsc5_t **st, int socket)
NRSC5_API int nrsc5_set_frequency(nrsc5_t *st, float freq)
NRSC5_API int nrsc5_set_mode(nrsc5_t *st, int mode)
struct nrsc5_t nrsc5_t
Definition nrsc5.h:584
NRSC5_API int nrsc5_set_freq_correction(nrsc5_t *st, int ppm_error)
NRSC5_API int nrsc5_pipe_samples_cu8(nrsc5_t *st, const uint8_t *samples, unsigned int length)
NRSC5_API int nrsc5_open_pipe(nrsc5_t **st)
NRSC5_API int nrsc5_pipe_samples_cs16(nrsc5_t *st, const int16_t *samples, unsigned int length)
NRSC5_API void nrsc5_alert_category_name(unsigned int category, const char **name)
NRSC5_API void nrsc5_get_version(const char **version)
NRSC5_API void nrsc5_program_type_name(unsigned int type, const char **name)
NRSC5_API void nrsc5_service_data_type_name(unsigned int type, const char **name)
NRSC5_API void nrsc5_close(nrsc5_t *st)
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 int nrsc5_set_bias_tee(nrsc5_t *st, int on)
NRSC5_API void nrsc5_stop(nrsc5_t *st)
NRSC5_API int nrsc5_open(nrsc5_t **st, int device_index)
NRSC5_API void nrsc5_get_frequency(nrsc5_t *st, float *freq)
NRSC5_API int nrsc5_open_file(nrsc5_t **st, FILE *fp)
NRSC5_API void nrsc5_start(nrsc5_t *st)
void(* nrsc5_callback_t)(const nrsc5_event_t *evt, void *opaque)
Definition nrsc5.h:577
NRSC5_API void nrsc5_get_gain(nrsc5_t *st, float *gain)
NRSC5_API int nrsc5_set_direct_sampling(nrsc5_t *st, int on)
NRSC5_API void nrsc5_set_callback(nrsc5_t *st, nrsc5_callback_t callback, void *opaque)
Definition nrsc5.h:357
unsigned int blend_control
Definition nrsc5.h:478
int is_final
Definition nrsc5.h:562
unsigned int bytes_so_far
Definition nrsc5.h:467
float latitude2
Definition nrsc5.h:553
float latitude1
Definition nrsc5.h:551
unsigned int type
Definition nrsc5.h:476
int digital_audio_gain
Definition nrsc5.h:479
const char * name
Definition nrsc5.h:456
unsigned int codec_mode
Definition nrsc5.h:477
unsigned int lot
Definition nrsc5.h:453
struct tm * expiry_utc
Definition nrsc5.h:458
float gain_db
Definition nrsc5.h:560
unsigned int sound_exp
Definition nrsc5.h:528
unsigned int latency
Definition nrsc5.h:481
int n1
Definition nrsc5.h:548
float longitude2
Definition nrsc5.h:554
unsigned int size
Definition nrsc5.h:436
float freq_offset
Definition nrsc5.h:396
unsigned int event
Definition nrsc5.h:388
unsigned int seq
Definition nrsc5.h:464
int image_type
Definition nrsc5.h:546
uint16_t port
Definition nrsc5.h:434
unsigned int repeat
Definition nrsc5.h:465
uint32_t mime_type
Definition nrsc5.h:533
nrsc5_sig_service_t * service
Definition nrsc5.h:439
struct tm * time_utc
Definition nrsc5.h:550
int psmi
Definition nrsc5.h:397
int seq
Definition nrsc5.h:547
float peak_dbfs
Definition nrsc5.h:561
unsigned int access
Definition nrsc5.h:475
int is_duplicate
Definition nrsc5.h:468
int n2
Definition nrsc5.h:549
const uint8_t * data
Definition nrsc5.h:408
uint32_t mime
Definition nrsc5.h:427
unsigned int common_delay
Definition nrsc5.h:480
float longitude1
Definition nrsc5.h:552
unsigned int program
Definition nrsc5.h:407
nrsc5_sig_component_t * component
Definition nrsc5.h:440
Definition nrsc5.h:339
struct nrsc5_id3_comment_t * next
Definition nrsc5.h:340
char * full_text
Definition nrsc5.h:343
char * lang
Definition nrsc5.h:341
char * short_content_desc
Definition nrsc5.h:342
Definition nrsc5.h:96
struct nrsc5_sig_component_t::@12::@14 data
uint32_t mime
Definition nrsc5.h:109
uint16_t service_data_type
Definition nrsc5.h:107
uint8_t type
Definition nrsc5.h:98
uint8_t id
Definition nrsc5.h:99
struct nrsc5_sig_component_t * next
Definition nrsc5.h:97
struct nrsc5_sig_component_t::@12::@15 audio
uint16_t port
Definition nrsc5.h:105
uint8_t port
Definition nrsc5.h:114
Definition nrsc5.h:146
nrsc5_sig_component_t * audio_component
Definition nrsc5.h:152
nrsc5_sig_component_t * components
Definition nrsc5.h:151
struct nrsc5_sig_service_t * next
Definition nrsc5.h:147
uint8_t type
Definition nrsc5.h:148
uint16_t number
Definition nrsc5.h:149
const char * name
Definition nrsc5.h:150
Definition nrsc5.h:280
unsigned int program
Definition nrsc5.h:282
unsigned int sound_exp
Definition nrsc5.h:285
struct nrsc5_sis_asd_t * next
Definition nrsc5.h:281
unsigned int access
Definition nrsc5.h:283
unsigned int type
Definition nrsc5.h:284
Definition nrsc5.h:323
struct nrsc5_sis_dsd_t * next
Definition nrsc5.h:324
unsigned int type
Definition nrsc5.h:326
uint32_t mime_type
Definition nrsc5.h:327
unsigned int access
Definition nrsc5.h:325