#include "common_audio/wav_header.h"
#include <cstring>
#include <limits>
#include <string>
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/sanitizer.h"
#include "rtc_base/system/arch.h"
namespace webrtc {
namespace {
#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
#error "Code not working properly for big endian platforms."
#endif
#pragma pack(2)
struct ChunkHeader { … };
static_assert …;
#pragma pack(2)
struct RiffHeader { … };
static_assert …;
#pragma pack(2)
struct FmtPcmSubchunk { … };
static_assert …;
const uint32_t kFmtPcmSubchunkSize = …;
#pragma pack(2)
struct FmtIeeeFloatSubchunk { … };
static_assert …;
const uint32_t kFmtIeeeFloatSubchunkSize = …;
#pragma pack(2)
struct WavHeaderPcm { … };
static_assert …;
#pragma pack(2)
struct WavHeaderIeeeFloat { … };
static_assert …;
uint32_t PackFourCC(char a, char b, char c, char d) { … }
std::string ReadFourCC(uint32_t x) { … }
uint16_t MapWavFormatToHeaderField(WavFormat format) { … }
WavFormat MapHeaderFieldToWavFormat(uint16_t format_header_value) { … }
uint32_t RiffChunkSize(size_t bytes_in_payload, size_t header_size) { … }
uint32_t ByteRate(size_t num_channels,
int sample_rate,
size_t bytes_per_sample) { … }
uint16_t BlockAlign(size_t num_channels, size_t bytes_per_sample) { … }
bool FindWaveChunk(ChunkHeader* chunk_header,
WavHeaderReader* readable,
const std::string sought_chunk_id) { … }
bool ReadFmtChunkData(FmtPcmSubchunk* fmt_subchunk, WavHeaderReader* readable) { … }
void WritePcmWavHeader(size_t num_channels,
int sample_rate,
size_t bytes_per_sample,
size_t num_samples,
uint8_t* buf,
size_t* header_size) { … }
void WriteIeeeFloatWavHeader(size_t num_channels,
int sample_rate,
size_t bytes_per_sample,
size_t num_samples,
uint8_t* buf,
size_t* header_size) { … }
size_t GetFormatBytesPerSample(WavFormat format) { … }
bool CheckWavParameters(size_t num_channels,
int sample_rate,
WavFormat format,
size_t bytes_per_sample,
size_t num_samples) { … }
}
bool CheckWavParameters(size_t num_channels,
int sample_rate,
WavFormat format,
size_t num_samples) { … }
void WriteWavHeader(size_t num_channels,
int sample_rate,
WavFormat format,
size_t num_samples,
uint8_t* buf,
size_t* header_size) { … }
bool ReadWavHeader(WavHeaderReader* readable,
size_t* num_channels,
int* sample_rate,
WavFormat* format,
size_t* bytes_per_sample,
size_t* num_samples,
int64_t* data_start_pos) { … }
}