libsstvenc
Asynchronous Analogue SSTV encoder
|
Topics | |
Audio encoding formats | |
Data Structures | |
struct | sstvenc_sunau |
Macros | |
#define | SSTVENC_SUNAU_MAGIC (0x2e736e64u) |
#define | SSTVENC_SUNAU_HEADER_SZ (7) |
#define | SSTVENC_SUNAU_STATE_HEADER (0x0001) |
Functions | |
int | sstvenc_sunau_check (uint32_t sample_rate, uint8_t encoding, uint8_t channels) |
int | sstvenc_sunau_enc_init_fh (struct sstvenc_sunau *const enc, FILE *fh, uint32_t sample_rate, uint8_t encoding, uint8_t channels) |
int | sstvenc_sunau_enc_init (struct sstvenc_sunau *const enc, const char *path, uint32_t sample_rate, uint8_t encoding, uint8_t channels) |
int | sstvenc_sunau_enc_write (struct sstvenc_sunau *const enc, size_t n_samples, const double *samples) |
int | sstvenc_sunau_enc_close (struct sstvenc_sunau *const enc) |
int | sstvenc_sunau_dec_init_fh (struct sstvenc_sunau *const dec, FILE *fh) |
int | sstvenc_sunau_dec_init (struct sstvenc_sunau *const dec, const char *path) |
int | sstvenc_sunau_dec_read (struct sstvenc_sunau *const enc, size_t *const n_samples, double *samples) |
int | sstvenc_sunau_dec_close (struct sstvenc_sunau *const dec) |
static uint32_t | fhtobe32 (float in) |
static float | fbe32toh (uint32_t in) |
static uint64_t | dhtobe64 (double in) |
static double | dbe64toh (uint64_t in) |
static int | sstvenc_sunau_enc_write_header (struct sstvenc_sunau *const enc) |
static int | sstvenc_sunau_write_s8 (struct sstvenc_sunau *const enc, size_t n_sample, const double *sample) |
static int | sstvenc_sunau_write_s16 (struct sstvenc_sunau *const enc, size_t n_sample, const double *sample) |
static int | sstvenc_sunau_write_s32 (struct sstvenc_sunau *const enc, size_t n_sample, const double *sample) |
static int | sstvenc_sunau_write_f32 (struct sstvenc_sunau *const enc, size_t n_sample, const double *sample) |
static int | sstvenc_sunau_write_f64 (struct sstvenc_sunau *const enc, size_t n_sample, const double *sample) |
static int | sstvenc_sunau_read_s8 (struct sstvenc_sunau *const dec, size_t *const n_samples, double *samples) |
static int | sstvenc_sunau_read_s16 (struct sstvenc_sunau *const dec, size_t *const n_samples, double *samples) |
static int | sstvenc_sunau_read_s32 (struct sstvenc_sunau *const dec, size_t *const n_samples, double *samples) |
static int | sstvenc_sunau_read_f32 (struct sstvenc_sunau *const dec, size_t *const n_samples, double *samples) |
static int | sstvenc_sunau_read_f64 (struct sstvenc_sunau *const dec, size_t *const n_samples, double *samples) |
This module implements a simple Sun Audio file encoder.
Reference: https://en.wikipedia.org/wiki/Au_file_format
struct sstvenc_sunau |
Encoder/decoder context. Stores the fields necessary to construct the header and the file pointer.
Data Fields | ||
---|---|---|
uint8_t | channels |
Channel count |
uint8_t | encoding |
Audio encoding, see Audio encoding formats |
FILE * | fh |
Pointer to the open file for reading or writing |
uint32_t | sample_rate |
File sample rate in Hz |
uint16_t | state |
Internal state |
uint32_t | written_sz |
Number of bytes written, not used when reading |
#define SSTVENC_SUNAU_HEADER_SZ (7) |
Size of a Sun Audio header in 32-bit words.
Definition at line 20 of file sunau.c.
Referenced by sstvenc_sunau_dec_init_fh(), and sstvenc_sunau_enc_write_header().
#define SSTVENC_SUNAU_MAGIC (0x2e736e64u) |
Magic bytes at start of the Sun Audio header. This is in fact, the ASCII characters ".snd".
Definition at line 15 of file sunau.c.
Referenced by sstvenc_sunau_dec_init_fh(), and sstvenc_sunau_enc_write_header().
#define SSTVENC_SUNAU_STATE_HEADER (0x0001) |
SunAU encoder state bit: header is written
Definition at line 50 of file sunau.c.
Referenced by sstvenc_sunau_enc_close(), sstvenc_sunau_enc_write(), and sstvenc_sunau_enc_write_header().
|
static |
Convert a 64-bit IEEE-754 float from big-endian
Definition at line 86 of file sunau.c.
Referenced by sstvenc_sunau_read_f64().
|
static |
Convert a 64-bit IEEE-754 float to big-endian
Definition at line 75 of file sunau.c.
Referenced by sstvenc_sunau_write_f64().
|
static |
Convert a 32-bit IEEE-754 float from big-endian
Definition at line 64 of file sunau.c.
Referenced by sstvenc_sunau_read_f32().
|
static |
Convert a 32-bit IEEE-754 float to big-endian
Definition at line 53 of file sunau.c.
Referenced by sstvenc_sunau_write_f32().
int sstvenc_sunau_check | ( | uint32_t | sample_rate, |
uint8_t | encoding, | ||
uint8_t | channels ) |
Validate the given settings as sane.
[in] | sample_rate | Sample rate for the audio output in Hz |
[in] | encoding | Audio encoding for the output file |
[in] | channels | Number of channels in the audio file |
0 | Settings are valid |
-EINVAL | Invalid sample rate, encoding or channel count |
Definition at line 250 of file sunau.c.
References SSTVENC_SUNAU_FMT_F32, SSTVENC_SUNAU_FMT_F64, SSTVENC_SUNAU_FMT_S16, SSTVENC_SUNAU_FMT_S32, and SSTVENC_SUNAU_FMT_S8.
Referenced by sstvenc_sunau_dec_init_fh(), sstvenc_sunau_enc_init(), and sstvenc_sunau_enc_init_fh().
int sstvenc_sunau_dec_close | ( | struct sstvenc_sunau *const | dec | ) |
Close the file opened for reading.
[in,out] | dec | SunAU decoder context (to be closed) |
0 | Success |
<0 | Write error errno from fclose() . |
Definition at line 606 of file sunau.c.
References sstvenc_sunau::fh.
int sstvenc_sunau_dec_init | ( | struct sstvenc_sunau *const | dec, |
const char * | path ) |
Open a file for reading.
[out] | dec | SunAU decoder context |
[in] | path | Path to the file to open for reading. |
0 | Success |
-EINVAL | Invalid sample rate, encoding or channel count |
<0 | -errno result from fopen() call. |
Definition at line 413 of file sunau.c.
References sstvenc_sunau_dec_init_fh().
int sstvenc_sunau_dec_init_fh | ( | struct sstvenc_sunau *const | dec, |
FILE * | fh ) |
Initialise an audio decoder context with an opened file.
[out] | dec | SunAU decoder context |
[in,out] | fh | Existing file handle, open for writing in binary mode, positioned at the start of the file. |
0 | Success |
-EINVAL | Invalid sample rate, encoding or channel count |
Definition at line 370 of file sunau.c.
References sstvenc_sunau::channels, sstvenc_sunau::encoding, sstvenc_sunau::fh, sstvenc_sunau::sample_rate, sstvenc_sunau_check(), SSTVENC_SUNAU_HEADER_SZ, and SSTVENC_SUNAU_MAGIC.
Referenced by sstvenc_sunau_dec_init().
int sstvenc_sunau_dec_read | ( | struct sstvenc_sunau *const | enc, |
size_t *const | n_samples, | ||
double * | samples ) |
Read some audio samples from the file. n_samples is assumed to be a multiple of the channel count.
[in,out] | enc | SunAU decoder context |
[in,out] | n_samples | Number of samples in the buffer, will be updated with the number of samples actually read. |
[out] | samples | The samples to be read |
0 | Success |
-EINVAL | Invalid number of samples (not a multiple of dec->channels ) |
<0 | Read error errno from fread() |
Definition at line 587 of file sunau.c.
References sstvenc_sunau::encoding, SSTVENC_SUNAU_FMT_F32, SSTVENC_SUNAU_FMT_F64, SSTVENC_SUNAU_FMT_S16, SSTVENC_SUNAU_FMT_S32, SSTVENC_SUNAU_FMT_S8, sstvenc_sunau_read_f32(), sstvenc_sunau_read_f64(), sstvenc_sunau_read_s16(), sstvenc_sunau_read_s32(), and sstvenc_sunau_read_s8().
int sstvenc_sunau_enc_close | ( | struct sstvenc_sunau *const | enc | ) |
Finish writing the file and close it.
[in,out] | enc | SunAU encoder context (to be closed) |
0 | Success |
<0 | Write error errno from fwrite() or fclose() . |
Definition at line 340 of file sunau.c.
References sstvenc_sunau::fh, sstvenc_sunau_enc_write_header(), SSTVENC_SUNAU_STATE_HEADER, sstvenc_sunau::state, and sstvenc_sunau::written_sz.
Referenced by main().
int sstvenc_sunau_enc_init | ( | struct sstvenc_sunau *const | enc, |
const char * | path, | ||
uint32_t | sample_rate, | ||
uint8_t | encoding, | ||
uint8_t | channels ) |
Open a file for writing.
[out] | enc | SunAU encoder context |
[in] | path | Path to the file to open for writing. |
[in] | sample_rate | Sample rate for the audio output in Hz |
[in] | encoding | Audio encoding for the output file |
[in] | channels | Number of channels in the audio file |
0 | Success |
-EINVAL | Invalid sample rate, encoding or channel count |
<0 | -errno result from fopen() call. |
Definition at line 288 of file sunau.c.
References sstvenc_sunau::channels, sstvenc_sunau::encoding, sstvenc_sunau::fh, sstvenc_sunau::sample_rate, sstvenc_sunau_check(), sstvenc_sunau::state, and sstvenc_sunau::written_sz.
Referenced by main().
int sstvenc_sunau_enc_init_fh | ( | struct sstvenc_sunau *const | enc, |
FILE * | fh, | ||
uint32_t | sample_rate, | ||
uint8_t | encoding, | ||
uint8_t | channels ) |
Initialise an audio encoder context with an opened file.
[out] | enc | SunAU encoder context |
[in,out] | fh | Existing file handle, open for writing in binary mode, positioned at the start of the file. |
[in] | sample_rate | Sample rate for the audio output in Hz |
[in] | encoding | Audio encoding for the output file |
[in] | channels | Number of channels in the audio file |
0 | Success |
-EINVAL | Invalid sample rate, encoding or channel count |
Definition at line 270 of file sunau.c.
References sstvenc_sunau::channels, sstvenc_sunau::encoding, sstvenc_sunau::fh, sstvenc_sunau::sample_rate, sstvenc_sunau_check(), sstvenc_sunau::state, and sstvenc_sunau::written_sz.
int sstvenc_sunau_enc_write | ( | struct sstvenc_sunau *const | enc, |
size_t | n_samples, | ||
const double * | samples ) |
Write some audio samples to the file. Audio is assumed to be a whole number of audio frames, given as double-precision values in the range [-1.0, 1.0] in the sample rate defined for the file.
[in,out] | enc | SunAU encoder context |
[in] | n_samples | Number of samples in the buffer |
[in] | samples | The samples to be written |
0 | Success |
-EINVAL | Invalid number of samples (not a multiple of enc->channels ) |
<0 | Write error errno from fwrite() |
Definition at line 310 of file sunau.c.
References sstvenc_sunau::channels, sstvenc_sunau::encoding, sstvenc_sunau_enc_write_header(), SSTVENC_SUNAU_FMT_F32, SSTVENC_SUNAU_FMT_F64, SSTVENC_SUNAU_FMT_S16, SSTVENC_SUNAU_FMT_S32, SSTVENC_SUNAU_FMT_S8, SSTVENC_SUNAU_STATE_HEADER, sstvenc_sunau_write_f32(), sstvenc_sunau_write_f64(), sstvenc_sunau_write_s16(), sstvenc_sunau_write_s32(), sstvenc_sunau_write_s8(), and sstvenc_sunau::state.
Referenced by main().
|
static |
Write the Sun Audio header to the output file.
Definition at line 99 of file sunau.c.
References sstvenc_sunau::channels, sstvenc_sunau::encoding, sstvenc_sunau::fh, sstvenc_sunau::sample_rate, SSTVENC_SUNAU_HEADER_SZ, SSTVENC_SUNAU_MAGIC, SSTVENC_SUNAU_STATE_HEADER, sstvenc_sunau::state, and sstvenc_sunau::written_sz.
Referenced by sstvenc_sunau_enc_close(), and sstvenc_sunau_enc_write().
|
static |
Definition at line 526 of file sunau.c.
References fbe32toh(), and sstvenc_sunau::fh.
Referenced by sstvenc_sunau_dec_read().
|
static |
Definition at line 557 of file sunau.c.
References dbe64toh(), and sstvenc_sunau::fh.
Referenced by sstvenc_sunau_dec_read().
|
static |
Definition at line 460 of file sunau.c.
References sstvenc_sunau::fh.
Referenced by sstvenc_sunau_dec_read().
|
static |
Definition at line 493 of file sunau.c.
References sstvenc_sunau::fh.
Referenced by sstvenc_sunau_dec_read().
|
static |
Definition at line 429 of file sunau.c.
References sstvenc_sunau::fh.
Referenced by sstvenc_sunau_dec_read().
|
static |
Write the given samples in 32-bit IEEE-754 floating-point format.
Definition at line 207 of file sunau.c.
References sstvenc_sunau::fh, fhtobe32(), and sstvenc_sunau::written_sz.
Referenced by sstvenc_sunau_enc_write().
|
static |
Write the given samples in 64-bit IEEE-754 floating-point format.
Definition at line 230 of file sunau.c.
References dhtobe64(), sstvenc_sunau::fh, and sstvenc_sunau::written_sz.
Referenced by sstvenc_sunau_enc_write().
|
static |
Write the given samples in signed 16-bit integer format.
Definition at line 157 of file sunau.c.
References sstvenc_sunau::fh, and sstvenc_sunau::written_sz.
Referenced by sstvenc_sunau_enc_write().
|
static |
Write the given samples in signed 32-bit integer format.
Definition at line 182 of file sunau.c.
References sstvenc_sunau::fh, and sstvenc_sunau::written_sz.
Referenced by sstvenc_sunau_enc_write().
|
static |
Write the given samples in signed 8-bit integer format.
Definition at line 134 of file sunau.c.
References sstvenc_sunau::fh, and sstvenc_sunau::written_sz.
Referenced by sstvenc_sunau_enc_write().