encoder/wave: use the structs from RiffFormat.hxx

This commit is contained in:
Max Kellermann 2021-02-16 19:31:31 +01:00
parent d2371af120
commit 8a4b88a59d
1 changed files with 20 additions and 28 deletions

View File

@ -19,6 +19,7 @@
#include "WaveEncoderPlugin.hxx" #include "WaveEncoderPlugin.hxx"
#include "../EncoderAPI.hxx" #include "../EncoderAPI.hxx"
#include "tag/RiffFormat.hxx"
#include "util/ByteOrder.hxx" #include "util/ByteOrder.hxx"
#include "util/DynamicFifoBuffer.hxx" #include "util/DynamicFifoBuffer.hxx"
@ -26,8 +27,6 @@
#include <string.h> #include <string.h>
static constexpr uint16_t WAVE_FORMAT_PCM = 1;
class WaveEncoder final : public Encoder { class WaveEncoder final : public Encoder {
unsigned bits; unsigned bits;
@ -56,19 +55,10 @@ class PreparedWaveEncoder final : public PreparedEncoder {
}; };
struct WaveHeader { struct WaveHeader {
uint32_t id_riff; RiffFileHeader file_header;
uint32_t riff_size; RiffChunkHeader fmt_header;
uint32_t id_wave; RiffFmtChunk fmt;
uint32_t id_fmt; RiffChunkHeader data_header;
uint32_t fmt_size;
uint16_t format;
uint16_t channels;
uint32_t freq;
uint32_t byterate;
uint16_t blocksize;
uint16_t bits;
uint32_t id_data;
uint32_t data_size;
}; };
static_assert(sizeof(WaveHeader) == 44); static_assert(sizeof(WaveHeader) == 44);
@ -82,23 +72,25 @@ MakeWaveHeader(int channels, int bits,
int data_size = 0x0FFFFFFF; int data_size = 0x0FFFFFFF;
/* constants */ /* constants */
header.id_riff = ToLE32(0x46464952); memcpy(header.file_header.id, "RIFF", 4);
header.id_wave = ToLE32(0x45564157); memcpy(header.file_header.format, "WAVE", 4);
header.id_fmt = ToLE32(0x20746d66); memcpy(header.fmt_header.id, "fmt ", 4);
header.id_data = ToLE32(0x61746164); memcpy(header.data_header.id, "data", 4);
/* wave format */ /* wave format */
header.format = ToLE16(WAVE_FORMAT_PCM); header.fmt.tag = ToLE16(RiffFmtChunk::TAG_PCM);
header.channels = ToLE16(channels); header.fmt.channels = ToLE16(channels);
header.bits = ToLE16(bits); header.fmt.bits_per_sample = ToLE16(bits);
header.freq = ToLE32(freq); header.fmt.sample_rate = ToLE32(freq);
header.blocksize = ToLE16(block_size); header.fmt.block_align = ToLE16(block_size);
header.byterate = ToLE32(freq * block_size); header.fmt.byte_rate = ToLE32(freq * block_size);
/* chunk sizes (fake data length) */ /* chunk sizes (fake data length) */
header.fmt_size = ToLE32(16); header.fmt_header.size = ToLE32(sizeof(header.fmt));
header.data_size = ToLE32(data_size); header.data_header.size = ToLE32(data_size);
header.riff_size = ToLE32(4 + (8 + 16) + (8 + data_size)); header.file_header.size = ToLE32(4 +
sizeof(header.fmt_header) + sizeof(header.fmt) +
sizeof(header.data_header) + data_size);
return header; return header;
} }