Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documents improvements #347

Merged
merged 10 commits into from
Jul 20, 2024
6 changes: 6 additions & 0 deletions include/nrsc5.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#define NRSC5_MIME_TTN_STM_TRAFFIC 0xFF8422D7
#define NRSC5_MIME_TTN_STM_WEATHER 0xEF042E96

#define NRSC5_SAMPLE_RATE_CU8 1488375
#define NRSC5_SAMPLE_RATE_CS16 744187.5
#define NRSC5_SAMPLE_RATE_AUDIO 44100

enum
{
NRSC5_MODE_FM,
Expand Down Expand Up @@ -593,6 +597,7 @@ void nrsc5_set_callback(nrsc5_t *st, nrsc5_callback_t callback, void *opaque);
* @param[in] st pointer to an `nrsc5_t` session object
* @param[in] samples pointer to an array 8-bit unsigned samples
* @param[in] length the number of samples in the array
* @see NRSC5_SAMPLE_RATE_CU8 for required sample rate
* @return 0 on success, nonzero on error
*
*/
Expand All @@ -605,6 +610,7 @@ int nrsc5_pipe_samples_cu8(nrsc5_t *st, const uint8_t *samples, unsigned int len
* @param[in] st pointer to an `nrsc5_t` session object
* @param[in] samples pointer to an array 16-bit signed samples
* @param[in] length the number of samples in the array
* @see NRSC5_SAMPLE_RATE_CS16 for required sample rate
* @return 0 on success, nonzero on error
*
*/
Expand Down
2 changes: 1 addition & 1 deletion src/acquire.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void acquire_cfo_adjust(acquire_t *st, int cfo)
return;

st->cfo += cfo;
hz = (float) st->cfo * SAMPLE_RATE / st->fft;
hz = (float) st->cfo * NRSC5_SAMPLE_RATE_CU8 / st->fft;
hz /= (st->mode == NRSC5_MODE_FM ? DECIMATION_FACTOR_FM : DECIMATION_FACTOR_AM);

log_info("CFO: %f Hz", hz);
Expand Down
2 changes: 0 additions & 2 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <complex.h>
#include <math.h>

// Sample rate before decimation
#define SAMPLE_RATE 1488375
// FFT length in samples
#define FFT_FM 2048
#define FFT_AM 256
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef struct {

static ao_sample_format sample_format = {
16,
44100,
NRSC5_SAMPLE_RATE_AUDIO,
2,
AO_FMT_NATIVE,
"L,R"
Expand Down Expand Up @@ -308,7 +308,7 @@ static void callback(const nrsc5_event_t *evt, void *opaque)
st->audio_packets++;
st->audio_bytes += evt->hdc.count * sizeof(evt->hdc.data[0]);
if (st->audio_packets >= 32) {
log_info("Audio bit rate: %.1f kbps", (float)st->audio_bytes * 8 * 44100 / 2048 / st->audio_packets / 1000);
log_info("Audio bit rate: %.1f kbps", (float)st->audio_bytes * 8 * NRSC5_SAMPLE_RATE_AUDIO / 2048 / st->audio_packets / 1000);
st->audio_packets = 0;
st->audio_bytes = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/nrsc5.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int do_auto_gain(nrsc5_t *st)
{
// there is no good way to wait for samples after the new gain was applied
// dump 250ms of samples and hope for the best
rtltcp_reset_buffer(st->rtltcp, (SAMPLE_RATE / 4) * 2);
rtltcp_reset_buffer(st->rtltcp, (NRSC5_SAMPLE_RATE_CU8 / 4) * 2);
}

st->auto_gain_snr_ready = 0;
Expand Down Expand Up @@ -309,7 +309,7 @@ NRSC5_API int nrsc5_open(nrsc5_t **result, int device_index)
if (rtlsdr_open(&st->dev, device_index) != 0)
goto error_init;

err = rtlsdr_set_sample_rate(st->dev, SAMPLE_RATE);
err = rtlsdr_set_sample_rate(st->dev, NRSC5_SAMPLE_RATE_CU8);
if (err) goto error;
err = rtlsdr_set_tuner_gain_mode(st->dev, 1);
if (err) goto error;
Expand Down Expand Up @@ -358,7 +358,7 @@ NRSC5_API int nrsc5_open_rtltcp(nrsc5_t **result, int socket)
if (st->rtltcp == NULL)
goto error;

err = rtltcp_set_sample_rate(st->rtltcp, SAMPLE_RATE);
err = rtltcp_set_sample_rate(st->rtltcp, NRSC5_SAMPLE_RATE_CU8);
if (err) goto error;
err = rtltcp_set_tuner_gain_mode(st->rtltcp, 1);
if (err) goto error;
Expand Down
4 changes: 2 additions & 2 deletions support/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def run(self):
self.wav_output = wave.open(self.args.o, "wb")
self.wav_output.setnchannels(2)
self.wav_output.setsampwidth(2)
self.wav_output.setframerate(44100)
self.wav_output.setframerate(nrsc5.SAMPLE_RATE_AUDIO)
else:
audio_thread = threading.Thread(target=self.audio_worker)
audio_thread.start()
Expand Down Expand Up @@ -145,7 +145,7 @@ def audio_worker(self):
index = audio.get_default_output_device_info()["index"]
stream = audio.open(format=pyaudio.paInt16,
channels=2,
rate=44100,
rate=nrsc5.SAMPLE_RATE_AUDIO,
output_device_index=index,
output=True)
except OSError:
Expand Down
5 changes: 5 additions & 0 deletions support/nrsc5.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class EventType(enum.Enum):
PACKET = 13


SAMPLE_RATE_CU8 = 1488375
SAMPLE_RATE_CS16 = 744187.5
SAMPLE_RATE_AUDIO = 44100


class ServiceType(enum.Enum):
AUDIO = 0
DATA = 1
Expand Down
Loading