libsstvenc
Asynchronous Analogue SSTV encoder
Loading...
Searching...
No Matches
Time-scale calculation routines
Collaboration diagram for Time-scale calculation routines:

Topics

 Time-scale units
 

Macros

#define SSTVENC_TS_INFINITE   UINT32_MAX
 

Functions

uint64_t sstvenc_ts_unit_scale (uint8_t unit)
 
uint32_t sstvenc_ts_clamp_samples (uint64_t samples)
 
uint32_t sstvenc_ts_unit_to_samples (double time, uint32_t sample_rate, uint8_t unit)
 
double sstvenc_ts_samples_to_unit (uint32_t samples, uint32_t sample_rate, uint8_t unit)
 

Detailed Description

Conversion between discrete samples and real-time. SSTV timings are given in real-world seconds (actually, nanoseconds) as time units but we need to know what that is in the number of discrete samples. There is rounding applied to handle fractional samples.

Time periods down to nanosecond precision may be specified.

Conversion between discrete samples and real-time. SSTV timings are given in real-world seconds (actually, nanoseconds) as time units but we need to know what that is in the number of discrete samples. There is rounding applied to handle fractional samples.

Time periods down to nanosecond precision may be specified.

Macro Definition Documentation

◆ SSTVENC_TS_INFINITE

#define SSTVENC_TS_INFINITE   UINT32_MAX

Infinite time scale. We set this to the maximum number of samples, which at 48kHz sample rates, equates to about a day.

Definition at line 28 of file timescale.h.

Referenced by sstvenc_ts_clamp_samples(), sstvenc_ts_samples_to_unit(), and sstvenc_ts_unit_to_samples().

Function Documentation

◆ sstvenc_ts_clamp_samples()

uint32_t sstvenc_ts_clamp_samples ( uint64_t samples)

Clamp the given number of samples to a safe maximum. If the value is greater than that supported by a uint32_t data type, it is clamped to SSTVENC_TS_INFINITE.

Parameters
[in]samplesUnclamped number of samples.
Returns
Clamped number of samples.

Definition at line 38 of file timescale.c.

38 {
39 if (samples > UINT32_MAX) {
41 } else {
42 return samples;
43 }
44}
#define SSTVENC_TS_INFINITE
Definition timescale.h:28

References SSTVENC_TS_INFINITE.

Referenced by sstvenc_ts_unit_to_samples().

Here is the caller graph for this function:

◆ sstvenc_ts_samples_to_unit()

double sstvenc_ts_samples_to_unit ( uint32_t samples,
uint32_t sample_rate,
uint8_t unit )

Convert the given number of samples to a time period in the specified unit.

Parameters
[in]samplesThe number of samples being measured.
[in]sample_rateThe sample rate in hertz being used for the discrete timebase.
[in]unitThe time unit desired, see Time-scale units
Returns
The time period represented by the given number of samples in the given time unit.
Return values
INFINITYInfinite number of samples is represented.

Definition at line 57 of file timescale.c.

58 {
59 if (samples == SSTVENC_TS_INFINITE) {
60 return INFINITY;
61 } else {
62 uint64_t n = samples * sstvenc_ts_unit_scale(unit);
63 return ((double)n) / ((double)sample_rate);
64 }
65}
uint64_t sstvenc_ts_unit_scale(uint8_t unit)
Definition timescale.c:22

References SSTVENC_TS_INFINITE, and sstvenc_ts_unit_scale().

Here is the call graph for this function:

◆ sstvenc_ts_unit_scale()

uint64_t sstvenc_ts_unit_scale ( uint8_t unit)

Obtain the scaling factor to convert 1 second of time to the given unit.

Parameters
[in]unitThe time scale of interest. Time-scale units
Returns
The number of specified time units in one second.

Definition at line 22 of file timescale.c.

22 {
23 switch (unit) {
25 return 1;
27 return 1000;
29 return 1000000;
31 return 1000000000;
32 default:
33 /* Not supported */
34 assert(0);
35 }
36}
#define SSTVENC_TS_UNIT_SECONDS
Definition timescale.h:36
#define SSTVENC_TS_UNIT_MICROSECONDS
Definition timescale.h:38
#define SSTVENC_TS_UNIT_MILLISECONDS
Definition timescale.h:37
#define SSTVENC_TS_UNIT_NANOSECONDS
Definition timescale.h:39

References SSTVENC_TS_UNIT_MICROSECONDS, SSTVENC_TS_UNIT_MILLISECONDS, SSTVENC_TS_UNIT_NANOSECONDS, and SSTVENC_TS_UNIT_SECONDS.

Referenced by sstvenc_sequencer_exec_set_ts(), sstvenc_ts_samples_to_unit(), and sstvenc_ts_unit_to_samples().

Here is the caller graph for this function:

◆ sstvenc_ts_unit_to_samples()

uint32_t sstvenc_ts_unit_to_samples ( double time,
uint32_t sample_rate,
uint8_t unit )

Convert the given time period to the number of units.

Parameters
[in]timeThe number of time units being converted.
[in]sample_rateThe sample rate in hertz being used for the discrete timebase.
[in]unitThe time unit being measured, see Time-scale units
Returns
The number of samples needed for that time period.
Return values
SSTVENC_TS_INFINITETime period is too long to represent.

Definition at line 46 of file timescale.c.

47 {
48 if (time == INFINITY) {
50 } else {
52 ((uint64_t)((time * sample_rate) + 0.5))
53 / sstvenc_ts_unit_scale(unit));
54 }
55}
uint32_t sstvenc_ts_clamp_samples(uint64_t samples)
Definition timescale.c:38

References sstvenc_ts_clamp_samples(), SSTVENC_TS_INFINITE, and sstvenc_ts_unit_scale().

Referenced by sstvenc_cw_init(), sstvenc_modulator_next_tone(), sstvenc_ps_init(), sstvenc_ps_reset(), and sstvenc_sequencer_begin_silence().

Here is the call graph for this function:
Here is the caller graph for this function: