![]() |
UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
|
#include <inttypes.h>#include <limits.h>#include <stdbool.h>#include <stdint.h>#include "audio/utils.h"#include "audio/wav_reader.h"#include "debug.h"#include "utils/macros.h"#include "utils/misc.h"
Go to the source code of this file.
Macros | |
| #define | CHECK(cmd, retval) |
| #define | GUID_PCM { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 } |
| #define | MOD_NAME "[WAV reader] " |
| #define | READ_N(buf, len) |
| #define | WAV_MAX_BIT_DEPTH 64 |
| #define | WAV_MAX_CHANNELS 128 |
Functions | |
| static int | fskip (FILE *f, long off) |
| const char * | get_wav_error (int errcode) |
| static _Bool | is_member (const char *needle, const char **haystack) |
| static _Bool | process_data_chunk (FILE *wav_file, uint32_t chunk_size, struct wav_metadata *metadata, _Bool found_ds64_chunk) |
| static _Bool | read_ds64 (FILE *wav_file, uint32_t chunk_size, struct wav_metadata *metadata) |
| static int | read_fmt_chunk (FILE *wav_file, struct wav_metadata *metadata, size_t chunk_size) |
| int | read_wav_header (FILE *wav_file, struct wav_metadata *metadata) |
| size_t | wav_read (void *buffer, size_t sample_count, FILE *wav_file, struct wav_metadata *metadata) |
| int | wav_seek (FILE *wav_file, long offset, int whence, struct wav_metadata *metadata) |
| same as fseek but WAV header presence is respected (for SEEK SET) | |
Definition in file wav_reader.c.
| #define CHECK | ( | cmd, | |
| retval ) |
Definition at line 214 of file wav_reader.c.
Referenced by read_wav_header().
| #define GUID_PCM { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 } |
Definition at line 65 of file wav_reader.c.
Referenced by read_fmt_chunk().
| #define MOD_NAME "[WAV reader] " |
Definition at line 55 of file wav_reader.c.
Referenced by get_wav_error(), process_data_chunk(), read_ds64(), read_fmt_chunk(), and read_wav_header().
| #define READ_N | ( | buf, | |
| len ) |
Definition at line 59 of file wav_reader.c.
Referenced by read_ds64(), read_fmt_chunk(), and read_wav_header().
| #define WAV_MAX_BIT_DEPTH 64 |
Definition at line 56 of file wav_reader.c.
Referenced by read_fmt_chunk().
| #define WAV_MAX_CHANNELS 128 |
Definition at line 57 of file wav_reader.c.
Referenced by read_fmt_chunk().
|
static |
Definition at line 147 of file wav_reader.c.
References _fseeki64.
Referenced by read_ds64(), and read_wav_header().
| const char * get_wav_error | ( | int | errcode | ) |
Definition at line 300 of file wav_reader.c.
References LOG_LEVEL_ERROR, log_msg(), MOD_NAME, WAV_HDR_PARSE_INVALID_PARAM, WAV_HDR_PARSE_NOT_PCM, WAV_HDR_PARSE_OK, WAV_HDR_PARSE_READ_ERROR, and WAV_HDR_PARSE_WRONG_FORMAT.
Referenced by audio_testcard_read_wav(), and init_audio().

|
static |
Definition at line 137 of file wav_reader.c.
Referenced by read_wav_header().
|
static |
Sets data_offset and data_size to metadata (from file position and actual chunk size) Return 1 (true) also for non-seekable > 4GB streams (caller may read it sequentially).
Definition at line 161 of file wav_reader.c.
References _fseeki64, _ftelli64, wav_metadata::data_offset, wav_metadata::data_size, MOD_NAME, and ug_perror().
Referenced by read_wav_header().

|
static |
Definition at line 187 of file wav_reader.c.
References wav_metadata::data_size, fskip(), LOG_LEVEL_ERROR, log_msg(), MIN, MOD_NAME, READ_N, and ug_perror().
Referenced by read_wav_header().

|
static |
Definition at line 67 of file wav_reader.c.
References wav_metadata::bits_per_sample, wav_metadata::ch_count, wav_metadata::channel_mask, GUID_PCM, LOG_LEVEL_ERROR, log_msg(), MOD_NAME, READ_N, sample_rate, wav_metadata::sample_rate, wav_metadata::valid_bits, WAV_HDR_PARSE_INVALID_PARAM, WAV_HDR_PARSE_NOT_PCM, WAV_HDR_PARSE_OK, WAV_HDR_PARSE_READ_ERROR, WAV_HDR_PARSE_WRONG_FORMAT, WAV_MAX_BIT_DEPTH, and WAV_MAX_CHANNELS.
Referenced by read_wav_header().

| int read_wav_header | ( | FILE * | wav_file, |
| struct wav_metadata * | metadata ) |
This function reads wav header
If read successfully, it leaves read file position at the beginning of data. Currently, only interleaved PCM is supported.
| WAV_HDR_PARSE_OK | if ok |
| WAV_HDR_PARSE_READ_ERROR | in case of file read error |
| WAV_HDR_PARSE_WRONG_FORMAT | if unsupported wav format |
| WAV_HDR_PARSE_NOT_PCM | non-PCM WAV detected |
< RF64 or BW64
Definition at line 215 of file wav_reader.c.
References CHECK, wav_metadata::data_offset, wav_metadata::data_size, fskip(), is_member(), LOG_LEVEL_ERROR, LOG_LEVEL_VERBOSE, LOG_LEVEL_WARNING, log_msg(), MOD_NAME, process_data_chunk(), read_ds64(), read_fmt_chunk(), READ_N, WAV_HDR_PARSE_OK, WAV_HDR_PARSE_READ_ERROR, and WAV_HDR_PARSE_WRONG_FORMAT.
Referenced by audio_testcard_read_wav(), and init_audio().

| size_t wav_read | ( | void * | buffer, |
| size_t | sample_count, | ||
| FILE * | wav_file, | ||
| struct wav_metadata * | metadata ) |
Reads sample_count samples from wav_file according to metadata.
Definition at line 291 of file wav_reader.c.
References wav_metadata::bits_per_sample, wav_metadata::ch_count, and signed2unsigned().
Referenced by audio_reading_thread(), and audio_testcard_read_wav().

| int wav_seek | ( | FILE * | wav_file, |
| long | offset, | ||
| int | whence, | ||
| struct wav_metadata * | metadata ) |
same as fseek but WAV header presence is respected (for SEEK SET)
Definition at line 319 of file wav_reader.c.
References wav_metadata::data_offset, and offset.
Referenced by audio_reading_thread(), and reset_import().