libsstvenc
Asynchronous Analogue SSTV encoder
|
Data Structures | |
struct | sstvenc_oscillator |
Macros | |
#define | SSTVENC_OSC_PHASE_FRAC_BITS (29) |
#define | SSTVENC_OSC_PHASE_FRAC_SCALE ((double)(1 << SSTVENC_OSC_PHASE_FRAC_BITS)) |
Functions | |
double | sstvenc_osc_get_frequency (const struct sstvenc_oscillator *const osc) |
void | sstvenc_osc_set_frequency (struct sstvenc_oscillator *const osc, double frequency) |
void | sstvenc_osc_init (struct sstvenc_oscillator *const osc, double amplitude, double frequency, double offset, uint32_t sample_rate) |
void | sstvenc_osc_compute (struct sstvenc_oscillator *const osc) |
This is a simple module that can be used to produce a single sinusoid tone at a given frequency for a given sample rate.
The phase is computed at each sample step, and increments modulo 2-Pi. Frequency, amplitude and phase can be modified at any time, they take effect on the next call to sstvenc_osc_compute.
struct sstvenc_oscillator |
Oscillator data structure. This must remain allocated for the lifetime of the sinusoid.
Use sstvenc_osc_init to initialise this structure.
Definition at line 29 of file oscillator.h.
Data Fields | ||
---|---|---|
double | amplitude |
The amplitude of the sinusoid: range 0-1.0. This may be adjusted to ampiltude-modulate the oscillator. The new amplitude takes effect on the next call to sstvenc_osc_compute. |
double | offset |
Phase offset in radians: range 0-2*M_PI. This may be adjusted to phase-modulate the oscillator. The new phase offset takes effect on the next call to sstvenc_osc_compute. |
double | output |
The last computed output of the sinusoid. The audio output should be read from this field. |
uint32_t | phase |
Fixed-point phase of the sinusoid oscillator. Do not manipulate directly, use sstvenc_osc_init or sstvenc_osc_compute to update. If just re-starting a sine with identical settings, you may set this to 0. |
uint32_t | phase_inc |
Fixed-point phase increment each iteration. Use sstvenc_osc_set_frequency to adjust this or sstvenc_osc_get_frequency to convert back to a frequency in Hz. |
uint32_t | sample_rate |
Sample rate for the sinusoid in Hz. Must not be changed after initialisation. |
#define SSTVENC_OSC_PHASE_FRAC_BITS (29) |
Fixed-point phase bit allocation. For a uint32_t, this gives us a range of 0-7.999 with a precision of ~1.86 nano-radians.
Definition at line 20 of file oscillator.c.
#define SSTVENC_OSC_PHASE_FRAC_SCALE ((double)(1 << SSTVENC_OSC_PHASE_FRAC_BITS)) |
Fixed-point scaling factor, computed from the number of bits.
Definition at line 25 of file oscillator.c.
Referenced by sstvenc_osc_compute(), sstvenc_osc_get_frequency(), and sstvenc_osc_set_frequency().
void sstvenc_osc_compute | ( | struct sstvenc_oscillator *const | osc | ) |
Compute the next sinusoid value and store it in the output field. A no-op if the sample rate is set to zero.
The next sample is made available in sstvenc_oscillator::output.
[in,out] | osc | Oscillator context being computed. |
Definition at line 52 of file oscillator.c.
References sstvenc_oscillator::amplitude, sstvenc_oscillator::offset, sstvenc_oscillator::output, sstvenc_oscillator::phase, sstvenc_oscillator::phase_inc, sstvenc_oscillator::sample_rate, and SSTVENC_OSC_PHASE_FRAC_SCALE.
Referenced by sstvenc_cw_handle_state_mark(), sstvenc_modulator_next_fall_sample(), sstvenc_modulator_next_hold_sample(), sstvenc_modulator_next_rise_sample(), sstvenc_psosc_fill_buffer(), and sstvenc_sequencer_compute().
double sstvenc_osc_get_frequency | ( | const struct sstvenc_oscillator *const | osc | ) |
Get the oscillator frequency in Hertz.
[in] | osc | Oscillator context. |
Definition at line 28 of file oscillator.c.
References sstvenc_oscillator::phase_inc, sstvenc_oscillator::sample_rate, and SSTVENC_OSC_PHASE_FRAC_SCALE.
void sstvenc_osc_init | ( | struct sstvenc_oscillator *const | osc, |
double | amplitude, | ||
double | frequency, | ||
double | offset, | ||
uint32_t | sample_rate ) |
Initialise an oscillator with the given amplitude, frequency and phase offset. Use this when starting a new sinusoid.
[in,out] | osc | Oscillator context being initialised. |
[in] | amplitude | Starting oscillator amplitude (range 0.0-1.0). |
[in] | frequency | Starting frequency of the oscillator (range 0.0 - ½ of sample_rate). |
[in] | offset | Starting phase offset in radians. |
[in] | sample_rate | Output sample rate in hertz. |
Definition at line 42 of file oscillator.c.
References sstvenc_oscillator::amplitude, sstvenc_oscillator::offset, sstvenc_oscillator::output, sstvenc_oscillator::phase, sstvenc_oscillator::sample_rate, and sstvenc_osc_set_frequency().
Referenced by sstvenc_cw_init(), sstvenc_modulator_init(), and sstvenc_sequencer_begin_tone().
void sstvenc_osc_set_frequency | ( | struct sstvenc_oscillator *const | osc, |
double | frequency ) |
Set the oscillator frequency in Hertz.
[in,out] | osc | Oscillator context being updated. |
[in] | frequency | The frequency in Hertz. This MUST be at least 0Hz and less than the nyquist frequency (half the sample rate). |
Definition at line 33 of file oscillator.c.
References sstvenc_oscillator::phase_inc, sstvenc_oscillator::sample_rate, and SSTVENC_OSC_PHASE_FRAC_SCALE.
Referenced by sstvenc_modulator_next_tone(), sstvenc_osc_init(), and sstvenc_sequencer_begin_tone().